1.\" $OpenBSD: random.4,v 1.36 2020/05/29 03:27:29 deraadt Exp $ 2.\" 3.\" Copyright (c) 1996, 1997 Michael Shalayeff 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.Dd $Mdocdate: May 29 2020 $ 27.Dt RANDOM 4 28.Os 29.Sh NAME 30.Nm random , 31.Nm urandom 32.Nd random data source device 33.Sh DESCRIPTION 34The 35.Nm urandom 36device produces high quality pseudo-random output data without ever 37blocking. 38.Pp 39Entropy data stored previously is provided to the kernel during the 40boot sequence and used as inner-state of a stream cipher. 41High quality data is available immediately upon kernel startup. 42System activity (such as disk, network, and clock device interrupts), 43and hardware random generator output is collected, whitened with a crc 44and hash, then periodically folded together with stream cipher 45inner-state and outer-state to create a new inner state. 46Reads from all consumers (including the kernel itself, which makes many 47requests per second) are sliced from the same output stream, which carves 48the stream cipher output unpredictably and helps improve forward and 49backtracking protection beyond the strength of the stream cipher. 50.Pp 51The 52.Nm urandom 53device is intended to be used in scripts. 54In C programs, use the 55.Xr arc4random 3 56family of functions instead, which can be called in almost all 57coding environments, including 58.Xr pthreads 3 , 59.Xr chroot 2 , 60.Xr pledge 2 , 61and 62.Xr unveil 2 , 63and which avoids accessing a filesystem device every time. 64.Pp 65For portability reasons, never use 66.Pa /dev/random . 67On 68.Ox , 69it is an alias for 70.Pa /dev/urandom , 71but on many other systems misbehaves by blocking because their 72random number generators lack a robust boot-time initialization sequence. 73.Sh FILES 74.Bl -tag -width /dev/urandom -compact 75.It Pa /dev/urandom 76.El 77.Sh SEE ALSO 78.Xr arc4random 3 , 79.Xr amdpm 4 , 80.Xr glxsb 4 , 81.Xr pchb 4 , 82.Xr arc4random 9 83.Sh HISTORY 84A 85.Nm 86device first appeared in Linux in 1994. 87The 88.Nm random 89and 90.Nm urandom 91devices have been available since 92.Ox 2.0 . 93