summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/arc4random.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2008-07-21 13:52:06 +0000
committerache <ache@FreeBSD.org>2008-07-21 13:52:06 +0000
commit5ed3228d52c437ca20964c105780d69d2e6892b1 (patch)
tree76fdcd5d3b5825fc0d89a698efff7a825c0ba340 /lib/libc/gen/arc4random.c
parent101cbb7cb3db72e499cc35d9319dac30b653d25b (diff)
downloadFreeBSD-src-5ed3228d52c437ca20964c105780d69d2e6892b1.zip
FreeBSD-src-5ed3228d52c437ca20964c105780d69d2e6892b1.tar.gz
Implement arc4random_buf() function
Obtained from: OpenBSD
Diffstat (limited to 'lib/libc/gen/arc4random.c')
-rw-r--r--lib/libc/gen/arc4random.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c
index 6aa2323..7c11da2 100644
--- a/lib/libc/gen/arc4random.c
+++ b/lib/libc/gen/arc4random.c
@@ -164,7 +164,7 @@ arc4_check_init(void)
}
}
-static void
+static inline void
arc4_check_stir(void)
{
if (!rs_stired || arc4_count <= 0) {
@@ -208,6 +208,21 @@ arc4random(void)
return (rnd);
}
+void
+arc4random_buf(void *_buf, size_t n)
+{
+ u_char *buf = (u_char *)_buf;
+
+ THREAD_LOCK();
+ arc4_check_init();
+ while (n--) {
+ arc4_check_stir();
+ buf[n] = arc4_getbyte(&rs);
+ arc4_count--;
+ }
+ THREAD_UNLOCK();
+}
+
#if 0
/*-------- Test code for i386 --------*/
#include <stdio.h>
OpenPOWER on IntegriCloud