summaryrefslogtreecommitdiffstats
path: root/bsd-arc4random.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-08-30 00:40:09 +0200
committerDamien Miller <djm@mindrot.org>2000-08-30 00:40:09 +0200
commitc30d35ce3234371c20a388d81b4bafd389d3019f (patch)
tree700aa922a381fa51c8334f9d09cc8481d0619db3 /bsd-arc4random.c
parent - (djm) Compile warning fixes from Mark Miller <markm@swoon.net> (diff)
downloadopenssh-c30d35ce3234371c20a388d81b4bafd389d3019f.tar.xz
openssh-c30d35ce3234371c20a388d81b4bafd389d3019f.zip
- (djm) Periodically rekey arc4random
- (djm) Clean up diff against OpenBSD.
Diffstat (limited to 'bsd-arc4random.c')
-rw-r--r--bsd-arc4random.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/bsd-arc4random.c b/bsd-arc4random.c
index 4c2f0854f..a1f515461 100644
--- a/bsd-arc4random.c
+++ b/bsd-arc4random.c
@@ -33,6 +33,12 @@
#ifndef HAVE_ARC4RANDOM
+/* Size of key to use */
+#define SEED_SIZE 20
+
+/* Number of bytes to reseed after */
+#define REKEY_BYTES (1 >> 18)
+
static int rc4_ready = 0;
static RC4_KEY rc4;
@@ -40,27 +46,30 @@ unsigned int arc4random(void)
{
unsigned int r = 0;
- if (!rc4_ready)
+ if (rc4_ready <= 0)
arc4random_stir();
RC4(&rc4, sizeof(r), (unsigned char *)&r, (unsigned char *)&r);
+
+ rc4_ready -= sizeof(r);
return(r);
}
void arc4random_stir(void)
{
- unsigned char rand_buf[32];
+ unsigned char rand_buf[SEED_SIZE];
memset(&rc4, 0, sizeof(rc4));
seed_rng();
+
RAND_bytes(rand_buf, sizeof(rand_buf));
RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
memset(rand_buf, 0, sizeof(rand_buf));
- rc4_ready = 1;
+ rc4_ready = REKEY_BYTES;
}
#endif /* !HAVE_ARC4RANDOM */