summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_random.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-09-27 13:25:13 +0000
committerpeter <peter@FreeBSD.org>1996-09-27 13:25:13 +0000
commit8f5f97e2d5caa554881af27cf87dd43497899faa (patch)
tree1616561a31008878272d60e47169e5d4e4965d79 /sys/kern/kern_random.c
parent63b16ce89e765c8f50578150a2c6353ddaf3caf2 (diff)
downloadFreeBSD-src-8f5f97e2d5caa554881af27cf87dd43497899faa.zip
FreeBSD-src-8f5f97e2d5caa554881af27cf87dd43497899faa.tar.gz
I've been meaning to commit this for months. Implement select()
for /dev/random and /dev/urandom. Both are always writable, urandom is always readable, and /dev/random is readable when >= 8 bits are in the pool.
Diffstat (limited to 'sys/kern/kern_random.c')
-rw-r--r--sys/kern/kern_random.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/sys/kern/kern_random.c b/sys/kern/kern_random.c
index 7a6ea06..31b4563 100644
--- a/sys/kern/kern_random.c
+++ b/sys/kern/kern_random.c
@@ -1,7 +1,7 @@
/*
* random_machdep.c -- A strong random number generator
*
- * $Id: random_machdep.c,v 1.9 1996/06/17 16:47:43 bde Exp $
+ * $Id: random_machdep.c,v 1.10 1996/08/02 21:16:27 bde Exp $
*
* Version 0.95, last modified 18-Oct-95
*
@@ -44,6 +44,8 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#include <sys/select.h>
+#include <sys/fcntl.h>
#include <machine/clock.h>
#include <machine/random.h>
@@ -85,6 +87,7 @@ struct random_bucket {
u_int entropy_count;
int input_rotate;
u_int32_t *pool;
+ struct selinfo rsel;
};
/* There is one of these per entropy source */
@@ -118,6 +121,8 @@ rand_initialize(void)
random_state.entropy_count = 0;
random_state.pool = random_pool;
random_wait = NULL;
+ random_state.rsel.si_flags = 0;
+ random_state.rsel.si_pid = 0;
}
/*
@@ -225,6 +230,9 @@ add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
/* Prevent overflow */
if (r->entropy_count > POOLBITS)
r->entropy_count = POOLBITS;
+
+ if (r->entropy_count >= 8)
+ selwakeup(&random_state.rsel);
}
void
@@ -479,3 +487,24 @@ write_random(const char *buf, u_int nbytes)
return nbytes;
}
#endif /* notused */
+
+int
+random_select(dev_t dev, int rw, struct proc *p)
+{
+ int s, ret;
+
+ if (rw == FWRITE)
+ return 1; /* heh. */
+
+ s = splhigh();
+ if (random_state.entropy_count >= 8)
+ ret = 1;
+ else {
+ selrecord(p, &random_state.rsel);
+ ret = 0;
+ }
+ splx(s);
+
+ return ret;
+}
+
OpenPOWER on IntegriCloud