Commit 3cd8547a2018ada88a4303067a2aa15eadc17f39 mixed the current time
into the randomness pool each time RAND_bytes is called. As the
resolution of gettimeofday() is limited, I propose to reseed the PRNG
each time a PID change is detected.
This change might also be an alternative for platforms where the
gettimeofday() call is prohibitively slow.
--
Florian Weimer / Red Hat Product Security Team
commit 136a8da88ff52ad32f894fb0ecbcab5f4205ca49
Author: Florian Weimer <fwei...@redhat.com>
Date: Wed Jan 15 16:46:17 2014 +0100
ssleay_rand_bytes: Re-seed on PID change
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c
index 6cab308..75382b5 100644
--- a/crypto/rand/md_rand.c
+++ b/crypto/rand/md_rand.c
@@ -153,6 +153,9 @@ static unsigned char md[MD_DIGEST_LENGTH];
static long md_count[2]={0,0};
static double entropy=0;
static int initialized=0;
+#ifndef GETPID_IS_MEANINGLESS
+static pid_t prev_pid=0;
+#endif
static unsigned int crypto_lock_rand = 0; /* may be set only when a thread
* holds CRYPTO_LOCK_RAND
@@ -201,6 +204,7 @@ static void ssleay_rand_cleanup(void)
md_count[1]=0;
entropy=0;
initialized=0;
+ prev_pid=0;
}
static int ssleay_rand_add(const void *buf, int num, double add)
@@ -439,7 +443,16 @@ static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo)
{
RAND_poll();
initialized = 1;
+ prev_pid = curr_pid;
+ }
+#ifndef GETPID_IS_MEANINGLESS
+ if (curr_pid != prev_pid)
+ {
+ RAND_poll();
+ prev_pid = curr_pid;
}
+#endif
+
if (!stirred_pool)
do_stir_pool = 1;