From fba8cab200dc6dfcdef0fcfd6dc8cfa662f64faf Mon Sep 17 00:00:00 2001 From: night1rider Date: Thu, 16 Oct 2025 09:42:42 -0600 Subject: [PATCH] Refactor wc_rng_new to use wc_rng_new_ex, and to use WC_USE_DEVID as the devId if set at compile time --- wolfcrypt/src/random.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 77e4168e8..c73a02731 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1856,15 +1856,18 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz, WOLFSSL_ABI WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap) { - WC_RNG* rng; + int ret = 0; + WC_RNG* rng = NULL; - rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG); - if (rng) { - int error = _InitRng(rng, nonce, nonceSz, heap, INVALID_DEVID) != 0; - if (error) { - XFREE(rng, heap, DYNAMIC_TYPE_RNG); - rng = NULL; - } + /* Assume if WC_USE_DEVID it is intended for default usage */ +#ifdef WC_USE_DEVID + ret = wc_rng_new_ex(&rng, nonce, nonceSz, heap, WC_USE_DEVID); +#else + ret = wc_rng_new_ex(&rng, nonce, nonceSz, heap, INVALID_DEVID); +#endif + + if (ret != 0) { + return NULL; } return rng;