From 89ca69193464a4d38b274170f31e1230f83f97d2 Mon Sep 17 00:00:00 2001 From: markm Date: Sun, 9 Jul 2000 11:52:12 +0000 Subject: Yarrow tweaks; separate the fast and slow reseed tasks so that they don't stomp on each other; provide constant names (as enums) for the harvester to use (makes it more self-documenting). --- sys/dev/random/yarrow.c | 23 +++++++++++++---------- sys/dev/random/yarrow.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'sys/dev/random') diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c index ab4a69c..dab10b5 100644 --- a/sys/dev/random/yarrow.c +++ b/sys/dev/random/yarrow.c @@ -47,17 +47,20 @@ static void generator_gate(void); static void reseed(int); -static void random_harvest_internal(struct timespec *nanotime, u_int64_t entropy, u_int bits, u_int frac, u_int source); +static void random_harvest_internal(struct timespec *nanotime, u_int64_t entropy, u_int bits, u_int frac, enum esource source); /* Structure holding the entropy state */ struct random_state random_state; /* When enough entropy has been harvested, asynchronously "stir" it in */ -static struct task regate_task; +static struct task regate_task[2]; -static struct context { +struct context { u_int pool; -} context = { 0 }; +} context[2] = { + { 0 }, + { 1 } + }; static void regate(void *context, int pending) @@ -80,7 +83,8 @@ random_init(void) random_state.pool[1].thresh = 160; random_state.slowoverthresh = 2; random_state.which = FAST; - TASK_INIT(®ate_task, 0, ®ate, (void *)&context); + TASK_INIT(®ate_task[FAST], FAST, ®ate, (void *)&context[FAST]); + TASK_INIT(®ate_task[SLOW], SLOW, ®ate, (void *)&context[SLOW]); random_init_harvester(random_harvest_internal); } @@ -286,7 +290,7 @@ generator_gate(void) static void random_harvest_internal(struct timespec *nanotime, u_int64_t entropy, - u_int bits, u_int frac, u_int origin) + u_int bits, u_int frac, enum esource origin) { u_int insert; int which; /* fast or slow */ @@ -324,16 +328,15 @@ random_harvest_internal(struct timespec *nanotime, u_int64_t entropy, source->bits += source->frac / 1024; source->frac %= 1024; } - context.pool = which; if (source->bits >= pool->thresh) { - /* XXX Needs to be multiply queued? */ - taskqueue_enqueue(taskqueue_swi, ®ate_task); + /* XXX Slowoverthresh nees to be considered */ + taskqueue_enqueue(taskqueue_swi, ®ate_task[which]); } /* bump the insertion point */ source->current = insert; - /* toggle the pool for next time */ + /* toggle the pool for next insertion */ random_state.which = !random_state.which; } diff --git a/sys/dev/random/yarrow.h b/sys/dev/random/yarrow.h index 2b6afcf..d2471bc 100644 --- a/sys/dev/random/yarrow.h +++ b/sys/dev/random/yarrow.h @@ -41,7 +41,7 @@ void random_init(void); void random_deinit(void); -void random_init_harvester(void (*)(struct timespec *, u_int64_t, u_int, u_int, u_int)); +void random_init_harvester(void (*)(struct timespec *, u_int64_t, u_int, u_int, enum esource)); void random_deinit_harvester(void); /* This is the beasite that needs protecting. It contains all of the -- cgit v1.1