diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/random/yarrow.c | 23 | ||||
-rw-r--r-- | sys/dev/random/yarrow.h | 2 | ||||
-rw-r--r-- | sys/dev/randomdev/yarrow.c | 23 | ||||
-rw-r--r-- | sys/dev/randomdev/yarrow.h | 2 | ||||
-rw-r--r-- | sys/sys/random.h | 1 |
5 files changed, 29 insertions, 22 deletions
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 diff --git a/sys/dev/randomdev/yarrow.c b/sys/dev/randomdev/yarrow.c index ab4a69c..dab10b5 100644 --- a/sys/dev/randomdev/yarrow.c +++ b/sys/dev/randomdev/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/randomdev/yarrow.h b/sys/dev/randomdev/yarrow.h index 2b6afcf..d2471bc 100644 --- a/sys/dev/randomdev/yarrow.h +++ b/sys/dev/randomdev/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 diff --git a/sys/sys/random.h b/sys/sys/random.h index 40894d9..1b99532 100644 --- a/sys/sys/random.h +++ b/sys/sys/random.h @@ -34,6 +34,7 @@ u_int read_random(char *, u_int); void write_random(char *, u_int); +enum esource { RANDOM_KEYBOARD, RANDOM_MOUSE }; void random_harvest(u_int64_t, u_int, u_int, u_int); #endif |