summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/openbsd-compat/bsd-arc4random.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/openbsd-compat/bsd-arc4random.c')
-rw-r--r--crypto/openssh/openbsd-compat/bsd-arc4random.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/crypto/openssh/openbsd-compat/bsd-arc4random.c b/crypto/openssh/openbsd-compat/bsd-arc4random.c
index 22003ff..5284e1a 100644
--- a/crypto/openssh/openbsd-compat/bsd-arc4random.c
+++ b/crypto/openssh/openbsd-compat/bsd-arc4random.c
@@ -17,7 +17,7 @@
#include "includes.h"
#include "log.h"
-RCSID("$Id: bsd-arc4random.c,v 1.8 2004/02/17 05:49:55 djm Exp $");
+RCSID("$Id: bsd-arc4random.c,v 1.9 2004/07/18 23:30:40 djm Exp $");
#ifndef HAVE_ARC4RANDOM
@@ -56,13 +56,21 @@ unsigned int arc4random(void)
void arc4random_stir(void)
{
unsigned char rand_buf[SEED_SIZE];
+ int i;
memset(&rc4, 0, sizeof(rc4));
if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
fatal("Couldn't obtain random bytes (error %ld)",
ERR_get_error());
RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
- RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
+
+ /*
+ * Discard early keystream, as per recommendations in:
+ * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
+ */
+ for(i = 0; i <= 256; i += sizeof(rand_buf))
+ RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
+
memset(rand_buf, 0, sizeof(rand_buf));
rc4_ready = REKEY_BYTES;
OpenPOWER on IntegriCloud