From 720a3741cf8c06f597bac5a1a216b6018278dc89 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Mon, 17 Jul 2000 12:23:04 +0000 Subject: Add randomness write functionality. This does absolutely nothing for entropy estimation, but causes an immediate reseed after the input (read in sizeof(u_int64_t) chunks) is "harvested". This will be used in the reboot "reseeder", coming in another commit. This can be used very effectively at any time you think your randomness is compromised; something like # (ps -gauxwww; netstat -an; dmesg; vmstat -c10 1) > /dev/random will give the attacker something to think about. --- sys/dev/random/randomdev.c | 2 +- sys/dev/random/yarrow.c | 19 +++++++++++++++++++ sys/dev/randomdev/randomdev.c | 2 +- sys/dev/randomdev/yarrow.c | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index ff5e481d6689c..c84f4bd670305 100644 --- a/sys/dev/random/randomdev.c +++ b/sys/dev/random/randomdev.c @@ -117,7 +117,7 @@ random_write(dev_t dev, struct uio *uio, int flag) error = uiomove(random_buf, c, uio); if (error) break; - /* write_random(random_buf, c); */ + write_random(random_buf, c); } free(random_buf, M_TEMP); return error; diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c index c6ae4481a0ebd..e5174d9cc9b5d 100644 --- a/sys/dev/random/yarrow.c +++ b/sys/dev/random/yarrow.c @@ -274,6 +274,25 @@ read_random(char *buf, u_int count) return retval; } +void +write_random(char *buf, u_int count) +{ + u_int i; + intrmask_t mask; + struct timespec nanotime; + + /* The reseed task must not be jumped on */ + mask = splsofttq(); + for (i = 0; i < count/sizeof(u_int64_t); i++) { + getnanotime(&nanotime); + random_harvest_internal(&nanotime, + *(u_int64_t *)&buf[i*sizeof(u_int64_t)], + 0, 0, RANDOM_WRITE); + } + reseed(FAST); + splx(mask); +} + static void generator_gate(void) { diff --git a/sys/dev/randomdev/randomdev.c b/sys/dev/randomdev/randomdev.c index ff5e481d6689c..c84f4bd670305 100644 --- a/sys/dev/randomdev/randomdev.c +++ b/sys/dev/randomdev/randomdev.c @@ -117,7 +117,7 @@ random_write(dev_t dev, struct uio *uio, int flag) error = uiomove(random_buf, c, uio); if (error) break; - /* write_random(random_buf, c); */ + write_random(random_buf, c); } free(random_buf, M_TEMP); return error; diff --git a/sys/dev/randomdev/yarrow.c b/sys/dev/randomdev/yarrow.c index c6ae4481a0ebd..e5174d9cc9b5d 100644 --- a/sys/dev/randomdev/yarrow.c +++ b/sys/dev/randomdev/yarrow.c @@ -274,6 +274,25 @@ read_random(char *buf, u_int count) return retval; } +void +write_random(char *buf, u_int count) +{ + u_int i; + intrmask_t mask; + struct timespec nanotime; + + /* The reseed task must not be jumped on */ + mask = splsofttq(); + for (i = 0; i < count/sizeof(u_int64_t); i++) { + getnanotime(&nanotime); + random_harvest_internal(&nanotime, + *(u_int64_t *)&buf[i*sizeof(u_int64_t)], + 0, 0, RANDOM_WRITE); + } + reseed(FAST); + splx(mask); +} + static void generator_gate(void) { -- cgit v1.3