diff options
author | 2003-08-16 19:07:40 +0000 | |
---|---|---|
committer | 2003-08-16 19:07:40 +0000 | |
commit | b3cc64f98715ad37ab87f03188e58dc61ea2bad3 (patch) | |
tree | a2acd3b511b7c5ae009d55542044c1dd80976a33 /lib/libc/crypt/arc4random.c | |
parent | spaces (diff) | |
download | wireguard-openbsd-b3cc64f98715ad37ab87f03188e58dc61ea2bad3.tar.xz wireguard-openbsd-b3cc64f98715ad37ab87f03188e58dc61ea2bad3.zip |
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.c | 33 |
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)); |