diff options
| author | 2010-12-22 18:16:24 +0000 | |
|---|---|---|
| committer | 2010-12-22 18:16:24 +0000 | |
| commit | 29b12fe827adaa7b581c4057f717b54840b5ab7b (patch) | |
| tree | 367f1ee2f4e5e945b35ba5626e46071c7c7f068a /sys/dev/rnd.c | |
| parent | Consistantly use /dev/arandom for feeding entropy to the kernel. (diff) | |
| download | wireguard-openbsd-29b12fe827adaa7b581c4057f717b54840b5ab7b.tar.xz wireguard-openbsd-29b12fe827adaa7b581c4057f717b54840b5ab7b.zip | |
rewrite randomwrite() for clarity after discussion with mikeb
ok djm
Diffstat (limited to 'sys/dev/rnd.c')
| -rw-r--r-- | sys/dev/rnd.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c index f33a99b7967..4b1e36d864f 100644 --- a/sys/dev/rnd.c +++ b/sys/dev/rnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rnd.c,v 1.104 2010/11/21 22:58:40 tedu Exp $ */ +/* $OpenBSD: rnd.c,v 1.105 2010/12/22 18:16:24 deraadt Exp $ */ /* * rnd.c -- A strong random number generator @@ -1105,7 +1105,7 @@ filt_rndwrite(struct knote *kn, long hint) int randomwrite(dev_t dev, struct uio *uio, int flags) { - int ret = 0; + int ret = 0, newdata = 0; u_int32_t *buf; if (minor(dev) == RND_RND) @@ -1117,18 +1117,22 @@ randomwrite(dev_t dev, struct uio *uio, int flags) buf = malloc(POOLBYTES, M_TEMP, M_WAITOK); while (!ret && uio->uio_resid > 0) { - u_short n = min(POOLBYTES, uio->uio_resid); + u_int n = min(POOLBYTES, uio->uio_resid); - ret = uiomove((caddr_t)buf, n, uio); - if (!ret) { - while (n % sizeof(u_int32_t)) - ((u_int8_t *) buf)[n++] = 0; - add_entropy_words(buf, n / 4); - } + ret = uiomove(buf, n, uio); + if (ret) + break; + while (n % sizeof(u_int32_t)) + ((u_int8_t *) buf)[n++] = 0; + add_entropy_words(buf, n / 4); + newdata = 1; } - if (!ret) + if (newdata) { + mtx_enter(&rndlock); arc4random_initialized = 0; + mtx_leave(&rndlock); + } free(buf, M_TEMP); return ret; |
