xref: /openbsd-src/share/man/man9/arc4random.9 (revision 9f11ffb7133c203312a01e4b986886bc88c7d74b)
1.\"	$OpenBSD: arc4random.9,v 1.14 2018/04/28 20:25:07 jmc Exp $
2.\"
3.\" Copyright (c) 1996,2000 Michael Shalayeff
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.Dd $Mdocdate: April 28 2018 $
27.Dt ARC4RANDOM 9
28.Os
29.Sh NAME
30.Nm arc4random ,
31.Nm arc4random_buf ,
32.Nm arc4random_uniform ,
33.Nm enqueue_randomness
34.Nd kernel random subsystem
35.Sh SYNOPSIS
36.In sys/systm.h
37.Ft u_int32_t
38.Fn arc4random "void"
39.Ft void
40.Fn arc4random_buf "void *buf" "size_t nbytes"
41.Ft u_int32_t
42.Fn arc4random_uniform "u_int32_t upper_bound"
43.In dev/rndvar.h
44.Ft void
45.Fn enqueue_randomness "int"
46.Sh DESCRIPTION
47The
48.Fn add_random
49functions below mix input into the system entropy pool, which is then used
50to create a key for the ChaCha stream cipher used in the
51.Fn arc4random
52series of functions.
53.Pp
54.Fn enqueue_randomness
55causes the supplied data argument to be added to the entropy pool,
56increasing the entropy counter by 32 bits.
57.Pp
58.Fn arc4random
59and
60.Fn arc4random_buf
61provide random numbers and are intended to be called in any
62circumstance where random numbers are required.
63.Pp
64.Fn arc4random_uniform
65will return a uniformly distributed random number less than
66.Fa upper_bound ,
67avoiding "modulo bias" when the upper bound is not a power of two.
68In the worst case, this function may consume multiple iterations
69to ensure uniformity; see the source code to understand the problem
70and solution.
71.Pp
72.Fn arc4random ,
73.Fn arc4random_buf ,
74and
75.Fn arc4random_uniform
76may be called in nearly any kernel context.
77.Sh SEE ALSO
78.Xr arc4random 3 ,
79.Xr pchb 4 ,
80.Xr random 4
81