summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt
diff options
context:
space:
mode:
authorderaadt <>2003-02-14 17:12:54 +0000
committerderaadt <>2003-02-14 17:12:54 +0000
commitf14577dc0d7d942846ae2f7bd106dd1d82008bac (patch)
tree9bae9118d8257993aa34d83090e907aa822babf0 /src/lib/libc/crypt
parentdf50f5d5668c1dd3920be8a8c09c8bbd00f223cd (diff)
downloadopenbsd-f14577dc0d7d942846ae2f7bd106dd1d82008bac.tar.gz
openbsd-f14577dc0d7d942846ae2f7bd106dd1d82008bac.tar.bz2
openbsd-f14577dc0d7d942846ae2f7bd106dd1d82008bac.zip
re-stir if pid changes; markus & me
Diffstat (limited to 'src/lib/libc/crypt')
-rw-r--r--src/lib/libc/crypt/arc4random.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c
index 4e916ab99a..a41001bcc3 100644
--- a/src/lib/libc/crypt/arc4random.c
+++ b/src/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */ 1/* $OpenBSD: arc4random.c,v 1.7 2003/02/14 17:12:54 deraadt Exp $ */
2 2
3/* 3/*
4 * Arc4 random number generator for OpenBSD. 4 * Arc4 random number generator for OpenBSD.
@@ -44,8 +44,9 @@ struct arc4_stream {
44 u_int8_t s[256]; 44 u_int8_t s[256];
45}; 45};
46 46
47int rs_initialized; 47static int rs_initialized;
48static struct arc4_stream rs; 48static struct arc4_stream rs;
49static pid_t arc4_stir_pid;
49 50
50static inline void 51static inline void
51arc4_init(as) 52arc4_init(as)
@@ -113,6 +114,7 @@ arc4_stir(as)
113 /* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take 114 /* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take
114 * whatever was on the stack... */ 115 * whatever was on the stack... */
115 116
117 arc4_stir_pid = getpid();
116 arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); 118 arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
117} 119}
118 120
@@ -166,7 +168,7 @@ arc4random_addrandom(dat, datlen)
166u_int32_t 168u_int32_t
167arc4random() 169arc4random()
168{ 170{
169 if (!rs_initialized) 171 if (!rs_initialized || arc4_stir_pid != getpid())
170 arc4random_stir(); 172 arc4random_stir();
171 return arc4_getword(&rs); 173 return arc4_getword(&rs);
172} 174}