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

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

Issue 457963002: Update to NSS 3.16.4. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Include certdata.c changes. Created 6 years, 4 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
« no previous file with comments | « nss/lib/ckfw/builtins/nssckbi.h ('k') | nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_crldp.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 CHECK_MPI_OK( mp_init(&d) ); 1379 CHECK_MPI_OK( mp_init(&d) );
1380 CHECK_MPI_OK( mp_init(&d_p) ); 1380 CHECK_MPI_OK( mp_init(&d_p) );
1381 CHECK_MPI_OK( mp_init(&d_q) ); 1381 CHECK_MPI_OK( mp_init(&d_q) );
1382 CHECK_MPI_OK( mp_init(&qInv) ); 1382 CHECK_MPI_OK( mp_init(&qInv) );
1383 CHECK_MPI_OK( mp_init(&res) ); 1383 CHECK_MPI_OK( mp_init(&res) );
1384 1384
1385 if (!key->modulus.data || !key->prime1.data || !key->prime2.data || 1385 if (!key->modulus.data || !key->prime1.data || !key->prime2.data ||
1386 !key->publicExponent.data || !key->privateExponent.data || 1386 !key->publicExponent.data || !key->privateExponent.data ||
1387 !key->exponent1.data || !key->exponent2.data || 1387 !key->exponent1.data || !key->exponent2.data ||
1388 !key->coefficient.data) { 1388 !key->coefficient.data) {
1389 /*call RSA_PopulatePrivateKey first, if the application wishes to 1389 /* call RSA_PopulatePrivateKey first, if the application wishes to
1390 * recover these parameters */ 1390 * recover these parameters */
1391 err = MP_BADARG; 1391 err = MP_BADARG;
1392 goto cleanup; 1392 goto cleanup;
1393 } 1393 }
1394 1394
1395 SECITEM_TO_MPINT(key->modulus, &n); 1395 SECITEM_TO_MPINT(key->modulus, &n);
1396 SECITEM_TO_MPINT(key->prime1, &p); 1396 SECITEM_TO_MPINT(key->prime1, &p);
1397 SECITEM_TO_MPINT(key->prime2, &q); 1397 SECITEM_TO_MPINT(key->prime2, &q);
1398 SECITEM_TO_MPINT(key->publicExponent, &e); 1398 SECITEM_TO_MPINT(key->publicExponent, &e);
1399 SECITEM_TO_MPINT(key->privateExponent, &d); 1399 SECITEM_TO_MPINT(key->privateExponent, &d);
1400 SECITEM_TO_MPINT(key->exponent1, &d_p); 1400 SECITEM_TO_MPINT(key->exponent1, &d_p);
1401 SECITEM_TO_MPINT(key->exponent2, &d_q); 1401 SECITEM_TO_MPINT(key->exponent2, &d_q);
1402 SECITEM_TO_MPINT(key->coefficient, &qInv); 1402 SECITEM_TO_MPINT(key->coefficient, &qInv);
1403 /* p > q */ 1403 /* p > q */
1404 if (mp_cmp(&p, &q) <= 0) { 1404 if (mp_cmp(&p, &q) <= 0) {
1405 rv = SECFailure; 1405 rv = SECFailure;
1406 goto cleanup; 1406 goto cleanup;
1407 } 1407 }
1408 #define VERIFY_MPI_EQUAL(m1, m2) \ 1408 #define VERIFY_MPI_EQUAL(m1, m2) \
1409 if (mp_cmp(m1, m2) != 0) { \ 1409 if (mp_cmp(m1, m2) != 0) { \
1410 rv = SECFailure; \ 1410 rv = SECFailure; \
1411 goto cleanup; \ 1411 goto cleanup; \
1412 } 1412 }
1413 #define VERIFY_MPI_EQUAL_1(m) \ 1413 #define VERIFY_MPI_EQUAL_1(m) \
1414 if (mp_cmp_d(m, 1) != 0) { \ 1414 if (mp_cmp_d(m, 1) != 0) { \
1415 rv = SECFailure; \ 1415 rv = SECFailure; \
1416 goto cleanup; \ 1416 goto cleanup; \
1417 } 1417 }
1418 /*
1419 * The following errors cannot be recovered from.
1420 */
1421 /* n == p * q */ 1418 /* n == p * q */
1422 CHECK_MPI_OK( mp_mul(&p, &q, &res) ); 1419 CHECK_MPI_OK( mp_mul(&p, &q, &res) );
1423 VERIFY_MPI_EQUAL(&res, &n); 1420 VERIFY_MPI_EQUAL(&res, &n);
1424 /* gcd(e, p-1) == 1 */ 1421 /* gcd(e, p-1) == 1 */
1425 CHECK_MPI_OK( mp_sub_d(&p, 1, &psub1) ); 1422 CHECK_MPI_OK( mp_sub_d(&p, 1, &psub1) );
1426 CHECK_MPI_OK( mp_gcd(&e, &psub1, &res) ); 1423 CHECK_MPI_OK( mp_gcd(&e, &psub1, &res) );
1427 VERIFY_MPI_EQUAL_1(&res); 1424 VERIFY_MPI_EQUAL_1(&res);
1428 /* gcd(e, q-1) == 1 */ 1425 /* gcd(e, q-1) == 1 */
1429 CHECK_MPI_OK( mp_sub_d(&q, 1, &qsub1) ); 1426 CHECK_MPI_OK( mp_sub_d(&q, 1, &qsub1) );
1430 CHECK_MPI_OK( mp_gcd(&e, &qsub1, &res) ); 1427 CHECK_MPI_OK( mp_gcd(&e, &qsub1, &res) );
1431 VERIFY_MPI_EQUAL_1(&res); 1428 VERIFY_MPI_EQUAL_1(&res);
1432 /* d*e == 1 mod p-1 */ 1429 /* d*e == 1 mod p-1 */
1433 CHECK_MPI_OK( mp_mulmod(&d, &e, &psub1, &res) ); 1430 CHECK_MPI_OK( mp_mulmod(&d, &e, &psub1, &res) );
1434 VERIFY_MPI_EQUAL_1(&res); 1431 VERIFY_MPI_EQUAL_1(&res);
1435 /* d*e == 1 mod q-1 */ 1432 /* d*e == 1 mod q-1 */
1436 CHECK_MPI_OK( mp_mulmod(&d, &e, &qsub1, &res) ); 1433 CHECK_MPI_OK( mp_mulmod(&d, &e, &qsub1, &res) );
1437 VERIFY_MPI_EQUAL_1(&res); 1434 VERIFY_MPI_EQUAL_1(&res);
1438 /*
1439 * The following errors can be recovered from. However, the purpose of this
1440 * function is to check consistency, so they are not.
1441 */
1442 /* d_p == d mod p-1 */ 1435 /* d_p == d mod p-1 */
1443 CHECK_MPI_OK( mp_mod(&d, &psub1, &res) ); 1436 CHECK_MPI_OK( mp_mod(&d, &psub1, &res) );
1444 VERIFY_MPI_EQUAL(&res, &d_p); 1437 VERIFY_MPI_EQUAL(&res, &d_p);
1445 /* d_q == d mod q-1 */ 1438 /* d_q == d mod q-1 */
1446 CHECK_MPI_OK( mp_mod(&d, &qsub1, &res) ); 1439 CHECK_MPI_OK( mp_mod(&d, &qsub1, &res) );
1447 VERIFY_MPI_EQUAL(&res, &d_q); 1440 VERIFY_MPI_EQUAL(&res, &d_q);
1448 /* q * q**-1 == 1 mod p */ 1441 /* q * q**-1 == 1 mod p */
1449 CHECK_MPI_OK( mp_mulmod(&q, &qInv, &p, &res) ); 1442 CHECK_MPI_OK( mp_mulmod(&q, &qInv, &p, &res) );
1450 VERIFY_MPI_EQUAL_1(&res); 1443 VERIFY_MPI_EQUAL_1(&res);
1451 1444
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 PRBool bl_parentForkedAfterC_Initialize; 1532 PRBool bl_parentForkedAfterC_Initialize;
1540 1533
1541 /* 1534 /*
1542 * Set fork flag so it can be tested in SKIP_AFTER_FORK on relevant platforms. 1535 * Set fork flag so it can be tested in SKIP_AFTER_FORK on relevant platforms.
1543 */ 1536 */
1544 void BL_SetForkState(PRBool forked) 1537 void BL_SetForkState(PRBool forked)
1545 { 1538 {
1546 bl_parentForkedAfterC_Initialize = forked; 1539 bl_parentForkedAfterC_Initialize = forked;
1547 } 1540 }
1548 1541
OLDNEW
« no previous file with comments | « nss/lib/ckfw/builtins/nssckbi.h ('k') | nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_crldp.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698