comparison rsa.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
67 TRACE(("leave buf_get_rsa_pub_key: failure")) 67 TRACE(("leave buf_get_rsa_pub_key: failure"))
68 goto out; 68 goto out;
69 } 69 }
70 70
71 if (fp_count_bits(key->n) < MIN_RSA_KEYLEN) { 71 if (fp_count_bits(key->n) < MIN_RSA_KEYLEN) {
72 dropbear_log(LOG_WARNING, "rsa key too short"); 72 dropbear_log(LOG_WARNING, "RSA key too short");
73 goto out; 73 goto out;
74 } 74 }
75 75
76 TRACE(("leave buf_get_rsa_pub_key: success")) 76 TRACE(("leave buf_get_rsa_pub_key: success"))
77 ret = DROPBEAR_SUCCESS; 77 ret = DROPBEAR_SUCCESS;
308 /* rsa_tmp1 is em */ 308 /* rsa_tmp1 is em */
309 /* em' = em * r^e mod n */ 309 /* em' = em * r^e mod n */
310 310
311 /* rsa_s used as a temp var*/ 311 /* rsa_s used as a temp var*/
312 if (fp_exptmod(&rsa_tmp2, key->e, key->n, &rsa_s) != FP_OKAY) { 312 if (fp_exptmod(&rsa_tmp2, key->e, key->n, &rsa_s) != FP_OKAY) {
313 dropbear_exit("rsa error"); 313 dropbear_exit("RSA error");
314 } 314 }
315 if (fp_invmod(&rsa_tmp2, key->n, &rsa_tmp3) != FP_OKAY) { 315 if (fp_invmod(&rsa_tmp2, key->n, &rsa_tmp3) != FP_OKAY) {
316 dropbear_exit("rsa error"); 316 dropbear_exit("RSA error");
317 } 317 }
318 if (fp_mulmod(&rsa_tmp1, &rsa_s, key->n, &rsa_tmp2) != FP_OKAY) { 318 if (fp_mulmod(&rsa_tmp1, &rsa_s, key->n, &rsa_tmp2) != FP_OKAY) {
319 dropbear_exit("rsa error"); 319 dropbear_exit("RSA error");
320 } 320 }
321 321
322 /* rsa_tmp2 is em' */ 322 /* rsa_tmp2 is em' */
323 /* s' = (em')^d mod n */ 323 /* s' = (em')^d mod n */
324 if (fp_exptmod(&rsa_tmp2, key->d, key->n, &rsa_tmp1) != FP_OKAY) { 324 if (fp_exptmod(&rsa_tmp2, key->d, key->n, &rsa_tmp1) != FP_OKAY) {
325 dropbear_exit("rsa error"); 325 dropbear_exit("RSA error");
326 } 326 }
327 327
328 /* rsa_tmp1 is s' */ 328 /* rsa_tmp1 is s' */
329 /* rsa_tmp3 is r^(-1) mod n */ 329 /* rsa_tmp3 is r^(-1) mod n */
330 /* s = (s')r^(-1) mod n */ 330 /* s = (s')r^(-1) mod n */
331 if (fp_mulmod(&rsa_tmp1, &rsa_tmp3, key->n, &rsa_s) != FP_OKAY) { 331 if (fp_mulmod(&rsa_tmp1, &rsa_tmp3, key->n, &rsa_s) != FP_OKAY) {
332 dropbear_exit("rsa error"); 332 dropbear_exit("RSA error");
333 } 333 }
334 334
335 #else 335 #else
336 336
337 /* s = em^d mod n */ 337 /* s = em^d mod n */
338 /* rsa_tmp1 is em */ 338 /* rsa_tmp1 is em */
339 if (fp_exptmod(&rsa_tmp1, key->d, key->n, &rsa_s) != FP_OKAY) { 339 if (fp_exptmod(&rsa_tmp1, key->d, key->n, &rsa_s) != FP_OKAY) {
340 dropbear_exit("rsa error"); 340 dropbear_exit("RSA error");
341 } 341 }
342 342
343 #endif /* RSA_BLINDING */ 343 #endif /* RSA_BLINDING */
344 344
345 fp_zero(&rsa_tmp1); 345 fp_zero(&rsa_tmp1);