mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 10:47:28 +02:00
review: removed WOLFSSL_ABI from and refactored args for wc_rng_new_ex, updated tests
This commit is contained in:
@ -1770,21 +1770,23 @@ WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap)
|
||||
}
|
||||
|
||||
|
||||
WOLFSSL_ABI
|
||||
WC_RNG* wc_rng_new_ex(byte* nonce, word32 nonceSz, void* heap, int devId)
|
||||
int wc_rng_new_ex(WC_RNG **rng, byte* nonce, word32 nonceSz,
|
||||
void* heap, int devId)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
|
||||
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG);
|
||||
if (rng) {
|
||||
int error = _InitRng(rng, nonce, nonceSz, heap, devId) != 0;
|
||||
if (error) {
|
||||
XFREE(rng, heap, DYNAMIC_TYPE_RNG);
|
||||
rng = NULL;
|
||||
}
|
||||
*rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG);
|
||||
if (*rng == NULL) {
|
||||
return MEMORY_E;
|
||||
}
|
||||
|
||||
return rng;
|
||||
ret = _InitRng(*rng, nonce, nonceSz, heap, devId);
|
||||
if (ret != 0) {
|
||||
XFREE(*rng, heap, DYNAMIC_TYPE_RNG);
|
||||
*rng = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15281,14 +15281,30 @@ static wc_test_ret_t random_rng_test(void)
|
||||
#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
|
||||
{
|
||||
byte nonce[8] = { 0 };
|
||||
/* Test dynamic RNG. */
|
||||
rng = wc_rng_new_ex(nonce, (word32)sizeof(nonce), HEAP_HINT, devId);
|
||||
|
||||
/* Test dynamic RNG */
|
||||
rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
|
||||
if (rng == NULL)
|
||||
return WC_TEST_RET_ENC_ERRNO;
|
||||
|
||||
ret = _rng_test(rng, WC_TEST_RET_ENC_NC);
|
||||
|
||||
wc_rng_free(rng);
|
||||
rng = NULL;
|
||||
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* Test dynamic RNG using extended API */
|
||||
ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
|
||||
HEAP_HINT, devId);
|
||||
if (ret != 0)
|
||||
return WC_TEST_RET_ENC_EC(ret);
|
||||
|
||||
ret = _rng_test(rng, WC_TEST_RET_ENC_NC);
|
||||
wc_rng_free(rng);
|
||||
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -205,8 +205,10 @@ WOLFSSL_API int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
|
||||
#endif /* HAVE_WNR */
|
||||
|
||||
|
||||
WOLFSSL_ABI WOLFSSL_API WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap);
|
||||
WOLFSSL_ABI WOLFSSL_API WC_RNG* wc_rng_new_ex(byte* nonce, word32 nonceSz, void* heap, int devId);
|
||||
WOLFSSL_ABI WOLFSSL_API WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz,
|
||||
void* heap);
|
||||
WOLFSSL_API int wc_rng_new_ex(WC_RNG **rng, byte* nonce, word32 nonceSz,
|
||||
void* heap, int devId);
|
||||
WOLFSSL_ABI WOLFSSL_API void wc_rng_free(WC_RNG* rng);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user