summaryrefslogtreecommitdiff
path: root/sys/dev/rnd.c
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2001-12-29 17:22:42 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2001-12-29 17:22:42 +0000
commit86914059dba36abcfb51bd8e78e31950e89e933f (patch)
treeb282e38a5941900d6ad624b89929832b8d09a3ad /sys/dev/rnd.c
parent254b1426b28eed3fd0ff6778f5f739c68a3818d6 (diff)
finer spl granularity, allowing ints to happen; pointed out and tested on vax by hugh@
Diffstat (limited to 'sys/dev/rnd.c')
-rw-r--r--sys/dev/rnd.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index e4a3ed2e553..3bfc565c872 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rnd.c,v 1.50 2001/09/24 02:23:44 mickey Exp $ */
+/* $OpenBSD: rnd.c,v 1.51 2001/12/29 17:22:41 mickey Exp $ */
/*
* random.c -- A strong random number generator
@@ -850,23 +850,25 @@ extract_entropy(buf, nbytes)
int nbytes;
{
struct random_bucket *rs = &random_state;
- MD5_CTX tmp;
u_char buffer[16];
add_timer_randomness(nbytes);
- if (rs->entropy_count / 8 > nbytes)
- rs->entropy_count -= nbytes*8;
- else
- rs->entropy_count = 0;
-
while (nbytes) {
- int i;
+ MD5_CTX tmp;
+ int i, s;
/* Hash the pool to get the output */
MD5Init(&tmp);
+ s = splhigh();
MD5Update(&tmp, (u_int8_t*)rs->pool, sizeof(rs->pool));
+ if (rs->entropy_count / 8 > i)
+ rs->entropy_count -= i * 8;
+ else
+ rs->entropy_count = 0;
MD5Final(buffer, &tmp);
+ bzero(&tmp, sizeof(tmp));
+ splx(s);
/*
* In case the hash function has some recognizable
@@ -881,9 +883,6 @@ extract_entropy(buf, nbytes)
buffer[6] ^= buffer[ 9];
buffer[7] ^= buffer[ 8];
- /* Modify pool so next hash will produce different results */
- add_entropy_words((u_int32_t*)buffer, sizeof(buffer)/8);
-
/* Copy data to destination buffer */
if (nbytes < sizeof(buffer) / 2)
bcopy(buffer, buf, i = nbytes);
@@ -891,11 +890,12 @@ extract_entropy(buf, nbytes)
bcopy(buffer, buf, i = sizeof(buffer) / 2);
nbytes -= i;
buf += i;
+
+ /* Modify pool so next hash will produce different results */
add_timer_randomness(nbytes);
}
/* Wipe data from memory */
- bzero(&tmp, sizeof(tmp));
bzero(&buffer, sizeof(buffer));
}
@@ -920,7 +920,7 @@ randomread(dev, uio, ioflag)
int ioflag;
{
int ret = 0;
- int s, i;
+ int i;
if (uio->uio_resid == 0)
return 0;
@@ -929,7 +929,6 @@ randomread(dev, uio, ioflag)
u_int32_t buf[ POOLWORDS ];
int n = min(sizeof(buf), uio->uio_resid);
- s = splhigh();
switch(minor(dev)) {
case RND_RND:
ret = EIO; /* no chip -- error */
@@ -986,7 +985,6 @@ randomread(dev, uio, ioflag)
default:
ret = ENXIO;
}
- splx(s);
if (n != 0 && ret == 0)
ret = uiomove((caddr_t)buf, n, uio);
}