Merge pull request #3613 from SparkiDev/sp_rand_prime_len

SP rand_prime: fix length check
This commit is contained in:
toddouska
2021-01-18 15:23:15 -08:00
committed by GitHub
2 changed files with 5 additions and 4 deletions

View File

@@ -13004,13 +13004,11 @@ int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap)
(void)heap;
if ((r == NULL) || (rng == NULL) || len < 0 ) {
/* Check NULL parameters and 0 is not prime so 0 bytes is invalid. */
if ((r == NULL) || (rng == NULL) || (len == 0)) {
err = MP_VAL;
}
if (len == 0)
return MP_OKAY;
if (err == MP_OKAY) {
/* get type */
if (len < 0) {

View File

@@ -30817,6 +30817,9 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
ret = mp_rand_prime(NULL, 32, rng, NULL);
if (ret != MP_VAL)
return -12789;
ret = mp_rand_prime(a, 0, rng, NULL);
if (ret != MP_VAL)
return -9969;
#endif
#if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)