aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Möller <ulf@openssl.org>2000-02-28 20:19:39 +0000
committerUlf Möller <ulf@openssl.org>2000-02-28 20:19:39 +0000
commite64dceab743f0c2f4aef5dbc2b0e479c07bd2049 (patch)
treec6140980f1cacd91674441d1ffc893ab1d03f7a2
parentc9e1fe33be9d9c60f832c22442cff45bf5a667a5 (diff)
downloadopenssl-e64dceab743f0c2f4aef5dbc2b0e479c07bd2049.zip
openssl-e64dceab743f0c2f4aef5dbc2b0e479c07bd2049.tar.gz
openssl-e64dceab743f0c2f4aef5dbc2b0e479c07bd2049.tar.bz2
Switch for turning on the predictable "random" number generator.
-rw-r--r--crypto/rand/md_rand.c25
-rw-r--r--crypto/rand/rand_egd.c2
2 files changed, 20 insertions, 7 deletions
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c
index 6b158f0..583fc13 100644
--- a/crypto/rand/md_rand.c
+++ b/crypto/rand/md_rand.c
@@ -130,6 +130,10 @@
#include <openssl/rand.h>
+#ifdef BN_DEBUG
+# define PREDICT
+#endif
+
/* #define NORAND 1 */
/* #define PREDICT 1 */
@@ -141,6 +145,10 @@ static long md_count[2]={0,0};
static double entropy=0;
static int initialized=0;
+#ifdef PREDICT
+int rand_predictable=0;
+#endif
+
const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT;
static void ssleay_rand_cleanup(void);
@@ -306,6 +314,10 @@ static void ssleay_rand_initialize(void)
FILE *fh;
#endif
+#ifdef NORAND
+ return;
+#endif
+
CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
/* put in some default random data, we need more than just this */
#ifndef GETPID_IS_MEANINGLESS
@@ -354,13 +366,14 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
#endif
#ifdef PREDICT
- {
- static unsigned char val=0;
+ if (rand_predictable)
+ {
+ static unsigned char val=0;
- for (i=0; i<num; i++)
- buf[i]=val++;
- return(1);
- }
+ for (i=0; i<num; i++)
+ buf[i]=val++;
+ return(1);
+ }
#endif
/*
diff --git a/crypto/rand/rand_egd.c b/crypto/rand/rand_egd.c
index d834408..380c782 100644
--- a/crypto/rand/rand_egd.c
+++ b/crypto/rand/rand_egd.c
@@ -97,7 +97,7 @@ int RAND_egd(const char *path)
buf[1] = 255;
write(fd, buf, 2);
if (read(fd, buf, 1) != 1) goto err;
- if (buf[0] == 0) goto err;
+ if (buf[0] == 0) goto err;
num = read(fd, buf, 255);
if (num < 1) goto err;
RAND_seed(buf, num);