summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2007-02-12 19:58:48 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2007-02-12 19:58:48 +0000
commit719ff72de946f76b51c5927ac6243593071819c9 (patch)
tree5d30b2a088333198b60cfe8c46e905fd11eb49f5
parentb101aacfe0089acbe8f6506bde82010caaab15d3 (diff)
provide an libc internal interface to get random bytes, to be used by malloc
to get random data without calling getpid(), ok millert@ deraadt@
-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);
}