diff options
author | Colin Watson <cjwatson@debian.org> | 2005-01-04 13:07:27 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2005-01-04 13:07:27 +0000 |
commit | fd0f611b70a83d80fe8793af785542ee5541b7cd (patch) | |
tree | bededd22bb7eeec52e20083237ab7e4113445a16 /openbsd-compat/bsd-arc4random.c | |
parent | c44fe9a5b9d3db96a7249b04d915f17e4a3a3b04 (diff) | |
parent | ebd2ce335af5861020c79fddb1ae35c03bf036cf (diff) |
Merge 3.9p1 to the trunk.
Diffstat (limited to 'openbsd-compat/bsd-arc4random.c')
-rw-r--r-- | openbsd-compat/bsd-arc4random.c | 12 |
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 | ||
20 | RCSID("$Id: bsd-arc4random.c,v 1.8 2004/02/17 05:49:55 djm Exp $"); | 20 | RCSID("$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) | |||
56 | void arc4random_stir(void) | 56 | void 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; |