Skip to content

Commit d86575c

Browse files
authored
Merge pull request #9312 from night1rider/FixCallbackRngInit
Refactor wc_rng_new to use wc_rng_new_ex, and to use WC_USE_DEVID as the devId if set at compile time
2 parents 7fa53c8 + bd4099d commit d86575c

2 files changed

Lines changed: 61 additions & 58 deletions

File tree

wolfcrypt/src/random.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,15 +1856,18 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
18561856
WOLFSSL_ABI
18571857
WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap)
18581858
{
1859-
WC_RNG* rng;
1859+
int ret = 0;
1860+
WC_RNG* rng = NULL;
18601861

1861-
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG);
1862-
if (rng) {
1863-
int error = _InitRng(rng, nonce, nonceSz, heap, INVALID_DEVID) != 0;
1864-
if (error) {
1865-
XFREE(rng, heap, DYNAMIC_TYPE_RNG);
1866-
rng = NULL;
1867-
}
1862+
/* Assume if WC_USE_DEVID it is intended for default usage */
1863+
#ifdef WC_USE_DEVID
1864+
ret = wc_rng_new_ex(&rng, nonce, nonceSz, heap, WC_USE_DEVID);
1865+
#else
1866+
ret = wc_rng_new_ex(&rng, nonce, nonceSz, heap, INVALID_DEVID);
1867+
#endif
1868+
1869+
if (ret != 0) {
1870+
return NULL;
18681871
}
18691872

18701873
return rng;

0 commit comments

Comments
 (0)