summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/arc4random.3
diff options
context:
space:
mode:
authorotto <>2008-03-16 19:47:43 +0000
committerotto <>2008-03-16 19:47:43 +0000
commite045e819cf6c3f1795515c3f3f6d661b69e1f66b (patch)
treef4249dd0935bf7960031a9fa944836948c49cad1 /src/lib/libc/crypt/arc4random.3
parenta8537602a33c58670952fc29ef3a95e13d478746 (diff)
downloadopenbsd-e045e819cf6c3f1795515c3f3f6d661b69e1f66b.tar.gz
openbsd-e045e819cf6c3f1795515c3f3f6d661b69e1f66b.tar.bz2
openbsd-e045e819cf6c3f1795515c3f3f6d661b69e1f66b.zip
diff from djm@ committed at his request:
introduce two new APIs for requesting strong random numbers: arc4random_buf() - fill an arbitrary memory range with random numbers arc4random_uniform() - return a uniformly distributed random number below a specified upper bound, avoiding the bias that comes from a naive "arc4random() % upper_bound" construction. these mirror similarly-named functions in the kernel; lots of discussion deraadt@ mcbride@
Diffstat (limited to 'src/lib/libc/crypt/arc4random.3')
-rw-r--r--src/lib/libc/crypt/arc4random.323
1 files changed, 21 insertions, 2 deletions
diff --git a/src/lib/libc/crypt/arc4random.3 b/src/lib/libc/crypt/arc4random.3
index 31da5ec7ec..d32ea4a951 100644
--- a/src/lib/libc/crypt/arc4random.3
+++ b/src/lib/libc/crypt/arc4random.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: arc4random.3,v 1.22 2007/05/31 19:19:27 jmc Exp $ 1.\" $OpenBSD: arc4random.3,v 1.23 2008/03/16 19:47:43 otto Exp $
2.\" 2.\"
3.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> 3.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
4.\" All rights reserved. 4.\" All rights reserved.
@@ -30,7 +30,7 @@
30.\" 30.\"
31.\" Manual page, using -mandoc macros 31.\" Manual page, using -mandoc macros
32.\" 32.\"
33.Dd $Mdocdate: May 31 2007 $ 33.Dd $Mdocdate: March 16 2008 $
34.Dt ARC4RANDOM 3 34.Dt ARC4RANDOM 3
35.Os 35.Os
36.Sh NAME 36.Sh NAME
@@ -43,6 +43,10 @@
43.Ft u_int32_t 43.Ft u_int32_t
44.Fn arc4random "void" 44.Fn arc4random "void"
45.Ft void 45.Ft void
46.Fn arc4random_buf "void *buf" "size_t nbytes"
47.Ft u_int32_t
48.Fn arc4random_uniform "u_int32_t upper_bound"
49.Ft void
46.Fn arc4random_stir "void" 50.Fn arc4random_stir "void"
47.Ft void 51.Ft void
48.Fn arc4random_addrandom "u_char *dat" "int datlen" 52.Fn arc4random_addrandom "u_char *dat" "int datlen"
@@ -73,6 +77,21 @@ versus the fast but poor quality interfaces described in
73and 77and
74.Xr drand48 3 . 78.Xr drand48 3 .
75.Pp 79.Pp
80.Fn arc4random_buf
81fills the region
82.Fa buf
83of length
84.Fa nbytes
85with ARC4-derived random data.
86.Pp
87.Fn arc4random_uniform
88will return a uniformly distributed random number less than
89.Fa upper_bound .
90.Fn arc4random_uniform
91is recommended over constructions like
92.Do Li arc4random() % upper_bound Dc
93as it avoids "modulo bias" when the upper bound is not a power of two.
94.Pp
76The 95The
77.Fn arc4random_stir 96.Fn arc4random_stir
78function reads data from 97function reads data from