diff --git a/tests/api.c b/tests/api.c index 2468f73ac..f9f9adc6f 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33914,6 +33914,12 @@ static int test_mp_rand (void) ret = 0; } } + if (ret == 0) { + ret = mp_rand(&a, 0, &rng); + if (ret == BAD_FUNC_ARG) { + ret = 0; + } + } if (ret == 0) { ret = mp_rand(&a, digits, &rng); } diff --git a/wolfcrypt/src/wolfmath.c b/wolfcrypt/src/wolfmath.c index 0c17a0a27..42243380b 100644 --- a/wolfcrypt/src/wolfmath.c +++ b/wolfcrypt/src/wolfmath.c @@ -146,7 +146,7 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng) if (rng == NULL) { ret = MISSING_RNG_E; } - else if (a == NULL) { + else if (a == NULL || digits == 0) { ret = BAD_FUNC_ARG; }