From 6ac673bf3ce6085f5f69239cbe8b7c589420612f Mon Sep 17 00:00:00 2001 From: markm Date: Sat, 25 Nov 2000 19:13:29 +0000 Subject: Greatly improve the boot-up unblocking time of the entropy device. --- sys/dev/random/randomdev.c | 11 ++++++++++- sys/dev/random/yarrow.c | 10 +++++++--- sys/dev/random/yarrow.h | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'sys/dev/random') diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index 13230db..37aeb3d 100644 --- a/sys/dev/random/randomdev.c +++ b/sys/dev/random/randomdev.c @@ -51,6 +51,7 @@ #include "opt_noblockrandom.h" static d_open_t random_open; +static d_close_t random_close; static d_read_t random_read; static d_write_t random_write; static d_ioctl_t random_ioctl; @@ -62,7 +63,7 @@ static d_poll_t random_poll; static struct cdevsw random_cdevsw = { /* open */ random_open, - /* close */ (d_close_t *)nullop, + /* close */ random_close, /* read */ random_read, /* write */ random_write, /* ioctl */ random_ioctl, @@ -104,6 +105,14 @@ random_open(dev_t dev, int flags, int fmt, struct proc *p) } static int +random_close(dev_t dev, int flags, int fmt, struct proc *p) +{ + if ((flags & FWRITE) && (securelevel > 0 || suser(p))) + random_reseed(); + return 0; +} + +static int random_read(dev_t dev, struct uio *uio, int flag) { u_int c, ret; diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c index 8480897..c53e7c1 100644 --- a/sys/dev/random/yarrow.c +++ b/sys/dev/random/yarrow.c @@ -455,9 +455,6 @@ write_random(void *buf, u_int count) random_harvest_internal(get_cyclecount(), (char *)buf + i, count, 0, 0, RANDOM_WRITE); } - - /* Explicit reseed */ - reseed(FAST); } static void @@ -527,3 +524,10 @@ random_harvest_internal(u_int64_t somecounter, void *entropy, u_int count, mtx_exit(&random_harvest_mtx, MTX_DEF); } } + +/* Helper routine to perform explicit reseeds */ +void +random_reseed(void) +{ + reseed(FAST); +} diff --git a/sys/dev/random/yarrow.h b/sys/dev/random/yarrow.h index 9904d24..49cc602 100644 --- a/sys/dev/random/yarrow.h +++ b/sys/dev/random/yarrow.h @@ -45,6 +45,8 @@ void random_init_harvester(void (*)(u_int64_t, void *, u_int, u_int, u_int, enum void random_deinit_harvester(void); void random_set_wakeup_exit(void *); +void random_reseed(void); + u_int read_random_real(void *, u_int); void write_random(void *, u_int); -- cgit v1.1