comparison dss.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents 76097ec1a29a a98a2138364a
children 33fd2f3499d2
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
344 344
345 /* generate k */ 345 /* generate k */
346 m_fp_init(&dss_protok); 346 m_fp_init(&dss_protok);
347 bytes_to_fp(&dss_protok, proto_k, SHA512_HASH_SIZE); 347 bytes_to_fp(&dss_protok, proto_k, SHA512_HASH_SIZE);
348 if (fp_mod(&dss_protok, key->q, &dss_k) != FP_OKAY) { 348 if (fp_mod(&dss_protok, key->q, &dss_k) != FP_OKAY) {
349 dropbear_exit("dss error"); 349 dropbear_exit("DSS error");
350 } 350 }
351 m_fp_zero(&dss_protok); 351 m_fp_zero(&dss_protok);
352 m_burn(proto_k, SHA512_HASH_SIZE); 352 m_burn(proto_k, SHA512_HASH_SIZE);
353 #else /* DSS_PROTOK not defined*/ 353 #else /* DSS_PROTOK not defined*/
354 gen_random_fpint(key->q, &dss_k); 354 gen_random_fpint(key->q, &dss_k);
357 /* now generate the actual signature */ 357 /* now generate the actual signature */
358 bytes_to_fp(&dss_m, msghash, SHA1_HASH_SIZE); 358 bytes_to_fp(&dss_m, msghash, SHA1_HASH_SIZE);
359 359
360 /* g^k mod p */ 360 /* g^k mod p */
361 if (fp_exptmod(key->g, &dss_k, key->p, &dss_temp1) != FP_OKAY) { 361 if (fp_exptmod(key->g, &dss_k, key->p, &dss_temp1) != FP_OKAY) {
362 dropbear_exit("dss error"); 362 dropbear_exit("DSS error");
363 } 363 }
364 /* r = (g^k mod p) mod q */ 364 /* r = (g^k mod p) mod q */
365 if (fp_mod(&dss_temp1, key->q, &dss_r) != FP_OKAY) { 365 if (fp_mod(&dss_temp1, key->q, &dss_r) != FP_OKAY) {
366 dropbear_exit("dss error"); 366 dropbear_exit("DSS error");
367 } 367 }
368 368
369 /* x*r mod q */ 369 /* x*r mod q */
370 if (fp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != FP_OKAY) { 370 if (fp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != FP_OKAY) {
371 dropbear_exit("dss error"); 371 dropbear_exit("DSS error");
372 } 372 }
373 /* (SHA1(M) + xr) mod q) */ 373 /* (SHA1(M) + xr) mod q) */
374 if (fp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != FP_OKAY) { 374 if (fp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != FP_OKAY) {
375 dropbear_exit("dss error"); 375 dropbear_exit("DSS error");
376 } 376 }
377 377
378 /* (k^-1) mod q */ 378 /* (k^-1) mod q */
379 if (fp_invmod(&dss_k, key->q, &dss_temp1) != FP_OKAY) { 379 if (fp_invmod(&dss_k, key->q, &dss_temp1) != FP_OKAY) {
380 dropbear_exit("dss error"); 380 dropbear_exit("DSS error");
381 } 381 }
382 382
383 /* s = (k^-1(SHA1(M) + xr)) mod q */ 383 /* s = (k^-1(SHA1(M) + xr)) mod q */
384 if (fp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != FP_OKAY) { 384 if (fp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != FP_OKAY) {
385 dropbear_exit("dss error"); 385 dropbear_exit("DSS error");
386 } 386 }
387 387
388 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); 388 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
389 buf_putint(buf, 2*SHA1_HASH_SIZE); 389 buf_putint(buf, 2*SHA1_HASH_SIZE);
390 390