xref: /openbsd/share/man/man9/arc4random.9 (revision 4bdff4be)
1.\"	$OpenBSD: arc4random.9,v 1.15 2020/05/29 03:19:43 deraadt 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: May 29 2020 $
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.Ft void
44.Fn enqueue_randomness "int"
45.Sh DESCRIPTION
46.Fn arc4random
47and
48.Fn arc4random_buf
49provide random numbers and are intended to be called in any
50circumstance where random numbers are required.
51.Pp
52.Fn arc4random_uniform
53will return a uniformly distributed random number less than
54.Fa upper_bound ,
55avoiding "modulo bias" when the upper bound is not a power of two.
56In the worst case, this function may consume multiple iterations
57to ensure uniformity; see the source code to understand the problem
58and solution.
59.Pp
60.Fn enqueue_randomness
61causes the supplied data argument to be added to the entropy pool.
62.Sh SEE ALSO
63.Xr arc4random 3 ,
64.Xr random 4
65