summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-arc4random.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/bsd-arc4random.c')
-rw-r--r--openbsd-compat/bsd-arc4random.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c
index 22003ff0a..5284e1af8 100644
--- a/openbsd-compat/bsd-arc4random.c
+++ b/openbsd-compat/bsd-arc4random.c
@@ -17,7 +17,7 @@
17#include "includes.h" 17#include "includes.h"
18#include "log.h" 18#include "log.h"
19 19
20RCSID("$Id: bsd-arc4random.c,v 1.8 2004/02/17 05:49:55 djm Exp $"); 20RCSID("$Id: bsd-arc4random.c,v 1.9 2004/07/18 23:30:40 djm Exp $");
21 21
22#ifndef HAVE_ARC4RANDOM 22#ifndef HAVE_ARC4RANDOM
23 23
@@ -56,13 +56,21 @@ unsigned int arc4random(void)
56void arc4random_stir(void) 56void arc4random_stir(void)
57{ 57{
58 unsigned char rand_buf[SEED_SIZE]; 58 unsigned char rand_buf[SEED_SIZE];
59 int i;
59 60
60 memset(&rc4, 0, sizeof(rc4)); 61 memset(&rc4, 0, sizeof(rc4));
61 if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0) 62 if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
62 fatal("Couldn't obtain random bytes (error %ld)", 63 fatal("Couldn't obtain random bytes (error %ld)",
63 ERR_get_error()); 64 ERR_get_error());
64 RC4_set_key(&rc4, sizeof(rand_buf), rand_buf); 65 RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
65 RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf); 66
67 /*
68 * Discard early keystream, as per recommendations in:
69 * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
70 */
71 for(i = 0; i <= 256; i += sizeof(rand_buf))
72 RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
73
66 memset(rand_buf, 0, sizeof(rand_buf)); 74 memset(rand_buf, 0, sizeof(rand_buf));
67 75
68 rc4_ready = REKEY_BYTES; 76 rc4_ready = REKEY_BYTES;