Skip to content

Commit 55421a1

Browse files
committed
review: removed WOLFSSL_ABI from and refactored args for wc_rng_new_ex, updated tests
1 parent 1a5064c commit 55421a1

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

wolfcrypt/src/random.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,21 +1770,23 @@ WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap)
17701770
}
17711771

17721772

1773-
WOLFSSL_ABI
1774-
WC_RNG* wc_rng_new_ex(byte* nonce, word32 nonceSz, void* heap, int devId)
1773+
int wc_rng_new_ex(WC_RNG **rng, byte* nonce, word32 nonceSz,
1774+
void* heap, int devId)
17751775
{
1776-
WC_RNG* rng;
1776+
int ret;
17771777

1778-
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG);
1779-
if (rng) {
1780-
int error = _InitRng(rng, nonce, nonceSz, heap, devId) != 0;
1781-
if (error) {
1782-
XFREE(rng, heap, DYNAMIC_TYPE_RNG);
1783-
rng = NULL;
1784-
}
1778+
*rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG);
1779+
if (*rng == NULL) {
1780+
return MEMORY_E;
17851781
}
17861782

1787-
return rng;
1783+
ret = _InitRng(*rng, nonce, nonceSz, heap, devId);
1784+
if (ret != 0) {
1785+
XFREE(*rng, heap, DYNAMIC_TYPE_RNG);
1786+
*rng = NULL;
1787+
}
1788+
1789+
return ret;
17881790
}
17891791

17901792

wolfcrypt/test/test.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15281,14 +15281,30 @@ static wc_test_ret_t random_rng_test(void)
1528115281
#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
1528215282
{
1528315283
byte nonce[8] = { 0 };
15284-
/* Test dynamic RNG. */
15285-
rng = wc_rng_new_ex(nonce, (word32)sizeof(nonce), HEAP_HINT, devId);
15284+
15285+
/* Test dynamic RNG */
15286+
rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
1528615287
if (rng == NULL)
1528715288
return WC_TEST_RET_ENC_ERRNO;
1528815289

1528915290
ret = _rng_test(rng, WC_TEST_RET_ENC_NC);
15291+
wc_rng_free(rng);
15292+
rng = NULL;
15293+
15294+
if (ret != 0)
15295+
return ret;
15296+
15297+
/* Test dynamic RNG using extended API */
15298+
ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
15299+
HEAP_HINT, devId);
15300+
if (ret != 0)
15301+
return WC_TEST_RET_ENC_EC(ret);
1529015302

15303+
ret = _rng_test(rng, WC_TEST_RET_ENC_NC);
1529115304
wc_rng_free(rng);
15305+
15306+
if (ret != 0)
15307+
return ret;
1529215308
}
1529315309
#endif
1529415310

wolfssl/wolfcrypt/random.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ WOLFSSL_API int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
205205
#endif /* HAVE_WNR */
206206

207207

208-
WOLFSSL_ABI WOLFSSL_API WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap);
209-
WOLFSSL_ABI WOLFSSL_API WC_RNG* wc_rng_new_ex(byte* nonce, word32 nonceSz, void* heap, int devId);
208+
WOLFSSL_ABI WOLFSSL_API WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz,
209+
void* heap);
210+
WOLFSSL_API int wc_rng_new_ex(WC_RNG **rng, byte* nonce, word32 nonceSz,
211+
void* heap, int devId);
210212
WOLFSSL_ABI WOLFSSL_API void wc_rng_free(WC_RNG* rng);
211213

212214

0 commit comments

Comments
 (0)