Skip to content

Commit 1a5064c

Browse files
committed
add full support to wolfcrypt tests for random.c cryptocbs
1 parent aa444c1 commit 1a5064c

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

wolfcrypt/src/random.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,24 @@ 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)
1775+
{
1776+
WC_RNG* rng;
1777+
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+
}
1785+
}
1786+
1787+
return rng;
1788+
}
1789+
1790+
17731791
WOLFSSL_ABI
17741792
void wc_rng_free(WC_RNG* rng)
17751793
{
@@ -3777,6 +3795,28 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
37773795

37783796
#elif defined(NO_DEV_RANDOM)
37793797

3798+
/* Allow bare-metal targets to use cryptoCb as seed provider */
3799+
#if defined(WOLF_CRYPTO_CB)
3800+
3801+
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
3802+
{
3803+
int ret = WC_HW_E;
3804+
3805+
#ifndef WOLF_CRYPTO_CB_FIND
3806+
if (os->devId != INVALID_DEVID)
3807+
#endif
3808+
{
3809+
ret = wc_CryptoCb_RandomSeed(os, output, sz);
3810+
if (ret == CRYPTOCB_UNAVAILABLE) {
3811+
ret = WC_HW_E;
3812+
}
3813+
}
3814+
3815+
return ret;
3816+
}
3817+
3818+
#else /* defined(WOLF_CRYPTO_CB)*/
3819+
37803820
#error "you need to write an os specific wc_GenerateSeed() here"
37813821

37823822
/*
@@ -3786,6 +3826,8 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
37863826
}
37873827
*/
37883828

3829+
#endif /* !defined(WOLF_CRYPTO_CB) */
3830+
37893831
#else
37903832

37913833
/* may block */

wolfcrypt/test/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15282,7 +15282,7 @@ static wc_test_ret_t random_rng_test(void)
1528215282
{
1528315283
byte nonce[8] = { 0 };
1528415284
/* Test dynamic RNG. */
15285-
rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
15285+
rng = wc_rng_new_ex(nonce, (word32)sizeof(nonce), HEAP_HINT, devId);
1528615286
if (rng == NULL)
1528715287
return WC_TEST_RET_ENC_ERRNO;
1528815288

wolfssl/wolfcrypt/random.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ WOLFSSL_API int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
206206

207207

208208
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);
209210
WOLFSSL_ABI WOLFSSL_API void wc_rng_free(WC_RNG* rng);
210211

211212

0 commit comments

Comments
 (0)