mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-18 10:35:55 +00:00
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).
This commit is contained in:
parent
769afb047c
commit
585ebe2b41
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=62841
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user