Merge pull request #4945 from kaleb-himes/ZD13795

Fix for ZD13795 and also remove all-caps parameter
This commit is contained in:
David Garske
2022-04-04 08:25:10 -07:00
committed by GitHub
4 changed files with 12 additions and 12 deletions

View File

@ -5000,12 +5000,12 @@ LBL_B:mp_clear (&b);
static const int USE_BBS = 1; static const int USE_BBS = 1;
int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap) int mp_rand_prime(mp_int* a, int len, WC_RNG* rng, void* heap)
{ {
int err, res, type; int err, res, type;
byte* buf; byte* buf;
if (N == NULL || rng == NULL) if (a == NULL || rng == NULL)
return MP_VAL; return MP_VAL;
/* get type */ /* get type */
@ -5045,7 +5045,7 @@ int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap)
buf[len-1] |= 0x01 | ((type & USE_BBS) ? 0x02 : 0x00); buf[len-1] |= 0x01 | ((type & USE_BBS) ? 0x02 : 0x00);
/* load value */ /* load value */
if ((err = mp_read_unsigned_bin(N, buf, len)) != MP_OKAY) { if ((err = mp_read_unsigned_bin(a, buf, len)) != MP_OKAY) {
XFREE(buf, heap, DYNAMIC_TYPE_RSA); XFREE(buf, heap, DYNAMIC_TYPE_RSA);
return err; return err;
} }
@ -5055,7 +5055,7 @@ int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap)
* of a 1024-bit candidate being a false positive, when it is our * of a 1024-bit candidate being a false positive, when it is our
* prime candidate. (Note 4.49 of Handbook of Applied Cryptography.) * prime candidate. (Note 4.49 of Handbook of Applied Cryptography.)
* Using 8 because we've always used 8. */ * Using 8 because we've always used 8. */
if ((err = mp_prime_is_prime_ex(N, 8, &res, rng)) != MP_OKAY) { if ((err = mp_prime_is_prime_ex(a, 8, &res, rng)) != MP_OKAY) {
XFREE(buf, heap, DYNAMIC_TYPE_RSA); XFREE(buf, heap, DYNAMIC_TYPE_RSA);
return err; return err;
} }

View File

@ -5208,7 +5208,7 @@ int mp_cond_swap_ct(mp_int * a, mp_int * b, int c, int m)
static int fp_gcd(fp_int *a, fp_int *b, fp_int *c); static int fp_gcd(fp_int *a, fp_int *b, fp_int *c);
static int fp_lcm(fp_int *a, fp_int *b, fp_int *c); static int fp_lcm(fp_int *a, fp_int *b, fp_int *c);
static int fp_randprime(fp_int* N, int len, WC_RNG* rng, void* heap); static int fp_randprime(fp_int* a, int len, WC_RNG* rng, void* heap);
int mp_gcd(fp_int *a, fp_int *b, fp_int *c) int mp_gcd(fp_int *a, fp_int *b, fp_int *c)
{ {
@ -5221,11 +5221,11 @@ int mp_lcm(fp_int *a, fp_int *b, fp_int *c)
return fp_lcm(a, b, c); return fp_lcm(a, b, c);
} }
int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap) int mp_rand_prime(mp_int* a, int len, WC_RNG* rng, void* heap)
{ {
int err; int err;
err = fp_randprime(N, len, rng, heap); err = fp_randprime(a, len, rng, heap);
switch(err) { switch(err) {
case FP_VAL: case FP_VAL:
return MP_VAL; return MP_VAL;
@ -5245,7 +5245,7 @@ int mp_exch (mp_int * a, mp_int * b)
int fp_randprime(fp_int* N, int len, WC_RNG* rng, void* heap) int fp_randprime(fp_int* a, int len, WC_RNG* rng, void* heap)
{ {
static const int USE_BBS = 1; static const int USE_BBS = 1;
int err, type; int err, type;
@ -5293,7 +5293,7 @@ int fp_randprime(fp_int* N, int len, WC_RNG* rng, void* heap)
buf[len-1] |= 0x01 | ((type & USE_BBS) ? 0x02 : 0x00); buf[len-1] |= 0x01 | ((type & USE_BBS) ? 0x02 : 0x00);
/* load value */ /* load value */
err = fp_read_unsigned_bin(N, buf, len); err = fp_read_unsigned_bin(a, buf, len);
if (err != 0) { if (err != 0) {
XFREE(buf, heap, DYNAMIC_TYPE_TMP_BUFFER); XFREE(buf, heap, DYNAMIC_TYPE_TMP_BUFFER);
return err; return err;
@ -5304,7 +5304,7 @@ int fp_randprime(fp_int* N, int len, WC_RNG* rng, void* heap)
* of a 1024-bit candidate being a false positive, when it is our * of a 1024-bit candidate being a false positive, when it is our
* prime candidate. (Note 4.49 of Handbook of Applied Cryptography.) * prime candidate. (Note 4.49 of Handbook of Applied Cryptography.)
* Using 8 because we've always used 8 */ * Using 8 because we've always used 8 */
mp_prime_is_prime_ex(N, 8, &isPrime, rng); mp_prime_is_prime_ex(a, 8, &isPrime, rng);
} while (isPrime == FP_NO); } while (isPrime == FP_NO);
XMEMSET(buf, 0, len); XMEMSET(buf, 0, len);

View File

@ -398,7 +398,7 @@ MP_API int mp_radix_size (mp_int * a, int radix, int *size);
#ifdef WOLFSSL_KEY_GEN #ifdef WOLFSSL_KEY_GEN
MP_API int mp_gcd (mp_int * a, mp_int * b, mp_int * c); MP_API int mp_gcd (mp_int * a, mp_int * b, mp_int * c);
MP_API int mp_lcm (mp_int * a, mp_int * b, mp_int * c); MP_API int mp_lcm (mp_int * a, mp_int * b, mp_int * c);
MP_API int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap); MP_API int mp_rand_prime(mp_int* a, int len, WC_RNG* rng, void* heap);
#endif #endif
MP_API int mp_cnt_lsb(mp_int *a); MP_API int mp_cnt_lsb(mp_int *a);

View File

@ -843,7 +843,7 @@ MP_API int mp_prime_is_prime_ex(mp_int* a, int t, int* result, WC_RNG* rng);
#ifdef WOLFSSL_KEY_GEN #ifdef WOLFSSL_KEY_GEN
MP_API int mp_gcd(fp_int *a, fp_int *b, fp_int *c); MP_API int mp_gcd(fp_int *a, fp_int *b, fp_int *c);
MP_API int mp_lcm(fp_int *a, fp_int *b, fp_int *c); MP_API int mp_lcm(fp_int *a, fp_int *b, fp_int *c);
MP_API int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap); MP_API int mp_rand_prime(mp_int* a, int len, WC_RNG* rng, void* heap);
MP_API int mp_exch(mp_int *a, mp_int *b); MP_API int mp_exch(mp_int *a, mp_int *b);
#endif /* WOLFSSL_KEY_GEN */ #endif /* WOLFSSL_KEY_GEN */
MP_API int mp_cond_swap_ct (mp_int * a, mp_int * b, int c, int m); MP_API int mp_cond_swap_ct (mp_int * a, mp_int * b, int c, int m);