Permalink
Browse files

global rng added to RAND_bytes

  • Loading branch information...
1 parent 968dfc4 commit a97dbb8a14493b971c00ae514ad131344fcb246a @toddouska toddouska committed May 8, 2012
Showing with 20 additions and 13 deletions.
  1. +20 −13 src/ssl.c
View
@@ -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 */

0 comments on commit a97dbb8

Please sign in to comment.