summaryrefslogtreecommitdiffstats
path: root/sys/dev/random
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2000-07-23 11:08:16 +0000
committermarkm <markm@FreeBSD.org>2000-07-23 11:08:16 +0000
commit5cdbfcb1a2cf4b4ded5bff0b970f29e18fada454 (patch)
tree21be041cff086690f613f725fd550c3d4efd3aad /sys/dev/random
parent230f54e2d8923fa7f9d8407246ac8735f0245caf (diff)
downloadFreeBSD-src-5cdbfcb1a2cf4b4ded5bff0b970f29e18fada454.zip
FreeBSD-src-5cdbfcb1a2cf4b4ded5bff0b970f29e18fada454.tar.gz
Clean this up with some BDE-inspired fixes.
o Make the comments KNF-compliant. o Use nanotime instead of getnanotime; the manpage lies about the kern.timecounter.method - it has been removed. o Fix the ENTROPYSOURCE const permanently. o Make variable names more consistent. o Make function prototypes more consistent. Some more needs to be done; to follow.
Diffstat (limited to 'sys/dev/random')
-rw-r--r--sys/dev/random/harvest.c22
-rw-r--r--sys/dev/random/yarrow.c41
-rw-r--r--sys/dev/random/yarrow.h17
3 files changed, 45 insertions, 35 deletions
diff --git a/sys/dev/random/harvest.c b/sys/dev/random/harvest.c
index 591d0d0..3e16059 100644
--- a/sys/dev/random/harvest.c
+++ b/sys/dev/random/harvest.c
@@ -39,8 +39,9 @@
#include <dev/randomdev/yarrow.h>
-/* hold the address of the routine which is actually called if */
-/* the ramdomdev is loaded */
+/* hold the address of the routine which is actually called if
+ * the ramdomdev is loaded
+ */
static void (*reap)(struct timespec *, u_int64_t, u_int, u_int, u_int) = NULL;
/* Initialise the harvester at load time */
@@ -57,17 +58,18 @@ random_deinit_harvester(void)
reap = NULL;
}
-/* Entropy harvesting routine. This is supposed to be fast; do */
-/* not do anything slow in here! */
-/* Implemented as in indirect call to allow non-inclusion of */
-/* the entropy device. */
+/* Entropy harvesting routine. This is supposed to be fast; do
+ * not do anything slow in here!
+ * Implemented as in indirect call to allow non-inclusion of
+ * the entropy device.
+ */
void
-random_harvest(u_int64_t entropy, u_int bits, u_int frac, u_int source)
+random_harvest(u_int64_t entropy, u_int bits, u_int frac, u_int origin)
{
- struct timespec nanotime;
+ struct timespec timebuf;
if (reap) {
- getnanotime(&nanotime);
- (*reap)(&nanotime, entropy, bits, frac, source);
+ nanotime(&timebuf);
+ (*reap)(&timebuf, entropy, bits, frac, origin);
}
}
diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c
index e5174d9..bc85575 100644
--- a/sys/dev/random/yarrow.c
+++ b/sys/dev/random/yarrow.c
@@ -27,7 +27,8 @@
*/
/* NOTE NOTE NOTE - This is not finished! It will supply numbers, but
- it is not yet cryptographically secure!! */
+ * it is not yet cryptographically secure!!
+ */
#include <sys/param.h>
#include <sys/systm.h>
@@ -47,13 +48,14 @@
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, enum esource source);
+static void random_harvest_internal(struct timespec *, u_int64_t, u_int, u_int, enum esource);
/* Structure holding the entropy state */
struct random_state random_state;
-/* When enough entropy has been harvested, asynchronously "stir" it in */
-/* The regate task is run at splsofttq() */
+/* When enough entropy has been harvested, asynchronously "stir" it in.
+ * The regate task is run at splsofttq()
+ */
static struct task regate_task[2];
struct context {
@@ -101,9 +103,10 @@ random_deinit(void)
static void
reseed(int fastslow)
{
- /* Interrupt-context stack is a limited resource; make static */
- /* large structures; XXX Revisit - needs to move to the large */
- /* random_state structure. */
+ /* Interrupt-context stack is a limited resource; make static
+ * large structures; XXX Revisit - needs to move to the large
+ * random_state structure.
+ */
static unsigned char v[TIMEBIN][KEYSIZE]; /* v[i] */
unsigned char hash[KEYSIZE]; /* h' */
static BF_KEY hashkey;
@@ -150,8 +153,9 @@ reseed(int fastslow)
}
}
- /* 2. Compute hash values for all v. _Supposed_ to be computationally */
- /* intensive. */
+ /* 2. Compute hash values for all v. _Supposed_ to be computationally
+ * intensive.
+ */
if (random_state.bins > TIMEBIN)
random_state.bins = TIMEBIN;
@@ -207,7 +211,7 @@ reseed(int fastslow)
bzero((void *)temp, sizeof(temp));
bzero((void *)hash, sizeof(hash));
- /* 7. Dump to seed file (XXX done by external process?) */
+ /* 7. Dump to seed file (done by external process) */
}
@@ -279,13 +283,13 @@ write_random(char *buf, u_int count)
{
u_int i;
intrmask_t mask;
- struct timespec nanotime;
+ struct timespec timebuf;
/* 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,
+ nanotime(&timebuf);
+ random_harvest_internal(&timebuf,
*(u_int64_t *)&buf[i*sizeof(u_int64_t)],
0, 0, RANDOM_WRITE);
}
@@ -320,11 +324,12 @@ generator_gate(void)
splx(mask);
}
-/* Entropy harvesting routine. This is supposed to be fast; do */
-/* not do anything slow in here! */
+/* Entropy harvesting routine. This is supposed to be fast; do
+ * not do anything slow in here!
+ */
static void
-random_harvest_internal(struct timespec *nanotime, u_int64_t entropy,
+random_harvest_internal(struct timespec *timep, u_int64_t entropy,
u_int bits, u_int frac, enum esource origin)
{
u_int insert;
@@ -355,7 +360,7 @@ random_harvest_internal(struct timespec *nanotime, u_int64_t entropy,
if (!bucket->nanotime.tv_sec && !bucket->nanotime.tv_nsec) {
/* nanotime provides clock jitter */
- bucket->nanotime = *nanotime;
+ bucket->nanotime = *timep;
/* the harvested entropy */
bucket->data = entropy;
@@ -368,7 +373,7 @@ random_harvest_internal(struct timespec *nanotime, u_int64_t entropy,
source->frac %= 1024;
}
if (source->bits >= pool->thresh) {
- /* XXX Slowoverthresh nees to be considered */
+ /* XXX Slowoverthresh needs to be considered */
taskqueue_enqueue(taskqueue_swi, &regate_task[which]);
}
diff --git a/sys/dev/random/yarrow.h b/sys/dev/random/yarrow.h
index d2471bc..e64a1bc 100644
--- a/sys/dev/random/yarrow.h
+++ b/sys/dev/random/yarrow.h
@@ -26,13 +26,14 @@
* $FreeBSD$
*/
-#define ENTROPYBIN 256 /* buckets to harvest entropy events */
-#define ENTROPYSOURCE 2 /* entropy sources (actually classes) */
- /* The entropy classes will as follows: */
- /* 0 - Keyboard */
- /* 1 - Mouse */
- /* to start with. More will be added */
+/* #define ENTROPYSOURCE nn entropy sources (actually classes)
+ * The entropy classes will as follows:
+ * 0 - Direct write
+ * 1 - Keyboard
+ * 2 - Mouse
+ */
+#define ENTROPYBIN 256 /* buckets to harvest entropy events */
#define TIMEBIN 16 /* max value for Pt/t */
#define KEYSIZE 32 /* 32 bytes == 256 bits */
@@ -44,7 +45,9 @@ void random_deinit(void);
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
+void write_random(char *, u_int);
+
+/* This is the beastie that needs protecting. It contains all of the
* state that we are excited about.
* This is a biiig structure. It may move over to a malloc(9)ed
* replacement.
OpenPOWER on IntegriCloud