summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/md_rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rand/md_rand.c')
-rw-r--r--src/lib/libcrypto/rand/md_rand.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c
index b2f04ff13e..fcdd3f2a84 100644
--- a/src/lib/libcrypto/rand/md_rand.c
+++ b/src/lib/libcrypto/rand/md_rand.c
@@ -109,6 +109,8 @@
109 * 109 *
110 */ 110 */
111 111
112#define OPENSSL_FIPSEVP
113
112#ifdef MD_RAND_DEBUG 114#ifdef MD_RAND_DEBUG
113# ifndef NDEBUG 115# ifndef NDEBUG
114# define NDEBUG 116# define NDEBUG
@@ -157,13 +159,14 @@ const char RAND_version[]="RAND" OPENSSL_VERSION_PTEXT;
157static void ssleay_rand_cleanup(void); 159static void ssleay_rand_cleanup(void);
158static void ssleay_rand_seed(const void *buf, int num); 160static void ssleay_rand_seed(const void *buf, int num);
159static void ssleay_rand_add(const void *buf, int num, double add_entropy); 161static void ssleay_rand_add(const void *buf, int num, double add_entropy);
160static int ssleay_rand_bytes(unsigned char *buf, int num); 162static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo);
163static int ssleay_rand_nopseudo_bytes(unsigned char *buf, int num);
161static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num); 164static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num);
162static int ssleay_rand_status(void); 165static int ssleay_rand_status(void);
163 166
164RAND_METHOD rand_ssleay_meth={ 167RAND_METHOD rand_ssleay_meth={
165 ssleay_rand_seed, 168 ssleay_rand_seed,
166 ssleay_rand_bytes, 169 ssleay_rand_nopseudo_bytes,
167 ssleay_rand_cleanup, 170 ssleay_rand_cleanup,
168 ssleay_rand_add, 171 ssleay_rand_add,
169 ssleay_rand_pseudo_bytes, 172 ssleay_rand_pseudo_bytes,
@@ -328,7 +331,7 @@ static void ssleay_rand_seed(const void *buf, int num)
328 ssleay_rand_add(buf, num, (double)num); 331 ssleay_rand_add(buf, num, (double)num);
329 } 332 }
330 333
331static int ssleay_rand_bytes(unsigned char *buf, int num) 334static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo)
332 { 335 {
333 static volatile int stirred_pool = 0; 336 static volatile int stirred_pool = 0;
334 int i,j,k,st_num,st_idx; 337 int i,j,k,st_num,st_idx;
@@ -517,7 +520,9 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
517 EVP_MD_CTX_cleanup(&m); 520 EVP_MD_CTX_cleanup(&m);
518 if (ok) 521 if (ok)
519 return(1); 522 return(1);
520 else 523 else if (pseudo)
524 return 0;
525 else
521 { 526 {
522 RANDerr(RAND_F_SSLEAY_RAND_BYTES,RAND_R_PRNG_NOT_SEEDED); 527 RANDerr(RAND_F_SSLEAY_RAND_BYTES,RAND_R_PRNG_NOT_SEEDED);
523 ERR_add_error_data(1, "You need to read the OpenSSL FAQ, " 528 ERR_add_error_data(1, "You need to read the OpenSSL FAQ, "
@@ -526,22 +531,16 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
526 } 531 }
527 } 532 }
528 533
534static int ssleay_rand_nopseudo_bytes(unsigned char *buf, int num)
535 {
536 return ssleay_rand_bytes(buf, num, 0);
537 }
538
529/* pseudo-random bytes that are guaranteed to be unique but not 539/* pseudo-random bytes that are guaranteed to be unique but not
530 unpredictable */ 540 unpredictable */
531static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num) 541static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
532 { 542 {
533 int ret; 543 return ssleay_rand_bytes(buf, num, 1);
534 unsigned long err;
535
536 ret = RAND_bytes(buf, num);
537 if (ret == 0)
538 {
539 err = ERR_peek_error();
540 if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
541 ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
542 ERR_clear_error();
543 }
544 return (ret);
545 } 544 }
546 545
547static int ssleay_rand_status(void) 546static int ssleay_rand_status(void)