comparison dss.c @ 1733:d529a52b2f7c coverity coverity

merge coverity from main
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 Jun 2020 21:07:34 +0800
parents 1051e4eea25a
children
comparison
equal deleted inserted replaced
1643:b59623a64678 1733:d529a52b2f7c
282 * to the buffer */ 282 * to the buffer */
283 void buf_put_dss_sign(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf) { 283 void buf_put_dss_sign(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf) {
284 unsigned char msghash[SHA1_HASH_SIZE]; 284 unsigned char msghash[SHA1_HASH_SIZE];
285 unsigned int writelen; 285 unsigned int writelen;
286 unsigned int i; 286 unsigned int i;
287 size_t written;
287 DEF_MP_INT(dss_k); 288 DEF_MP_INT(dss_k);
288 DEF_MP_INT(dss_m); 289 DEF_MP_INT(dss_m);
289 DEF_MP_INT(dss_temp1); 290 DEF_MP_INT(dss_temp1);
290 DEF_MP_INT(dss_temp2); 291 DEF_MP_INT(dss_temp2);
291 DEF_MP_INT(dss_r); 292 DEF_MP_INT(dss_r);
338 } 339 }
339 340
340 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); 341 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
341 buf_putint(buf, 2*SHA1_HASH_SIZE); 342 buf_putint(buf, 2*SHA1_HASH_SIZE);
342 343
343 writelen = mp_unsigned_bin_size(&dss_r); 344 writelen = mp_ubin_size(&dss_r);
344 dropbear_assert(writelen <= SHA1_HASH_SIZE); 345 dropbear_assert(writelen <= SHA1_HASH_SIZE);
345 /* need to pad to 160 bits with leading zeros */ 346 /* need to pad to 160 bits with leading zeros */
346 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { 347 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
347 buf_putbyte(buf, 0); 348 buf_putbyte(buf, 0);
348 } 349 }
349 if (mp_to_unsigned_bin(&dss_r, buf_getwriteptr(buf, writelen)) 350 if (mp_to_ubin(&dss_r, buf_getwriteptr(buf, writelen), writelen, &written)
350 != MP_OKAY) { 351 != MP_OKAY) {
351 dropbear_exit("DSS error"); 352 dropbear_exit("DSS error");
352 } 353 }
353 mp_clear(&dss_r); 354 mp_clear(&dss_r);
354 buf_incrwritepos(buf, writelen); 355 buf_incrwritepos(buf, written);
355 356
356 writelen = mp_unsigned_bin_size(&dss_s); 357 writelen = mp_ubin_size(&dss_s);
357 dropbear_assert(writelen <= SHA1_HASH_SIZE); 358 dropbear_assert(writelen <= SHA1_HASH_SIZE);
358 /* need to pad to 160 bits with leading zeros */ 359 /* need to pad to 160 bits with leading zeros */
359 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { 360 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
360 buf_putbyte(buf, 0); 361 buf_putbyte(buf, 0);
361 } 362 }
362 if (mp_to_unsigned_bin(&dss_s, buf_getwriteptr(buf, writelen)) 363 if (mp_to_ubin(&dss_s, buf_getwriteptr(buf, writelen), writelen, &written)
363 != MP_OKAY) { 364 != MP_OKAY) {
364 dropbear_exit("DSS error"); 365 dropbear_exit("DSS error");
365 } 366 }
366 mp_clear(&dss_s); 367 mp_clear(&dss_s);
367 buf_incrwritepos(buf, writelen); 368 buf_incrwritepos(buf, written);
368 369
369 mp_clear_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s, 370 mp_clear_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s,
370 &dss_m, NULL); 371 &dss_m, NULL);
371 372
372 /* create the signature to return */ 373 /* create the signature to return */