.\" .\" random.c -- A strong random number generator .\" .\" Version 0.92, last modified 21-Sep-95 .\" .\" Copyright Theodore Ts'o, 1994, 1995. All rights reserved. .\" .\" 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, and the entire permission notice in its entirety, .\" including the disclaimer of warranties. .\" 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. .\" 3. The name of the author may not be used to endorse or promote .\" products derived from this software without specific prior .\" written permission. .\" .\" ALTERNATIVELY, this product may be distributed under the terms of .\" the GNU Public License, in which case the provisions of the GPL are .\" required INSTEAD OF the above restrictions. (This clause is .\" necessary due to a potential bad interaction between the GPL and .\" the restrictions contained in a BSD-style copyright.) .\" .\" THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. .\" .\" $FreeBSD: src/usr.sbin/rndcontrol/random.4,v 1.9.2.2 2001/11/24 16:14:18 dd Exp $ .\" $DragonFly: src/usr.sbin/rndcontrol/random.4,v 1.13 2008/10/17 11:30:24 swildner Exp $ .\" .Dd October 21, 1995 .Dt RANDOM 4 i386 .Os .Sh NAME .Nm random , .Nm urandom .Nd random number devices .Sh DESCRIPTION This device gathers environmental noise from device drivers, etc., and returns good random numbers, suitable for cryptographic use. Besides the obvious cryptographic uses, these numbers are also good for seeding TCP sequence numbers, and other places where it is desirable to have numbers which are not only random, but hard to predict by an attacker. .Ss Theory of operation Computers are very predictable devices. Hence it is extremely hard to produce truly random numbers on a computer \(em as opposed to pseudo-random numbers, which can easily be generated by using an algorithm. Unfortunately, it is very easy for attackers to guess the sequence of pseudo-random number generators, and for some applications this is not acceptable. So instead, we must try to gather "environmental noise" from the computer's environment, which must be hard for outside attackers to observe, and use that to generate random numbers. In a Unix environment, this is best done from inside the kernel. .Pp Previous and contemporary .Xr random 4 implementations typically used an "entropy" pool which was processed with a cryptographic hash function such as MD5. However, at the time of this writing security issues have been discovered in some of these functions (MD4, MD5, SHA0, SHA1). .Pp This implementation uses a CSPRNG (Cryptographically Secure Pseudo Random Number Generator) which is continuously reseeded as described above. .Pp The user interface consists of two character devices .Pa /dev/random and .Pa /dev/urandom . The .Pa /dev/random device is suitable for use when very high quality randomness is desired (e.g. for key generation). Previous implementations of this device attempted to limit the number of returned bytes based on a guess as to the secureness of the pool. However, this resulted in the interface being so undependable that most programs just started using /dev/urandom instead of /dev/random. The current .Dx implementation will return all requested bytes but the system reserves the right in the future to limit the transfer rate to maintain the high quality of randomness requested. .Pp The .Pa /dev/urandom device uses a different and much faster algorithm, but one which is not considered to be as secure (though for all practical purposes it probably is good enough). .Pp Root may write entropy to .Pa /dev/random to seed the random number generator only if the securelevel is less than or equal to zero and the .Va kern.seedenable sysctl is non-zero. A certain degree of entropy is added by RC scripts during the boot sequence. .Sh FILES .Bl -tag -width Pa -compact .It Pa /dev/random .It Pa /dev/urandom .El .Sh "SEE ALSO" .Xr arc4random 3 , .Xr drand48 3 , .Xr rand 3 , .Xr RAND_add 3 , .Xr RAND_bytes 3 , .Xr random 3 , .Xr rndcontrol 8 .Sh HISTORY The .Pa random , .Pa urandom files appeared in .Fx 2.1.5 . .Sh AUTHORS .An -nosplit The current algorithms are implemented by .An Robin Carey and were ported to .Dx by .An Matthew Dillon . .Pp .An Mark Murray wrote the .Xr rndcontrol 8 utility for .Fx . .Pp The .Em IBAA CSPRNG was developed by .An Bob Jenkins and is used by .Pa /dev/random . The .Em L15 CSPRNG (based on ARC4) was developed by .An Robin Carey and is used by .Pa /dev/urandom .