mirror of https://github.com/wolfSSL/wolfssl.git
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.pull/4359/head
parent
0c6d8cfc22
commit
976402e04b
|
@ -1754,6 +1754,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:g")) != -1) {
|
||||
|
|
|
@ -4185,6 +4185,9 @@ exit:
|
|||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
wolfSSL_Init();
|
||||
#ifdef WC_RNG_SEED_CB
|
||||
wc_SetSeed_Cb(wc_GenerateSeed);
|
||||
#endif
|
||||
ChangeToWolfRoot();
|
||||
|
||||
#ifndef NO_WOLFSSL_CLIENT
|
||||
|
|
|
@ -385,6 +385,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
|
||||
|
|
|
@ -546,6 +546,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");
|
||||
|
|
|
@ -3315,6 +3315,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");
|
||||
|
|
|
@ -133,6 +133,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();
|
||||
|
|
|
@ -2037,6 +2037,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();
|
||||
|
||||
|
|
|
@ -307,6 +307,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
|
||||
|
@ -821,10 +822,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;
|
||||
}
|
||||
|
|
|
@ -1517,6 +1517,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
|
||||
|
@ -11667,9 +11671,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;
|
||||
|
@ -11725,7 +11730,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;
|
||||
}
|
||||
|
|
|
@ -65,9 +65,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
|
||||
#ifndef WC_DH_TYPE_DEFINED
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue