diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index e8070a355..bd8a2142a 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -917,6 +917,9 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz) if (rng == NULL || output == NULL) return BAD_FUNC_ARG; + if (sz == 0) + return 0; + #ifdef WOLF_CRYPTO_CB if (rng->devId != INVALID_DEVID) { ret = wc_CryptoCb_RandomBlock(rng, output, sz); diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index af1c9c244..fc093e8e7 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -9240,7 +9240,7 @@ int sp_div_2d(sp_int* a, int e, sp_int* r, sp_int* rem) rem->used = (e + SP_WORD_SIZE - 1) >> SP_WORD_SHIFT; e &= SP_WORD_MASK; if (e > 0) { - rem->dp[rem->used - 1] &= (1 << e) - 1; + rem->dp[rem->used - 1] &= ((sp_int_digit)1 << e) - 1; } sp_clamp(rem); } @@ -12979,10 +12979,13 @@ int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap) (void)heap; - if ((r == NULL) || (rng == NULL)) { + 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) {