summaryrefslogtreecommitdiff
path: root/lib/libc/crypt/arc4random.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-02-14 17:12:55 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-02-14 17:12:55 +0000
commita86f6a73646ec070054ca2c946f5a3003613d6ed (patch)
tree886c79cf97c0f51f1d81fe5ec3b21c01ce12d472 /lib/libc/crypt/arc4random.c
parent1366f91c08553f00d4ca497d6240b42f1916917e (diff)
re-stir if pid changes; markus & me
Diffstat (limited to 'lib/libc/crypt/arc4random.c')
-rw-r--r--lib/libc/crypt/arc4random.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c
index 4e916ab99a1..a41001bcc3d 100644
--- a/lib/libc/crypt/arc4random.c
+++ b/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
+/* $OpenBSD: arc4random.c,v 1.7 2003/02/14 17:12:54 deraadt Exp $ */
/*
* Arc4 random number generator for OpenBSD.
@@ -44,8 +44,9 @@ struct arc4_stream {
u_int8_t s[256];
};
-int rs_initialized;
+static int rs_initialized;
static struct arc4_stream rs;
+static pid_t arc4_stir_pid;
static inline void
arc4_init(as)
@@ -113,6 +114,7 @@ arc4_stir(as)
/* 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));
}
@@ -166,7 +168,7 @@ arc4random_addrandom(dat, datlen)
u_int32_t
arc4random()
{
- if (!rs_initialized)
+ if (!rs_initialized || arc4_stir_pid != getpid())
arc4random_stir();
return arc4_getword(&rs);
}