xref: /openbsd-src/share/man/man9/arc4random.9 (revision 5accd69fd458bb5dc9e9270303b780d8dae36f82)
1*5accd69fSderaadt.\"	$OpenBSD: arc4random.9,v 1.15 2020/05/29 03:19:43 deraadt Exp $
20a2df620Sderaadt.\"
30a2df620Sderaadt.\" Copyright (c) 1996,2000 Michael Shalayeff
40a2df620Sderaadt.\" All rights reserved.
50a2df620Sderaadt.\"
60a2df620Sderaadt.\" Redistribution and use in source and binary forms, with or without
70a2df620Sderaadt.\" modification, are permitted provided that the following conditions
80a2df620Sderaadt.\" are met:
90a2df620Sderaadt.\" 1. Redistributions of source code must retain the above copyright
100a2df620Sderaadt.\"    notice, this list of conditions and the following disclaimer.
110a2df620Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
120a2df620Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
130a2df620Sderaadt.\"    documentation and/or other materials provided with the distribution.
140a2df620Sderaadt.\"
150a2df620Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
160a2df620Sderaadt.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
170a2df620Sderaadt.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
180a2df620Sderaadt.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
190a2df620Sderaadt.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
200a2df620Sderaadt.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
210a2df620Sderaadt.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
220a2df620Sderaadt.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
230a2df620Sderaadt.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
240a2df620Sderaadt.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
250a2df620Sderaadt.\"
26*5accd69fSderaadt.Dd $Mdocdate: May 29 2020 $
270a2df620Sderaadt.Dt ARC4RANDOM 9
280a2df620Sderaadt.Os
290a2df620Sderaadt.Sh NAME
3033378d91Sjmc.Nm arc4random ,
3133378d91Sjmc.Nm arc4random_buf ,
3233378d91Sjmc.Nm arc4random_uniform ,
333b5a7725Sjmc.Nm enqueue_randomness
340a2df620Sderaadt.Nd kernel random subsystem
350a2df620Sderaadt.Sh SYNOPSIS
36bbf9aadcStedu.In sys/systm.h
37bbf9aadcStedu.Ft u_int32_t
38bbf9aadcStedu.Fn arc4random "void"
39bbf9aadcStedu.Ft void
40bbf9aadcStedu.Fn arc4random_buf "void *buf" "size_t nbytes"
41bbf9aadcStedu.Ft u_int32_t
42bbf9aadcStedu.Fn arc4random_uniform "u_int32_t upper_bound"
430a2df620Sderaadt.Ft void
449e9abf5bSjasper.Fn enqueue_randomness "int"
450a2df620Sderaadt.Sh DESCRIPTION
460a2df620Sderaadt.Fn arc4random
470a2df620Sderaadtand
480a2df620Sderaadt.Fn arc4random_buf
49c818251cSderaadtprovide random numbers and are intended to be called in any
50c818251cSderaadtcircumstance where random numbers are required.
510a2df620Sderaadt.Pp
520a2df620Sderaadt.Fn arc4random_uniform
530a2df620Sderaadtwill return a uniformly distributed random number less than
540a2df620Sderaadt.Fa upper_bound ,
550a2df620Sderaadtavoiding "modulo bias" when the upper bound is not a power of two.
56c818251cSderaadtIn the worst case, this function may consume multiple iterations
57c818251cSderaadtto ensure uniformity; see the source code to understand the problem
58c818251cSderaadtand solution.
59c818251cSderaadt.Pp
60*5accd69fSderaadt.Fn enqueue_randomness
61*5accd69fSderaadtcauses the supplied data argument to be added to the entropy pool.
620a2df620Sderaadt.Sh SEE ALSO
630a2df620Sderaadt.Xr arc4random 3 ,
640a2df620Sderaadt.Xr random 4
65