diff options
author | Damien Miller <djm@mindrot.org> | 2001-03-19 09:38:15 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-03-19 09:38:15 +1100 |
commit | 60bc51735643baa1b7fb237ea56303fed454dadb (patch) | |
tree | 8ece761df99755046be27984f4ea8dcbca1d99d5 /openbsd-compat | |
parent | b399be4436914e23dd066482a371e068f2724f5c (diff) |
- (djm) Seed PRNG at startup, rather than waiting for arc4random calls to
do it implicitly.
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/bsd-arc4random.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c index 87c7da5f..2f313070 100644 --- a/openbsd-compat/bsd-arc4random.c +++ b/openbsd-compat/bsd-arc4random.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-arc4random.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); +RCSID("$Id: bsd-arc4random.c,v 1.3 2001/03/18 22:38:16 djm Exp $"); #ifndef HAVE_ARC4RANDOM @@ -43,10 +43,15 @@ static RC4_KEY rc4; unsigned int arc4random(void) { unsigned int r = 0; + static int first_time = 1; - if (rc4_ready <= 0) + if (rc4_ready <= 0) { + if (!first_time) + seed_rng(); + first_time = 0; arc4random_stir(); - + } + RC4(&rc4, sizeof(r), (unsigned char *)&r, (unsigned char *)&r); rc4_ready -= sizeof(r); @@ -57,17 +62,14 @@ unsigned int arc4random(void) void arc4random_stir(void) { unsigned char rand_buf[SEED_SIZE]; - - memset(&rc4, 0, sizeof(rc4)); - - seed_rng(); - RAND_bytes(rand_buf, sizeof(rand_buf)); - + memset(&rc4, 0, sizeof(rc4)); + if (!RAND_bytes(rand_buf, sizeof(rand_buf))) + fatal("Couldn't obtain random bytes (error %ld)", + ERR_get_error()); RC4_set_key(&rc4, sizeof(rand_buf), rand_buf); - memset(rand_buf, 0, sizeof(rand_buf)); - + rc4_ready = REKEY_BYTES; } #endif /* !HAVE_ARC4RANDOM */ |