Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: nss/lib/freebl/rsa.c

Issue 319593003: Update to NSS 3.16.2 Beta 3. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Remove unused function SEC_NumberOrNameStringToOIDTag Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 /* 5 /*
6 * RSA key generation, public key op, private key op. 6 * RSA key generation, public key op, private key op.
7 */ 7 */
8 #ifdef FREEBL_NO_DEPEND 8 #ifdef FREEBL_NO_DEPEND
9 #include "stubs.h" 9 #include "stubs.h"
10 #endif 10 #endif
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 CHECK_MPI_OK( mp_init(&q) ); 1399 CHECK_MPI_OK( mp_init(&q) );
1400 CHECK_MPI_OK( mp_init(&n) ); 1400 CHECK_MPI_OK( mp_init(&n) );
1401 CHECK_MPI_OK( mp_init(&psub1)); 1401 CHECK_MPI_OK( mp_init(&psub1));
1402 CHECK_MPI_OK( mp_init(&qsub1)); 1402 CHECK_MPI_OK( mp_init(&qsub1));
1403 CHECK_MPI_OK( mp_init(&e) ); 1403 CHECK_MPI_OK( mp_init(&e) );
1404 CHECK_MPI_OK( mp_init(&d) ); 1404 CHECK_MPI_OK( mp_init(&d) );
1405 CHECK_MPI_OK( mp_init(&d_p) ); 1405 CHECK_MPI_OK( mp_init(&d_p) );
1406 CHECK_MPI_OK( mp_init(&d_q) ); 1406 CHECK_MPI_OK( mp_init(&d_q) );
1407 CHECK_MPI_OK( mp_init(&qInv) ); 1407 CHECK_MPI_OK( mp_init(&qInv) );
1408 CHECK_MPI_OK( mp_init(&res) ); 1408 CHECK_MPI_OK( mp_init(&res) );
1409
1410 if (!key->modulus.data || !key->prime1.data || !key->prime2.data ||
1411 !key->publicExponent.data || !key->privateExponent.data ||
1412 !key->exponent1.data || !key->exponent2.data ||
1413 !key->coefficient.data) {
1414 /*call RSA_PopulatePrivateKey first, if the application wishes to
1415 * recover these parameters */
1416 err = MP_BADARG;
1417 goto cleanup;
1418 }
1419
1409 SECITEM_TO_MPINT(key->modulus, &n); 1420 SECITEM_TO_MPINT(key->modulus, &n);
1410 SECITEM_TO_MPINT(key->prime1, &p); 1421 SECITEM_TO_MPINT(key->prime1, &p);
1411 SECITEM_TO_MPINT(key->prime2, &q); 1422 SECITEM_TO_MPINT(key->prime2, &q);
1412 SECITEM_TO_MPINT(key->publicExponent, &e); 1423 SECITEM_TO_MPINT(key->publicExponent, &e);
1413 SECITEM_TO_MPINT(key->privateExponent, &d); 1424 SECITEM_TO_MPINT(key->privateExponent, &d);
1414 SECITEM_TO_MPINT(key->exponent1, &d_p); 1425 SECITEM_TO_MPINT(key->exponent1, &d_p);
1415 SECITEM_TO_MPINT(key->exponent2, &d_q); 1426 SECITEM_TO_MPINT(key->exponent2, &d_q);
1416 SECITEM_TO_MPINT(key->coefficient, &qInv); 1427 SECITEM_TO_MPINT(key->coefficient, &qInv);
1417 /* p > q */ 1428 /* p > q */
1418 if (mp_cmp(&p, &q) <= 0) { 1429 if (mp_cmp(&p, &q) <= 0) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 CHECK_MPI_OK( mp_sub_d(&q, 1, &qsub1) ); 1462 CHECK_MPI_OK( mp_sub_d(&q, 1, &qsub1) );
1452 CHECK_MPI_OK( mp_gcd(&e, &qsub1, &res) ); 1463 CHECK_MPI_OK( mp_gcd(&e, &qsub1, &res) );
1453 VERIFY_MPI_EQUAL_1(&res); 1464 VERIFY_MPI_EQUAL_1(&res);
1454 /* d*e == 1 mod p-1 */ 1465 /* d*e == 1 mod p-1 */
1455 CHECK_MPI_OK( mp_mulmod(&d, &e, &psub1, &res) ); 1466 CHECK_MPI_OK( mp_mulmod(&d, &e, &psub1, &res) );
1456 VERIFY_MPI_EQUAL_1(&res); 1467 VERIFY_MPI_EQUAL_1(&res);
1457 /* d*e == 1 mod q-1 */ 1468 /* d*e == 1 mod q-1 */
1458 CHECK_MPI_OK( mp_mulmod(&d, &e, &qsub1, &res) ); 1469 CHECK_MPI_OK( mp_mulmod(&d, &e, &qsub1, &res) );
1459 VERIFY_MPI_EQUAL_1(&res); 1470 VERIFY_MPI_EQUAL_1(&res);
1460 /* 1471 /*
1461 * The following errors can be recovered from. 1472 * The following errors can be recovered from. However, the purpose of this
1473 * function is to check consistency, so they are not.
1462 */ 1474 */
1463 /* d_p == d mod p-1 */ 1475 /* d_p == d mod p-1 */
1464 CHECK_MPI_OK( mp_mod(&d, &psub1, &res) ); 1476 CHECK_MPI_OK( mp_mod(&d, &psub1, &res) );
1465 if (mp_cmp(&d_p, &res) != 0) { 1477 VERIFY_MPI_EQUAL(&res, &d_p);
1466 » /* swap in the correct value */
1467 » CHECK_SEC_OK( swap_in_key_value(key->arena, &res, &key->exponent1) );
1468 }
1469 /* d_q == d mod q-1 */ 1478 /* d_q == d mod q-1 */
1470 CHECK_MPI_OK( mp_mod(&d, &qsub1, &res) ); 1479 CHECK_MPI_OK( mp_mod(&d, &qsub1, &res) );
1471 if (mp_cmp(&d_q, &res) != 0) { 1480 VERIFY_MPI_EQUAL(&res, &d_q);
1472 » /* swap in the correct value */
1473 » CHECK_SEC_OK( swap_in_key_value(key->arena, &res, &key->exponent2) );
1474 }
1475 /* q * q**-1 == 1 mod p */ 1481 /* q * q**-1 == 1 mod p */
1476 CHECK_MPI_OK( mp_mulmod(&q, &qInv, &p, &res) ); 1482 CHECK_MPI_OK( mp_mulmod(&q, &qInv, &p, &res) );
1477 if (mp_cmp_d(&res, 1) != 0) { 1483 VERIFY_MPI_EQUAL_1(&res);
1478 » /* compute the correct value */ 1484
1479 » CHECK_MPI_OK( mp_invmod(&q, &p, &qInv) );
1480 » CHECK_SEC_OK( swap_in_key_value(key->arena, &qInv, &key->coefficient) );
1481 }
1482 cleanup: 1485 cleanup:
1483 mp_clear(&n); 1486 mp_clear(&n);
1484 mp_clear(&p); 1487 mp_clear(&p);
1485 mp_clear(&q); 1488 mp_clear(&q);
1486 mp_clear(&psub1); 1489 mp_clear(&psub1);
1487 mp_clear(&qsub1); 1490 mp_clear(&qsub1);
1488 mp_clear(&e); 1491 mp_clear(&e);
1489 mp_clear(&d); 1492 mp_clear(&d);
1490 mp_clear(&d_p); 1493 mp_clear(&d_p);
1491 mp_clear(&d_q); 1494 mp_clear(&d_q);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 PRBool bl_parentForkedAfterC_Initialize; 1572 PRBool bl_parentForkedAfterC_Initialize;
1570 1573
1571 /* 1574 /*
1572 * Set fork flag so it can be tested in SKIP_AFTER_FORK on relevant platforms. 1575 * Set fork flag so it can be tested in SKIP_AFTER_FORK on relevant platforms.
1573 */ 1576 */
1574 void BL_SetForkState(PRBool forked) 1577 void BL_SetForkState(PRBool forked)
1575 { 1578 {
1576 bl_parentForkedAfterC_Initialize = forked; 1579 bl_parentForkedAfterC_Initialize = forked;
1577 } 1580 }
1578 1581
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698