summaryrefslogtreecommitdiffstats
path: root/sys/dev/random/yarrow.c
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2000-11-25 17:09:01 +0000
committermarkm <markm@FreeBSD.org>2000-11-25 17:09:01 +0000
commit9ec7bc0451ec7ffe96d31c1c0e6d1c7b4ddc709c (patch)
treec4e38c6e58dc3b98f0eba6228af546879a85b7ed /sys/dev/random/yarrow.c
parent64d964e98ea77870092686823e5dde13a5a24ccb (diff)
downloadFreeBSD-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/yarrow.c')
-rw-r--r--sys/dev/random/yarrow.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c
index 31201d2..8480897 100644
--- a/sys/dev/random/yarrow.c
+++ b/sys/dev/random/yarrow.c
@@ -40,9 +40,11 @@
#include <sys/mutex.h>
#include <sys/select.h>
#include <sys/random.h>
-#include <sys/time.h>
#include <sys/types.h>
#include <sys/unistd.h>
+
+#include <machine/cpu.h>
+
#include <crypto/blowfish/blowfish.h>
#include <dev/random/hash.h>
@@ -53,7 +55,7 @@
static void generator_gate(void);
static void reseed(int);
-static void random_harvest_internal(struct timespec *, void *, u_int, u_int, u_int, enum esource);
+static void random_harvest_internal(u_int64_t, void *, u_int, u_int, u_int, enum esource);
static void random_kthread(void *);
@@ -68,7 +70,7 @@ TAILQ_HEAD(harvestqueue, harvest) harvestqueue,
* buffer size is pretty arbitrary.
*/
struct harvest {
- struct timespec time; /* nanotime for clock jitter */
+ u_int64_t somecounter; /* fast counter for clock jitter */
u_char entropy[HARVESTSIZE]; /* the harvested entropy */
u_int size, bits, frac; /* stats about the entropy */
enum esource source; /* stats about the entropy */
@@ -139,7 +141,7 @@ random_kthread(void *arg /* NOTUSED */)
yarrow_hash_iterate(&random_state.pool[event->pool].hash,
event->entropy, sizeof(event->entropy));
yarrow_hash_iterate(&random_state.pool[event->pool].hash,
- &event->time, sizeof(event->time));
+ &event->somecounter, sizeof(event->somecounter));
source->frac += event->frac;
source->bits += event->bits + source->frac/1024;
source->frac %= 1024;
@@ -431,25 +433,27 @@ void
write_random(void *buf, u_int count)
{
u_int i;
- struct timespec timebuf;
- /* arbitrarily break the input up into HARVESTSIZE chunks */
+ /* Break the input up into HARVESTSIZE chunks.
+ * The writer has too much control here, so "estimate" the
+ * the entropy as zero.
+ */
for (i = 0; i < count; i += HARVESTSIZE) {
- nanotime(&timebuf);
- random_harvest_internal(&timebuf, (char *)buf + i, HARVESTSIZE, 0, 0,
- RANDOM_WRITE);
+ random_harvest_internal(get_cyclecount(), (char *)buf + i,
+ HARVESTSIZE, 0, 0, RANDOM_WRITE);
}
/* Maybe the loop iterated at least once */
if (i > count)
i -= HARVESTSIZE;
- /* Get the last bytes even if the input length is not a multiple of HARVESTSIZE */
+ /* Get the last bytes even if the input length is not
+ * a multiple of HARVESTSIZE.
+ */
count %= HARVESTSIZE;
if (count) {
- nanotime(&timebuf);
- random_harvest_internal(&timebuf, (char *)buf + i, count, 0, 0,
- RANDOM_WRITE);
+ random_harvest_internal(get_cyclecount(), (char *)buf + i, count,
+ 0, 0, RANDOM_WRITE);
}
/* Explicit reseed */
@@ -485,22 +489,20 @@ generator_gate(void)
*/
static void
-random_harvest_internal(struct timespec *timep, void *entropy, u_int count,
+random_harvest_internal(u_int64_t somecounter, void *entropy, u_int count,
u_int bits, u_int frac, enum esource origin)
{
struct harvest *event;
-#if 0
-#ifdef DEBUG
+#ifdef DEBUG1
printf("Random harvest\n");
#endif
-#endif
event = malloc(sizeof(struct harvest), M_TEMP, M_NOWAIT);
if (origin < ENTROPYSOURCE && event != NULL) {
- /* nanotime provides clock jitter */
- event->time = *timep;
+ /* fast counter provides clock jitter */
+ event->somecounter = somecounter;
/* the harvested entropy */
count = count > sizeof(event->entropy)
OpenPOWER on IntegriCloud