summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-06-24 20:52:06 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-06-24 20:52:06 +0000
commitfb00ed2229dcf70c469b64851e2b11307bee9430 (patch)
tree6228accd2b4a801a8028f2223c9a15ebf51ee78d
parent2fb3aad89ae820366dcc49e91f6d04c73563c824 (diff)
only run timeout if stirring happened, save cycles for mass energy conservation
-rw-r--r--sys/dev/rnd.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index 540cb307be2..df21ca1f2b3 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rnd.c,v 1.47 2001/05/08 17:30:56 mickey Exp $ */
+/* $OpenBSD: rnd.c,v 1.48 2001/06/24 20:52:05 mickey Exp $ */
/*
* random.c -- A strong random number generator
@@ -459,8 +459,9 @@ static __inline void add_entropy_words __P((const u_int32_t *, u_int n));
static __inline void extract_entropy __P((register u_int8_t *, int));
static __inline u_int8_t arc4_getbyte __P((void));
-void arc4_stir __P((void));
+static __inline void arc4_stir __P((void));
void arc4_reinit __P((void *v));
+void arc4maybeinit __P((void));
/* Arcfour random stream generator. This code is derived from section
* 17.1 of Applied Cryptography, second edition, which describes a
@@ -480,7 +481,7 @@ void arc4_reinit __P((void *v));
* RC4 is a registered trademark of RSA Laboratories.
*/
-void
+static __inline void
arc4_stir(void)
{
u_int8_t buf[256];
@@ -528,24 +529,28 @@ arc4_getbyte(void)
return arc4random_state.s[(si + sj) & 0xff];
}
-static __inline void
+void
arc4maybeinit(void)
{
+ extern int hz;
+
if (!arc4random_initialized) {
arc4random_initialized++;
arc4_stir();
+ /* 10 minutes, per dm@'s suggestion */
+ timeout_add(&arc4_timeout, 10 * 60 * hz);
}
}
+/*
+ * called by timeout to mark arc4 for stirring,
+ * actuall stirring happens on any access attempt.
+ */
void
arc4_reinit(v)
void *v;
{
- extern int hz;
-
arc4random_initialized = 0;
- /* 10 minutes, per dm@'s suggestion */
- timeout_add(&arc4_timeout, 10 * 60 * hz);
}
int
@@ -747,7 +752,7 @@ enqueue_randomness(state, val)
/*
* the logic is to drop low-entropy entries,
- * in hope for dequeuing to be more sourcefull
+ * in hope for dequeuing to be more randomfull
*/
if (rnd_qlen() > QEVSLOW && nbits < QEVSBITS) {
rndstats.rnd_drople++;