diff options
author | markm <markm@FreeBSD.org> | 2000-11-25 17:09:01 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2000-11-25 17:09:01 +0000 |
commit | 9ec7bc0451ec7ffe96d31c1c0e6d1c7b4ddc709c (patch) | |
tree | c4e38c6e58dc3b98f0eba6228af546879a85b7ed /sys/dev/random/harvest.c | |
parent | 64d964e98ea77870092686823e5dde13a5a24ccb (diff) | |
download | FreeBSD-src-9ec7bc0451ec7ffe96d31c1c0e6d1c7b4ddc709c.zip FreeBSD-src-9ec7bc0451ec7ffe96d31c1c0e6d1c7b4ddc709c.tar.gz |
Stop explicitly using nanotime(9) and use the new get_cyclecounter(9)
call instead.
This makes a pretty dramatic difference to the amount of work that
the harvester needs to do - it is much friendlier on the system.
(80386 and 80486 class machines will notice little, as the new
get_cyclecounter() call is a wrapper round nanotime(9) for them).
Diffstat (limited to 'sys/dev/random/harvest.c')
-rw-r--r-- | sys/dev/random/harvest.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/sys/dev/random/harvest.c b/sys/dev/random/harvest.c index 76c23a9..89a6368 100644 --- a/sys/dev/random/harvest.c +++ b/sys/dev/random/harvest.c @@ -35,7 +35,9 @@ #include <sys/poll.h> #include <sys/select.h> #include <sys/random.h> -#include <sys/time.h> + +#include <machine/cpu.h> + #include <crypto/blowfish/blowfish.h> #include <dev/random/hash.h> @@ -44,14 +46,14 @@ static u_int read_random_phony(void *, u_int); /* hold the address of the routine which is actually called if - * the ramdomdev is loaded + * the randomdev is loaded */ -static void (*reap_func)(struct timespec *, void *, u_int, u_int, u_int, u_int) = NULL; +static void (*reap_func)(u_int64_t, void *, u_int, u_int, u_int, u_int) = NULL; static u_int (*read_func)(void *, u_int) = read_random_phony; /* Initialise the harvester at load time */ void -random_init_harvester(void (*reaper)(struct timespec *, void *, u_int, u_int, u_int, u_int), u_int (*reader)(void *, u_int)) +random_init_harvester(void (*reaper)(u_int64_t, void *, u_int, u_int, u_int, u_int), u_int (*reader)(void *, u_int)) { reap_func = reaper; read_func = reader; @@ -73,12 +75,8 @@ random_deinit_harvester(void) void random_harvest(void *entropy, u_int count, u_int bits, u_int frac, u_int origin) { - struct timespec timebuf; - - if (reap_func) { - nanotime(&timebuf); - (*reap_func)(&timebuf, entropy, count, bits, frac, origin); - } + if (reap_func) + (*reap_func)(get_cyclecount(), entropy, count, bits, frac, origin); } /* Userland-visible version of read_random */ @@ -95,18 +93,15 @@ read_random(void *buf, u_int count) static u_int read_random_phony(void *buf, u_int count) { - struct timespec timebuf; u_long randval; int size, i; static int initialised = 0; /* Try to give random(9) a half decent initialisation - * DO not make the mistake of thinking this is secure!! + * DO NOT make the mistake of thinking this is secure!! */ - if (!initialised) { - nanotime(&timebuf); - srandom((u_long)(timebuf.tv_sec ^ timebuf.tv_nsec)); - } + if (!initialised) + srandom((u_long)get_cyclecount()); /* Fill buf[] with random(9) output */ for (i = 0; i < count; i+= sizeof(u_long)) { |