forked from wolfSSL/wolfssl
RNG Update
1. When the seed callback is enabled, allow wc_GenerateSeed() to be used as a default callback. 2. Modify all the tests and examples to use the default seed callback if the seed callback is enabled.
This commit is contained in:
@ -1586,6 +1586,9 @@ int bench_tls(void* args)
|
||||
|
||||
/* Initialize wolfSSL */
|
||||
wolfSSL_Init();
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
|
||||
/* Parse command line arguments */
|
||||
while ((ch = mygetopt(argc, argv, "?" "udeil:p:t:vT:sch:P:mS:")) != -1) {
|
||||
|
@ -3809,6 +3809,9 @@ exit:
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
wolfSSL_Init();
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
ChangeToWolfRoot();
|
||||
|
||||
#ifndef NO_WOLFSSL_CLIENT
|
||||
|
@ -387,6 +387,9 @@ void echoclient_test(void* args)
|
||||
#if defined(DEBUG_CYASSL) && !defined(WOLFSSL_MDK_SHELL)
|
||||
CyaSSL_Debugging_ON();
|
||||
#endif
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
#ifndef CYASSL_TIRTOS
|
||||
ChangeToWolfRoot();
|
||||
#endif
|
||||
|
@ -558,6 +558,9 @@ THREAD_RETURN CYASSL_THREAD echoserver_test(void* args)
|
||||
CyaSSL_Init();
|
||||
#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
|
||||
CyaSSL_Debugging_ON();
|
||||
#endif
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
ChangeToWolfRoot();
|
||||
#ifndef NO_WOLFSSL_SERVER
|
||||
|
@ -70,6 +70,9 @@ int main()
|
||||
const char* response = "hello there";
|
||||
char buffer[80];
|
||||
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method());
|
||||
if (ctx == NULL)
|
||||
err_sys("ctx new dtls client failed");
|
||||
|
@ -76,6 +76,9 @@ int main()
|
||||
const char* response = "well hello to you";
|
||||
char buffer[80];
|
||||
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
|
||||
if (ctx == NULL)
|
||||
err_sys("ctx new dtls server failed");
|
||||
|
@ -2885,6 +2885,9 @@ exit:
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
wolfSSL_Init();
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
ChangeToWolfRoot();
|
||||
|
||||
#ifndef NO_WOLFSSL_SERVER
|
||||
|
@ -64,6 +64,9 @@ int unit_test(int argc, char** argv)
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
#ifdef HAVE_WNR
|
||||
if (wc_InitNetRandom(wnrConfig, NULL, 5000) != 0)
|
||||
err_sys("Whitewood netRandom global config failed");
|
||||
|
@ -127,6 +127,9 @@ int testsuite_test(int argc, char** argv)
|
||||
#if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_TIRTOS)
|
||||
ChangeToWolfRoot();
|
||||
|
@ -1972,6 +1972,9 @@ int benchmark_init(void)
|
||||
printf("wolfCrypt_Init failed %d\n", ret);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
|
||||
bench_stats_init();
|
||||
|
||||
|
@ -304,6 +304,7 @@ int wc_SetSeed_Cb(wc_RngSeed_Cb cb)
|
||||
#define DRBG_FAILURE 1
|
||||
#define DRBG_NEED_RESEED 2
|
||||
#define DRBG_CONT_FAILURE 3
|
||||
#define DRBG_NO_SEED_CB 4
|
||||
|
||||
/* RNG health states */
|
||||
#define DRBG_NOT_INIT 0
|
||||
@ -815,10 +816,10 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
|
||||
if (ret == 0) {
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
if (seedCb == NULL) {
|
||||
ret = DRBG_FAILURE;
|
||||
ret = DRBG_NO_SEED_CB;
|
||||
}
|
||||
else {
|
||||
ret = seedCb(seed, seedSz);
|
||||
ret = seedCb(&rng->seed, seed, seedSz);
|
||||
if (ret != 0) {
|
||||
ret = DRBG_FAILURE;
|
||||
}
|
||||
|
@ -1441,6 +1441,10 @@ initDefaultName();
|
||||
err_sys("Error with wolfCrypt_Init!\n", -1003);
|
||||
}
|
||||
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STACK_SIZE
|
||||
StackSizeCheck(&args, wolfcrypt_test);
|
||||
#else
|
||||
@ -11405,9 +11409,10 @@ static int random_rng_test(void)
|
||||
#if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
|
||||
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
static int seed_cb(byte* output, word32 sz)
|
||||
static int seed_cb(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
word32 i;
|
||||
(void)os;
|
||||
/* Known answer test. Set the seed to the same value every time. */
|
||||
for (i = 0; i < sz; i++)
|
||||
output[i] = (byte)i;
|
||||
@ -11463,7 +11468,7 @@ static int rng_seed_test(void)
|
||||
ret = -7011;
|
||||
goto exit;
|
||||
}
|
||||
ret = wc_SetSeed_Cb(NULL);
|
||||
ret = wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
if (ret != 0) {
|
||||
ret = -7012;
|
||||
}
|
||||
|
@ -56,9 +56,6 @@ This library defines the interface APIs for X509 certificates.
|
||||
#endif
|
||||
#ifndef WC_RNG_TYPE_DEFINED
|
||||
typedef struct WC_RNG WC_RNG;
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
typedef int (*wc_RngSeed_Cb)(byte* seed, word32 sz);
|
||||
#endif
|
||||
#define WC_RNG_TYPE_DEFINED
|
||||
#endif
|
||||
|
||||
|
@ -194,9 +194,13 @@ struct WC_RNG {
|
||||
#define RNG WC_RNG
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WC_RNG_SEED_CB
|
||||
WOLFSSL_LOCAL
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
|
||||
#else
|
||||
WOLFSSL_API
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_WNR
|
||||
@ -236,7 +240,7 @@ WOLFSSL_API int wc_FreeRng(WC_RNG*);
|
||||
#endif
|
||||
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
typedef int (*wc_RngSeed_Cb)(byte* seed, word32 sz);
|
||||
typedef int (*wc_RngSeed_Cb)(OS_Seed* os, byte* seed, word32 sz);
|
||||
WOLFSSL_API int wc_SetSeed_Cb(wc_RngSeed_Cb cb);
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user