diff options
Diffstat (limited to 'src/lib/libcrypto/rand/md_rand.c')
-rw-r--r-- | src/lib/libcrypto/rand/md_rand.c | 31 |
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; | |||
157 | static void ssleay_rand_cleanup(void); | 159 | static void ssleay_rand_cleanup(void); |
158 | static void ssleay_rand_seed(const void *buf, int num); | 160 | static void ssleay_rand_seed(const void *buf, int num); |
159 | static void ssleay_rand_add(const void *buf, int num, double add_entropy); | 161 | static void ssleay_rand_add(const void *buf, int num, double add_entropy); |
160 | static int ssleay_rand_bytes(unsigned char *buf, int num); | 162 | static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo); |
163 | static int ssleay_rand_nopseudo_bytes(unsigned char *buf, int num); | ||
161 | static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num); | 164 | static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num); |
162 | static int ssleay_rand_status(void); | 165 | static int ssleay_rand_status(void); |
163 | 166 | ||
164 | RAND_METHOD rand_ssleay_meth={ | 167 | RAND_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 | ||
331 | static int ssleay_rand_bytes(unsigned char *buf, int num) | 334 | static 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 | ||
534 | static 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 */ |
531 | static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num) | 541 | static 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 | ||
547 | static int ssleay_rand_status(void) | 546 | static int ssleay_rand_status(void) |