comparison dss.c @ 1580:7f2be495dff6 coverity

merge coverity
author Matt Johnston <matt@ucc.asn.au>
date Sun, 04 Mar 2018 15:07:09 +0800
parents 5916af64acd4
children 1051e4eea25a
comparison
equal deleted inserted replaced
1545:0b991dec7ab9 1580:7f2be495dff6
71 dropbear_log(LOG_WARNING, "Bad DSS q"); 71 dropbear_log(LOG_WARNING, "Bad DSS q");
72 ret = DROPBEAR_FAILURE; 72 ret = DROPBEAR_FAILURE;
73 goto out; 73 goto out;
74 } 74 }
75 75
76 /* test 1 < g < p */
77 if (mp_cmp_d(key->g, 1) != MP_GT) {
78 dropbear_log(LOG_WARNING, "Bad DSS g");
79 ret = DROPBEAR_FAILURE;
80 goto out;
81 }
82 if (mp_cmp(key->g, key->p) != MP_LT) {
83 dropbear_log(LOG_WARNING, "Bad DSS g");
84 ret = DROPBEAR_FAILURE;
85 goto out;
86 }
87
76 ret = DROPBEAR_SUCCESS; 88 ret = DROPBEAR_SUCCESS;
77 TRACE(("leave buf_get_dss_pub_key: success")) 89 TRACE(("leave buf_get_dss_pub_key: success"))
78 out: 90 out:
79 if (ret == DROPBEAR_FAILURE) { 91 if (ret == DROPBEAR_FAILURE) {
80 m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, NULL); 92 m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, NULL);
170 string = buf_getstring(buf, &stringlen); 182 string = buf_getstring(buf, &stringlen);
171 if (stringlen != 2*SHA1_HASH_SIZE) { 183 if (stringlen != 2*SHA1_HASH_SIZE) {
172 goto out; 184 goto out;
173 } 185 }
174 186
187 #if DEBUG_DSS_VERIFY
188 printmpint("dss verify p", key->p);
189 printmpint("dss verify q", key->q);
190 printmpint("dss verify g", key->g);
191 printmpint("dss verify y", key->y);
192 #endif
193
175 /* hash the data */ 194 /* hash the data */
176 sha1_init(&hs); 195 sha1_init(&hs);
177 sha1_process(&hs, data_buf->data, data_buf->len); 196 sha1_process(&hs, data_buf->data, data_buf->len);
178 sha1_done(&hs, msghash); 197 sha1_done(&hs, msghash);
179 198
180 /* create the signature - s' and r' are the received signatures in buf */ 199 /* create the signature - s' and r' are the received signatures in buf */
181 /* w = (s')-1 mod q */ 200 /* w = (s')-1 mod q */
182 /* let val1 = s' */ 201 /* let val1 = s' */
183 bytes_to_mp(&val1, (const unsigned char*) &string[SHA1_HASH_SIZE], SHA1_HASH_SIZE); 202 bytes_to_mp(&val1, (const unsigned char*) &string[SHA1_HASH_SIZE], SHA1_HASH_SIZE);
203 #if DEBUG_DSS_VERIFY
204 printmpint("dss verify s'", &val1);
205 #endif
184 206
185 if (mp_cmp(&val1, key->q) != MP_LT) { 207 if (mp_cmp(&val1, key->q) != MP_LT) {
186 TRACE(("verify failed, s' >= q")) 208 TRACE(("verify failed, s' >= q"))
187 goto out; 209 goto out;
188 } 210 }
196 } 218 }
197 219
198 /* u1 = ((SHA(M')w) mod q */ 220 /* u1 = ((SHA(M')w) mod q */
199 /* let val1 = SHA(M') = msghash */ 221 /* let val1 = SHA(M') = msghash */
200 bytes_to_mp(&val1, msghash, SHA1_HASH_SIZE); 222 bytes_to_mp(&val1, msghash, SHA1_HASH_SIZE);
223 #if DEBUG_DSS_VERIFY
224 printmpint("dss verify r'", &val1);
225 #endif
201 226
202 /* let val3 = u1 = ((SHA(M')w) mod q */ 227 /* let val3 = u1 = ((SHA(M')w) mod q */
203 if (mp_mulmod(&val1, &val2, key->q, &val3) != MP_OKAY) { 228 if (mp_mulmod(&val1, &val2, key->q, &val3) != MP_OKAY) {
204 goto out; 229 goto out;
205 } 230 }