summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt
diff options
context:
space:
mode:
authorotto <>2007-02-12 19:58:47 +0000
committerotto <>2007-02-12 19:58:47 +0000
commit69c771d75d0fc0fe568375eaf8269d6afa45d501 (patch)
tree27404c813b2caaf5bcc4a1aebd490b58851cac63 /src/lib/libc/crypt
parent724761fc242a8a20d33094c00b97166b061108bb (diff)
downloadopenbsd-69c771d75d0fc0fe568375eaf8269d6afa45d501.tar.gz
openbsd-69c771d75d0fc0fe568375eaf8269d6afa45d501.tar.bz2
openbsd-69c771d75d0fc0fe568375eaf8269d6afa45d501.zip
provide an libc internal interface to get random bytes, to be used by malloc
to get random data without calling getpid(), ok millert@ deraadt@
Diffstat (limited to 'src/lib/libc/crypt')
-rw-r--r--src/lib/libc/crypt/arc4random.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c
index 1e338f9968..35d7953002 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.15 2005/11/30 07:51:02 otto Exp $ */ 1/* $OpenBSD: arc4random.c,v 1.16 2007/02/12 19:58:47 otto Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -110,7 +110,7 @@ arc4_stir(struct arc4_stream *as)
110 */ 110 */
111 for (i = 0; i < 256; i++) 111 for (i = 0; i < 256; i++)
112 (void)arc4_getbyte(as); 112 (void)arc4_getbyte(as);
113 arc4_count = 400000; 113 arc4_count = 1600000;
114} 114}
115 115
116static inline u_int8_t 116static inline u_int8_t
@@ -127,6 +127,14 @@ arc4_getbyte(struct arc4_stream *as)
127 return (as->s[(si + sj) & 0xff]); 127 return (as->s[(si + sj) & 0xff]);
128} 128}
129 129
130u_int8_t
131__arc4_getbyte(void)
132{
133 if (--arc4_count == 0 || !rs_initialized)
134 arc4random_stir();
135 return arc4_getbyte(&rs);
136}
137
130static inline u_int32_t 138static inline u_int32_t
131arc4_getword(struct arc4_stream *as) 139arc4_getword(struct arc4_stream *as)
132{ 140{
@@ -159,7 +167,8 @@ arc4random_addrandom(u_char *dat, int datlen)
159u_int32_t 167u_int32_t
160arc4random(void) 168arc4random(void)
161{ 169{
162 if (--arc4_count == 0 || !rs_initialized || arc4_stir_pid != getpid()) 170 arc4_count -= 4;
171 if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid())
163 arc4random_stir(); 172 arc4random_stir();
164 return arc4_getword(&rs); 173 return arc4_getword(&rs);
165} 174}