5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 .Nm is_random_seeded ,
38 .Nd supply pseudo-random numbers
44 .Fn arc4random_buf "void *ptr" "size_t len"
46 .Fn arc4rand "void *ptr" "u_int length" "int reseed"
50 .Fn is_random_seeded "void"
52 .Fn read_random "void *buffer" "int count"
54 .Fn read_random_uio "struct uio *uio" "bool nonblock"
64 functions will return very good quality random numbers, suited for
65 security-related purposes.
66 Both are wrappers around the underlying
70 returns a 32-bit random value, while
83 kernel abstract entropy device.
84 Automatic reseeding happens at unspecified time and bytes (of output)
86 A reseed can be forced by passing a non-zero
92 function is used to read entropy directly from the kernel abstract entropy
95 blocks if and until the entropy device is seeded.
98 is filled with no more than
101 It is strongly advised that
103 is not used directly;
110 function can be used to check in advance if
113 (If random is seeded, it will not block.)
117 function behaves identically to
123 argument points to a buffer where random data should be stored.
126 is true and the random device is not seeded, this function does not return any
128 Otherwise, this function may block interruptibly until the random device is seeded.
129 If the function is interrupted before the random device is seeded, no data is
134 function will return a 31-bit value.
135 It is obsolete and scheduled to be removed in
140 .Sx SECURITY CONSIDERATIONS .
144 function uses the Chacha20 algorithm to generate a pseudo-random sequence of
150 to generate pseudo-random numbers
151 in the range from 0 to
152 .if t 2\u\s732\s10\d\(mi1.
158 the number of bytes placed in
162 returns zero when successful,
163 otherwise an error code is returned.
167 in the range from 0 to
168 .if t 2\u\s731\s10\d\(mi1.
177 points to an invalid memory region.
178 .It Bq Er EWOULDBLOCK
179 The random device is unseeded and
190 .Sh SECURITY CONSIDERATIONS
195 It is important to remember that the
197 function is entirely predictable.
198 It is easy for attackers to predict future output of
200 by recording some generated values.
201 We cannot emphasize strongly enough that
203 must not be used to generate values that are intended to be unpredictable.