comparison dss.c @ 594:a98a2138364a

Improve capitalisation for all logged strings
author Matt Johnston <matt@ucc.asn.au>
date Wed, 23 Feb 2011 15:50:30 +0000
parents b50f0107e505
children 2b1bb792cd4d 94aa1203be1e
comparison
equal deleted inserted replaced
593:ea103e4476ce 594:a98a2138364a
268 int size; 268 int size;
269 269
270 size = mp_unsigned_bin_size(mp); 270 size = mp_unsigned_bin_size(mp);
271 ret = m_malloc(size); 271 ret = m_malloc(size);
272 if (mp_to_unsigned_bin(mp, ret) != MP_OKAY) { 272 if (mp_to_unsigned_bin(mp, ret) != MP_OKAY) {
273 dropbear_exit("mem alloc error"); 273 dropbear_exit("Mem alloc error");
274 } 274 }
275 if (len != NULL) { 275 if (len != NULL) {
276 *len = size; 276 *len = size;
277 } 277 }
278 return ret; 278 return ret;
340 340
341 /* generate k */ 341 /* generate k */
342 m_mp_init(&dss_protok); 342 m_mp_init(&dss_protok);
343 bytes_to_mp(&dss_protok, proto_k, SHA512_HASH_SIZE); 343 bytes_to_mp(&dss_protok, proto_k, SHA512_HASH_SIZE);
344 if (mp_mod(&dss_protok, key->q, &dss_k) != MP_OKAY) { 344 if (mp_mod(&dss_protok, key->q, &dss_k) != MP_OKAY) {
345 dropbear_exit("dss error"); 345 dropbear_exit("DSS error");
346 } 346 }
347 mp_clear(&dss_protok); 347 mp_clear(&dss_protok);
348 m_burn(proto_k, SHA512_HASH_SIZE); 348 m_burn(proto_k, SHA512_HASH_SIZE);
349 #else /* DSS_PROTOK not defined*/ 349 #else /* DSS_PROTOK not defined*/
350 gen_random_mpint(key->q, &dss_k); 350 gen_random_mpint(key->q, &dss_k);
353 /* now generate the actual signature */ 353 /* now generate the actual signature */
354 bytes_to_mp(&dss_m, msghash, SHA1_HASH_SIZE); 354 bytes_to_mp(&dss_m, msghash, SHA1_HASH_SIZE);
355 355
356 /* g^k mod p */ 356 /* g^k mod p */
357 if (mp_exptmod(key->g, &dss_k, key->p, &dss_temp1) != MP_OKAY) { 357 if (mp_exptmod(key->g, &dss_k, key->p, &dss_temp1) != MP_OKAY) {
358 dropbear_exit("dss error"); 358 dropbear_exit("DSS error");
359 } 359 }
360 /* r = (g^k mod p) mod q */ 360 /* r = (g^k mod p) mod q */
361 if (mp_mod(&dss_temp1, key->q, &dss_r) != MP_OKAY) { 361 if (mp_mod(&dss_temp1, key->q, &dss_r) != MP_OKAY) {
362 dropbear_exit("dss error"); 362 dropbear_exit("DSS error");
363 } 363 }
364 364
365 /* x*r mod q */ 365 /* x*r mod q */
366 if (mp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != MP_OKAY) { 366 if (mp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != MP_OKAY) {
367 dropbear_exit("dss error"); 367 dropbear_exit("DSS error");
368 } 368 }
369 /* (SHA1(M) + xr) mod q) */ 369 /* (SHA1(M) + xr) mod q) */
370 if (mp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != MP_OKAY) { 370 if (mp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != MP_OKAY) {
371 dropbear_exit("dss error"); 371 dropbear_exit("DSS error");
372 } 372 }
373 373
374 /* (k^-1) mod q */ 374 /* (k^-1) mod q */
375 if (mp_invmod(&dss_k, key->q, &dss_temp1) != MP_OKAY) { 375 if (mp_invmod(&dss_k, key->q, &dss_temp1) != MP_OKAY) {
376 dropbear_exit("dss error"); 376 dropbear_exit("DSS error");
377 } 377 }
378 378
379 /* s = (k^-1(SHA1(M) + xr)) mod q */ 379 /* s = (k^-1(SHA1(M) + xr)) mod q */
380 if (mp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != MP_OKAY) { 380 if (mp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != MP_OKAY) {
381 dropbear_exit("dss error"); 381 dropbear_exit("DSS error");
382 } 382 }
383 383
384 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); 384 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
385 buf_putint(buf, 2*SHA1_HASH_SIZE); 385 buf_putint(buf, 2*SHA1_HASH_SIZE);
386 386
390 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { 390 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
391 buf_putbyte(buf, 0); 391 buf_putbyte(buf, 0);
392 } 392 }
393 if (mp_to_unsigned_bin(&dss_r, buf_getwriteptr(buf, writelen)) 393 if (mp_to_unsigned_bin(&dss_r, buf_getwriteptr(buf, writelen))
394 != MP_OKAY) { 394 != MP_OKAY) {
395 dropbear_exit("dss error"); 395 dropbear_exit("DSS error");
396 } 396 }
397 mp_clear(&dss_r); 397 mp_clear(&dss_r);
398 buf_incrwritepos(buf, writelen); 398 buf_incrwritepos(buf, writelen);
399 399
400 writelen = mp_unsigned_bin_size(&dss_s); 400 writelen = mp_unsigned_bin_size(&dss_s);
403 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { 403 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
404 buf_putbyte(buf, 0); 404 buf_putbyte(buf, 0);
405 } 405 }
406 if (mp_to_unsigned_bin(&dss_s, buf_getwriteptr(buf, writelen)) 406 if (mp_to_unsigned_bin(&dss_s, buf_getwriteptr(buf, writelen))
407 != MP_OKAY) { 407 != MP_OKAY) {
408 dropbear_exit("dss error"); 408 dropbear_exit("DSS error");
409 } 409 }
410 mp_clear(&dss_s); 410 mp_clear(&dss_s);
411 buf_incrwritepos(buf, writelen); 411 buf_incrwritepos(buf, writelen);
412 412
413 mp_clear_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s, 413 mp_clear_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s,