summaryrefslogtreecommitdiff
path: root/lib/libc/crypt/arc4random.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2003-08-16 19:07:41 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2003-08-16 19:07:41 +0000
commit15fb4a2f571e172e4fe20be759ea09a7188c3536 (patch)
tree7d8fcbd6580f82dc59c75d40995cd7969acbe599 /lib/libc/crypt/arc4random.c
parent09b8ab5dde5b736cce2297e95c71ed6f8eafc3da (diff)
just use sysctl for stirring. thread safe and can't fail.
ok deraadt and co.
Diffstat (limited to 'lib/libc/crypt/arc4random.c')
-rw-r--r--lib/libc/crypt/arc4random.c33
1 files changed, 10 insertions, 23 deletions
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c
index b23b1955e42..5e3b2925a68 100644
--- a/lib/libc/crypt/arc4random.c
+++ b/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random.c,v 1.8 2003/06/11 21:03:10 deraadt Exp $ */
+/* $OpenBSD: arc4random.c,v 1.9 2003/08/16 19:07:40 tedu Exp $ */
/*
* Arc4 random number generator for OpenBSD.
@@ -79,35 +79,22 @@ arc4_addrandom(struct arc4_stream *as, u_char *dat, int datlen)
static void
arc4_stir(struct arc4_stream *as)
{
- int fd;
+ int i, mib[2];
+ size_t len;
struct {
struct timeval tv;
u_int rnd[(128 - sizeof(struct timeval)) / sizeof(u_int)];
} rdat;
gettimeofday(&rdat.tv, NULL);
- fd = open("/dev/arandom", O_RDONLY);
- if (fd != -1) {
- read(fd, rdat.rnd, sizeof(rdat.rnd));
- close(fd);
- } else {
- int i, mib[2];
- size_t len;
-
- /* Device could not be opened, we might be chrooted, take
- * randomness from sysctl. */
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_ARND;
-
- for (i = 0; i < sizeof(rdat.rnd) / sizeof(u_int); i ++) {
- len = sizeof(u_int);
- if (sysctl(mib, 2, &rdat.rnd[i], &len, NULL, 0) == -1)
- break;
- }
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_ARND;
+
+ for (i = 0; i < sizeof(rdat.rnd) / sizeof(u_int); i ++) {
+ len = sizeof(u_int);
+ if (sysctl(mib, 2, &rdat.rnd[i], &len, NULL, 0) == -1)
+ break;
}
- /* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take
- * whatever was on the stack... */
arc4_stir_pid = getpid();
arc4_addrandom(as, (void *) &rdat, sizeof(rdat));