1.\" $OpenBSD: arc4random.9,v 1.5 2011/01/09 02:20:53 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: January 9 2011 $ 27.Dt ARC4RANDOM 9 28.Os 29.Sh NAME 30.Nm arc4random 31.Nd kernel random subsystem 32.Sh SYNOPSIS 33.Fd #include <dev/rndvar.h> 34.Ft void 35.Fn add_true_randomness "int" 36.Ft void 37.Fn add_timer_randomness "int" 38.Ft void 39.Fn add_mouse_randomness "int" 40.Ft void 41.Fn add_tty_randomness "int" 42.Ft void 43.Fn add_net_randomness "int" 44.Ft void 45.Fn add_disk_randomness "int" 46.Ft void 47.Fn add_audio_randomness "int" 48.Ft u_int32_t 49.Fn arc4random "void" 50.Ft void 51.Fn arc4random_buf "void *buf" "size_t nbytes" 52.Ft u_int32_t 53.Fn arc4random_uniform "u_int32_t upper_bound" 54.Sh DESCRIPTION 55The 56.Fn add_mouse_randomness , 57.Fn add_tty_randomness , 58.Fn add_net_randomness , 59.Fn add_disk_randomness 60and 61.Fn add_audio_randomness 62routines are used to 63supply data for the random data source device for further processing. 64The processing involves calculating inter-event timedelta and measuring 65entropy contained in the resulting delta-T; the argument data supplied 66is just mixed into the pool and does not increase the entropy counter. 67.Pp 68.Fn add_true_randomness 69does not involve the usual timing calculations, 70and causes the supplied data argument to be added to the entropy pool, 71increasing the entropy counter by 32 bits. 72.Pp 73.Fn add_timer_randomness 74will not cause the entropy counter to rise. 75It is used to change the state of the pool periodically, 76mostly by means of timing the random driver's operations. 77.Pp 78.Fn arc4random 79and 80.Fn arc4random_buf 81provide random numbers. 82They may be called safely in any kernel context. 83.Pp 84.Fn arc4random_uniform 85will return a uniformly distributed random number less than 86.Fa upper_bound , 87avoiding "modulo bias" when the upper bound is not a power of two. 88.Sh SEE ALSO 89.Xr arc4random 3 , 90.Xr pchb 4 , 91.Xr random 4 92