From a97dbb8a14493b971c00ae514ad131344fcb246a Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 7 May 2012 19:36:19 -0700 Subject: [PATCH] global rng added to RAND_bytes --- src/ssl.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index cd955dd79..8af1e2903 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -4448,19 +4448,6 @@ int CyaSSL_set_compression(CYASSL* ssl) } - int CyaSSL_RAND_bytes(unsigned char* buf, int num) - { - RNG rng; - - CYASSL_ENTER("RAND_bytes"); - if (InitRng(&rng)) - return 0; - - RNG_GenerateBlock(&rng, buf, num); - - return 1; - } - void CyaSSL_RAND_add(const void* add, int len, double entropy) { @@ -5684,6 +5671,26 @@ static int initGlobalRNG = 0; } + int CyaSSL_RAND_bytes(unsigned char* buf, int num) + { + RNG tmpRNG; + RNG* rng = &tmpRNG; + + CYASSL_ENTER("RAND_bytes"); + if (InitRng(&tmpRNG) != 0) { + CYASSL_MSG("Bad RNG Init, trying global"); + if (initGlobalRNG == 0) { + CYASSL_MSG("Global RNG no Init"); + return 0; + } + rng = &globalRNG; + } + + RNG_GenerateBlock(rng, buf, num); + + return 1; + } + CYASSL_BN_CTX* CyaSSL_BN_CTX_new(void) { static int ctx; /* ctaocrypt doesn't now need ctx */