summaryrefslogtreecommitdiffstats
path: root/security/nss/lib/freebl/rsa.c
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-29 09:07:42 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-29 09:07:42 +0200
commitaff03b0a67c41cf7af5df9c9eef715a8b27a2667 (patch)
treeaa2909ae4718f81c83c8cfb68c1f5a23485b3173 /security/nss/lib/freebl/rsa.c
parentbdb4ff581677ad1cd411b55a68c87534f9a64882 (diff)
parent11caf6ecb3cb8c84d2355a6c6e9580a290147e92 (diff)
downloadUXP-aff03b0a67c41cf7af5df9c9eef715a8b27a2667.tar
UXP-aff03b0a67c41cf7af5df9c9eef715a8b27a2667.tar.gz
UXP-aff03b0a67c41cf7af5df9c9eef715a8b27a2667.tar.lz
UXP-aff03b0a67c41cf7af5df9c9eef715a8b27a2667.tar.xz
UXP-aff03b0a67c41cf7af5df9c9eef715a8b27a2667.zip
Merge branch 'master' of https://github.com/MoonchildProductions/UXP into js_dom_performance-resource-timing_1
Diffstat (limited to 'security/nss/lib/freebl/rsa.c')
-rw-r--r--security/nss/lib/freebl/rsa.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/security/nss/lib/freebl/rsa.c b/security/nss/lib/freebl/rsa.c
index a08636de6..7354d9317 100644
--- a/security/nss/lib/freebl/rsa.c
+++ b/security/nss/lib/freebl/rsa.c
@@ -276,10 +276,7 @@ RSAPrivateKey *
RSA_NewKey(int keySizeInBits, SECItem *publicExponent)
{
unsigned int primeLen;
- mp_int p = { 0, 0, 0, NULL };
- mp_int q = { 0, 0, 0, NULL };
- mp_int e = { 0, 0, 0, NULL };
- mp_int d = { 0, 0, 0, NULL };
+ mp_int p, q, e, d;
int kiter;
int max_attempts;
mp_err err = MP_OKAY;
@@ -293,46 +290,34 @@ RSA_NewKey(int keySizeInBits, SECItem *publicExponent)
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return NULL;
}
- /* 1. Set the public exponent and check if it's uneven and greater than 2.*/
- MP_DIGITS(&e) = 0;
- CHECK_MPI_OK(mp_init(&e));
- SECITEM_TO_MPINT(*publicExponent, &e);
- if (mp_iseven(&e) || !(mp_cmp_d(&e, 2) > 0)) {
- PORT_SetError(SEC_ERROR_INVALID_ARGS);
- goto cleanup;
- }
-#ifndef NSS_FIPS_DISABLED
- /* Check that the exponent is not smaller than 65537 */
- if (mp_cmp_d(&e, 0x10001) < 0) {
- PORT_SetError(SEC_ERROR_INVALID_ARGS);
- goto cleanup;
- }
-#endif
-
- /* 2. Allocate arena & key */
+ /* 1. Allocate arena & key */
arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE);
if (!arena) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
- goto cleanup;
+ return NULL;
}
key = PORT_ArenaZNew(arena, RSAPrivateKey);
if (!key) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
- goto cleanup;
+ PORT_FreeArena(arena, PR_TRUE);
+ return NULL;
}
key->arena = arena;
/* length of primes p and q (in bytes) */
primeLen = keySizeInBits / (2 * PR_BITS_PER_BYTE);
MP_DIGITS(&p) = 0;
MP_DIGITS(&q) = 0;
+ MP_DIGITS(&e) = 0;
MP_DIGITS(&d) = 0;
CHECK_MPI_OK(mp_init(&p));
CHECK_MPI_OK(mp_init(&q));
+ CHECK_MPI_OK(mp_init(&e));
CHECK_MPI_OK(mp_init(&d));
- /* 3. Set the version number (PKCS1 v1.5 says it should be zero) */
+ /* 2. Set the version number (PKCS1 v1.5 says it should be zero) */
SECITEM_AllocItem(arena, &key->version, 1);
key->version.data[0] = 0;
-
+ /* 3. Set the public exponent */
+ SECITEM_TO_MPINT(*publicExponent, &e);
kiter = 0;
max_attempts = 5 * (keySizeInBits / 2); /* FIPS 186-4 B.3.3 steps 4.7 and 5.8 */
do {