.\" $OpenBSD: random.4,v 1.36 2020/05/29 03:27:29 deraadt Exp $ .\" .\" Copyright (c) 1996, 1997 Michael Shalayeff .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .Dd $Mdocdate: May 29 2020 $ .Dt RANDOM 4 .Os .Sh NAME .Nm random , .Nm urandom .Nd random data source device .Sh DESCRIPTION The .Nm urandom device produces high quality pseudo-random output data without ever blocking. .Pp Entropy data stored previously is provided to the kernel during the boot sequence and used as inner-state of a stream cipher. High quality data is available immediately upon kernel startup. System activity (such as disk, network, and clock device interrupts), and hardware random generator output is collected, whitened with a crc and hash, then periodically folded together with stream cipher inner-state and outer-state to create a new inner state. Reads from all consumers (including the kernel itself, which makes many requests per second) are sliced from the same output stream, which carves the stream cipher output unpredictably and helps improve forward and backtracking protection beyond the strength of the stream cipher. .Pp The .Nm urandom device is intended to be used in scripts. In C programs, use the .Xr arc4random 3 family of functions instead, which can be called in almost all coding environments, including .Xr pthreads 3 , .Xr chroot 2 , .Xr pledge 2 , and .Xr unveil 2 , and which avoids accessing a filesystem device every time. .Pp For portability reasons, never use .Pa /dev/random . On .Ox , it is an alias for .Pa /dev/urandom , but on many other systems misbehaves by blocking because their random number generators lack a robust boot-time initialization sequence. .Sh FILES .Bl -tag -width /dev/urandom -compact .It Pa /dev/urandom .El .Sh SEE ALSO .Xr arc4random 3 , .Xr amdpm 4 , .Xr glxsb 4 , .Xr pchb 4 , .Xr arc4random 9 .Sh HISTORY A .Nm device first appeared in Linux in 1994. The .Nm random and .Nm urandom devices have been available since .Ox 2.0 .