summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2007-02-12 19:58:47 +0000
committerotto <otto@openbsd.org>2007-02-12 19:58:47 +0000
commit5a41b3bec75cb1be164a0319a3e3aa983836981d (patch)
treec7b7caea83ac631b07262439f17041d4f394c414 /lib/libc
parentFix the hw.vendor/product sysctls on sparc64, handle the cases where (diff)
downloadwireguard-openbsd-5a41b3bec75cb1be164a0319a3e3aa983836981d.tar.xz
wireguard-openbsd-5a41b3bec75cb1be164a0319a3e3aa983836981d.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 'lib/libc')
-rw-r--r--lib/libc/crypt/arc4random.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c
index 1e338f9968c..35d79530022 100644
--- a/lib/libc/crypt/arc4random.c
+++ b/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random.c,v 1.15 2005/11/30 07:51:02 otto Exp $ */
+/* $OpenBSD: arc4random.c,v 1.16 2007/02/12 19:58:47 otto Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -110,7 +110,7 @@ arc4_stir(struct arc4_stream *as)
*/
for (i = 0; i < 256; i++)
(void)arc4_getbyte(as);
- arc4_count = 400000;
+ arc4_count = 1600000;
}
static inline u_int8_t
@@ -127,6 +127,14 @@ arc4_getbyte(struct arc4_stream *as)
return (as->s[(si + sj) & 0xff]);
}
+u_int8_t
+__arc4_getbyte(void)
+{
+ if (--arc4_count == 0 || !rs_initialized)
+ arc4random_stir();
+ return arc4_getbyte(&rs);
+}
+
static inline u_int32_t
arc4_getword(struct arc4_stream *as)
{
@@ -159,7 +167,8 @@ arc4random_addrandom(u_char *dat, int datlen)
u_int32_t
arc4random(void)
{
- if (--arc4_count == 0 || !rs_initialized || arc4_stir_pid != getpid())
+ arc4_count -= 4;
+ if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid())
arc4random_stir();
return arc4_getword(&rs);
}