xref: /dflybsd-src/share/man/man4/random.4 (revision d52e3170130f2ddf5b002f195940ccc0f0aaeeca)
12c3ea15cSSascha Wildner.\"
22c3ea15cSSascha Wildner.\" random.c -- A strong random number generator
32c3ea15cSSascha Wildner.\"
42c3ea15cSSascha Wildner.\" Version 0.92, last modified 21-Sep-95
52c3ea15cSSascha Wildner.\"
62c3ea15cSSascha Wildner.\" Copyright Theodore Ts'o, 1994, 1995.  All rights reserved.
72c3ea15cSSascha Wildner.\"
82c3ea15cSSascha Wildner.\" Redistribution and use in source and binary forms, with or without
92c3ea15cSSascha Wildner.\" modification, are permitted provided that the following conditions
102c3ea15cSSascha Wildner.\" are met:
112c3ea15cSSascha Wildner.\" 1. Redistributions of source code must retain the above copyright
122c3ea15cSSascha Wildner.\"    notice, and the entire permission notice in its entirety,
132c3ea15cSSascha Wildner.\"    including the disclaimer of warranties.
142c3ea15cSSascha Wildner.\" 2. Redistributions in binary form must reproduce the above copyright
152c3ea15cSSascha Wildner.\"    notice, this list of conditions and the following disclaimer in the
162c3ea15cSSascha Wildner.\"    documentation and/or other materials provided with the distribution.
172c3ea15cSSascha Wildner.\" 3. The name of the author may not be used to endorse or promote
182c3ea15cSSascha Wildner.\"    products derived from this software without specific prior
192c3ea15cSSascha Wildner.\"    written permission.
202c3ea15cSSascha Wildner.\"
212c3ea15cSSascha Wildner.\" ALTERNATIVELY, this product may be distributed under the terms of
222c3ea15cSSascha Wildner.\" the GNU Public License, in which case the provisions of the GPL are
232c3ea15cSSascha Wildner.\" required INSTEAD OF the above restrictions.  (This clause is
242c3ea15cSSascha Wildner.\" necessary due to a potential bad interaction between the GPL and
252c3ea15cSSascha Wildner.\" the restrictions contained in a BSD-style copyright.)
262c3ea15cSSascha Wildner.\"
272c3ea15cSSascha Wildner.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
282c3ea15cSSascha Wildner.\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
292c3ea15cSSascha Wildner.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
302c3ea15cSSascha Wildner.\" DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
312c3ea15cSSascha Wildner.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
322c3ea15cSSascha Wildner.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
332c3ea15cSSascha Wildner.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
342c3ea15cSSascha Wildner.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
352c3ea15cSSascha Wildner.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
362c3ea15cSSascha Wildner.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
372c3ea15cSSascha Wildner.\" OF THE POSSIBILITY OF SUCH DAMAGE.
382c3ea15cSSascha Wildner.\"
392c3ea15cSSascha Wildner.\" $FreeBSD: src/usr.sbin/rndcontrol/random.4,v 1.9.2.2 2001/11/24 16:14:18 dd Exp $
402c3ea15cSSascha Wildner.\"
41*d52e3170SSascha Wildner.Dd December 31, 2021
42f98e2cd5SAlex Hornung.Dt RANDOM 4
432c3ea15cSSascha Wildner.Os
442c3ea15cSSascha Wildner.Sh NAME
452c3ea15cSSascha Wildner.Nm random ,
462c3ea15cSSascha Wildner.Nm urandom
472c3ea15cSSascha Wildner.Nd random number devices
482c3ea15cSSascha Wildner.Sh DESCRIPTION
492c3ea15cSSascha WildnerThis device gathers environmental noise from device drivers, etc.,
502c3ea15cSSascha Wildnerand returns good random numbers, suitable for cryptographic use.
512c3ea15cSSascha WildnerBesides the obvious cryptographic uses, these numbers are also good
522c3ea15cSSascha Wildnerfor seeding TCP sequence numbers, and other places where it is
532c3ea15cSSascha Wildnerdesirable to have numbers which are not only random, but hard to
542c3ea15cSSascha Wildnerpredict by an attacker.
552c3ea15cSSascha Wildner.Ss Theory of operation
562c3ea15cSSascha WildnerComputers are very predictable devices.  Hence it is extremely hard
572c3ea15cSSascha Wildnerto produce truly random numbers on a computer \(em as opposed to
582c3ea15cSSascha Wildnerpseudo-random numbers, which can easily be generated by using an
592c3ea15cSSascha Wildneralgorithm.  Unfortunately, it is very easy for attackers to guess
602c3ea15cSSascha Wildnerthe sequence of pseudo-random number generators, and for some
612c3ea15cSSascha Wildnerapplications this is not acceptable.  So instead, we must try to
622c3ea15cSSascha Wildnergather "environmental noise" from the computer's environment, which
632c3ea15cSSascha Wildnermust be hard for outside attackers to observe, and use that to
642c3ea15cSSascha Wildnergenerate random numbers.  In a Unix environment, this is best done
652c3ea15cSSascha Wildnerfrom inside the kernel.
662c3ea15cSSascha Wildner.Pp
672c3ea15cSSascha WildnerPrevious and contemporary
68265a1428SSascha Wildner.Nm
692c3ea15cSSascha Wildnerimplementations typically used
702c3ea15cSSascha Wildneran "entropy" pool which was processed with a cryptographic hash
712c3ea15cSSascha Wildnerfunction such as MD5. However, at the time of this writing security
722c3ea15cSSascha Wildnerissues have been discovered in some of these functions
732c3ea15cSSascha Wildner(MD4, MD5, SHA0, SHA1).
742c3ea15cSSascha Wildner.Pp
752c3ea15cSSascha WildnerThis implementation uses a CSPRNG (Cryptographically Secure Pseudo
762c3ea15cSSascha WildnerRandom Number Generator) which is continuously reseeded as described above.
772c3ea15cSSascha Wildner.Pp
782c3ea15cSSascha WildnerThe user interface consists of two character devices
792c3ea15cSSascha Wildner.Pa /dev/random
802c3ea15cSSascha Wildnerand
812c3ea15cSSascha Wildner.Pa /dev/urandom .
822c3ea15cSSascha WildnerThe
832c3ea15cSSascha Wildner.Pa /dev/random
842c3ea15cSSascha Wildnerdevice is suitable for use when very high quality randomness is desired
852c3ea15cSSascha Wildner(e.g. for key generation).  Previous implementations of this device
862c3ea15cSSascha Wildnerattempted to limit the number of returned bytes based on a guess as to
872c3ea15cSSascha Wildnerthe secureness of the pool.  However, this resulted in the interface being
882c3ea15cSSascha Wildnerso undependable that most programs just started using /dev/urandom
892c3ea15cSSascha Wildnerinstead of /dev/random.
902c3ea15cSSascha WildnerThe current
912c3ea15cSSascha Wildner.Dx
922c3ea15cSSascha Wildnerimplementation will return all requested bytes but the system reserves the
932c3ea15cSSascha Wildnerright in the future to limit the transfer rate to maintain the high quality
942c3ea15cSSascha Wildnerof randomness requested.
952c3ea15cSSascha Wildner.Pp
962c3ea15cSSascha WildnerThe
972c3ea15cSSascha Wildner.Pa /dev/urandom
982c3ea15cSSascha Wildnerdevice uses a different and much faster algorithm, but one which is not
992c3ea15cSSascha Wildnerconsidered to be as secure (though for all practical purposes it probably
1002c3ea15cSSascha Wildneris good enough).
1012c3ea15cSSascha Wildner.Pp
1022c3ea15cSSascha WildnerRoot may write entropy to
1032c3ea15cSSascha Wildner.Pa /dev/random
1042c3ea15cSSascha Wildnerto seed the random number generator only if the securelevel is less than
1052c3ea15cSSascha Wildneror equal to zero and the
1062c3ea15cSSascha Wildner.Va kern.seedenable
1072c3ea15cSSascha Wildnersysctl is non-zero.  A certain
1082c3ea15cSSascha Wildnerdegree of entropy is added by RC scripts during the boot sequence.
1092c3ea15cSSascha Wildner.Sh FILES
1102c3ea15cSSascha Wildner.Bl -tag -width Pa -compact
1112c3ea15cSSascha Wildner.It Pa /dev/random
1122c3ea15cSSascha Wildner.It Pa /dev/urandom
1132c3ea15cSSascha Wildner.El
114ec9265c3SFranco Fichtner.Sh SEE ALSO
1152c3ea15cSSascha Wildner.Xr arc4random 3 ,
1162c3ea15cSSascha Wildner.Xr drand48 3 ,
117*d52e3170SSascha Wildner.Xr getentropy 3 ,
1182c3ea15cSSascha Wildner.Xr rand 3 ,
1192c3ea15cSSascha Wildner.Xr RAND_add 3 ,
1202c3ea15cSSascha Wildner.Xr RAND_bytes 3 ,
1212c3ea15cSSascha Wildner.Xr random 3 ,
1222c3ea15cSSascha Wildner.Xr rndcontrol 8
1232c3ea15cSSascha Wildner.Sh HISTORY
1242c3ea15cSSascha WildnerThe
1252c3ea15cSSascha Wildner.Pa random ,
1262c3ea15cSSascha Wildner.Pa urandom
1272c3ea15cSSascha Wildnerfiles appeared in
1282c3ea15cSSascha Wildner.Fx 2.1.5 .
1292c3ea15cSSascha Wildner.Sh AUTHORS
1302c3ea15cSSascha Wildner.An -nosplit
1312c3ea15cSSascha Wildner.An Mark Murray
1322c3ea15cSSascha Wildnerwrote the
1332c3ea15cSSascha Wildner.Xr rndcontrol 8
1342c3ea15cSSascha Wildnerutility for
1352c3ea15cSSascha Wildner.Fx .
1362c3ea15cSSascha Wildner.Pp
1372c3ea15cSSascha WildnerThe
1382c3ea15cSSascha Wildner.Em IBAA
1392c3ea15cSSascha WildnerCSPRNG was developed by
1402c3ea15cSSascha Wildner.An Bob Jenkins
1412c3ea15cSSascha Wildnerand is used by
1422c3ea15cSSascha Wildner.Pa /dev/urandom .
143f98e2cd5SAlex HornungThe
144f98e2cd5SAlex Hornung.Dx
145f98e2cd5SAlex Hornungimplementation was ported by
146f98e2cd5SAlex Hornung.An Matthew Dillon
147f98e2cd5SAlex Hornungfrom initial work done by
148f98e2cd5SAlex Hornung.An Robin Carey .
149f98e2cd5SAlex HornungThe
150f98e2cd5SAlex Hornung.Pa /dev/random
151f98e2cd5SAlex Hornunggenerator uses a choice of
152f98e2cd5SAlex Hornung.Em IBAA
153f98e2cd5SAlex Hornungand a
154f98e2cd5SAlex Hornung.Em Fortuna
155f98e2cd5SAlex Hornung-based CSPRNG implemented by
156f98e2cd5SAlex Hornung.An Alex Hornung .
157