1RANDOM(4)                  Linux Programmer's Manual                 RANDOM(4)
2
3
4

NAME

6       random, urandom - kernel random number source devices
7

DESCRIPTION

9       The character special files /dev/random and /dev/urandom (present since
10       Linux 1.3.30) provide an interface to the kernel's random number gener‐
11       ator.  File /dev/random has major device number 1 and minor device num‐
12       ber 8.  File /dev/urandom has major device number 1  and  minor  device
13       number 9.
14
15       The  random  number  generator  gathers environmental noise from device
16       drivers and other sources into an entropy  pool.   The  generator  also
17       keeps  an  estimate of the number of bits of noise in the entropy pool.
18       From this entropy pool random numbers are created.
19
20       When read, the /dev/random device will only return random bytes  within
21       the estimated number of bits of noise in the entropy pool.  /dev/random
22       should be suitable for uses that need very high quality randomness such
23       as  one-time  pad  or  key generation.  When the entropy pool is empty,
24       reads from /dev/random will block until additional environmental  noise
25       is gathered.
26
27       A  read  from  the  /dev/urandom device will not block waiting for more
28       entropy.  As a result, if  there  is  not  sufficient  entropy  in  the
29       entropy  pool,  the  returned  values are theoretically vulnerable to a
30       cryptographic attack on the algorithms used by the  driver.   Knowledge
31       of how to do this is not available in the current non-classified liter‐
32       ature, but it is theoretically possible that such an attack may  exist.
33       If this is a concern in your application, use /dev/random instead.
34

CONFIGURING

36       If  your  system  does  not  have  /dev/random and /dev/urandom created
37       already, they can be created with the following commands:
38
39               mknod -m 644 /dev/random c 1 8
40               mknod -m 644 /dev/urandom c 1 9
41               chown root:root /dev/random /dev/urandom
42
43       When a Linux system starts up without much  operator  interaction,  the
44       entropy  pool  may  be in a fairly predictable state.  This reduces the
45       actual amount of noise in the entropy  pool  below  the  estimate.   In
46       order  to counteract this effect, it helps to carry entropy pool infor‐
47       mation across shut-downs and start-ups.  To do this, add the  following
48       lines  to  an  appropriate  script which is run during the Linux system
49       start-up sequence:
50
51            echo "Initializing random number generator..."
52            random_seed=/var/run/random-seed
53            # Carry a random seed from start-up to start-up
54            # Load and then save the whole entropy pool
55            if [ -f $random_seed ]; then
56                cat $random_seed >/dev/urandom
57            else
58                touch $random_seed
59            fi
60            chmod 600 $random_seed
61            poolfile=/proc/sys/kernel/random/poolsize
62            [ -r $poolfile ] && bytes=`cat $poolfile` || bytes=512
63            dd if=/dev/urandom of=$random_seed count=1 bs=$bytes
64
65       Also, add the following lines in an appropriate  script  which  is  run
66       during the Linux system shutdown:
67
68            # Carry a random seed from shut-down to start-up
69            # Save the whole entropy pool
70            echo "Saving random seed..."
71            random_seed=/var/run/random-seed
72            touch $random_seed
73            chmod 600 $random_seed
74            poolfile=/proc/sys/kernel/random/poolsize
75            [ -r $poolfile ] && bytes=`cat $poolfile` || bytes=512
76            dd if=/dev/urandom of=$random_seed count=1 bs=$bytes
77

PROC INTERFACE

79       The  files  in  the  directory  /proc/sys/kernel/random  (present since
80       2.3.16) provide an additional interface to the /dev/random device.
81
82       The read-only file entropy_avail gives the available entropy. Normally,
83       this will be 4096 (bits), a full entropy pool.
84
85       The  file  poolsize  gives the size of the entropy pool. Normally, this
86       will be 512 (bytes).  It can be changed to any value for which an algo‐
87       rithm  is  available.  Currently the choices are 32, 64, 128, 256, 512,
88       1024, 2048.
89
90       The file read_wakeup_threshold contains the number of bits  of  entropy
91       required  for  waking  up processes that sleep waiting for entropy from
92       /dev/random.  The default is 64.  The file write_wakeup_threshold  con‐
93       tains  the  number  of bits of entropy below which we wake up processes
94       that do a select() or poll() for write access  to  /dev/random.   These
95       values can be changed by writing to the files.
96
97       The  read-only  files  uuid  and  boot_id  contain  random strings like
98       6fd5a44b-35f4-4ad4-a9b9-6b9be13e1fe9.  The former is  generated  afresh
99       for each read, the latter was generated once.
100

FILES

102       /dev/random
103       /dev/urandom
104

AUTHOR

106       The  kernel's  random  number  generator  was  written by Theodore Ts'o
107       (tytso@athena.mit.edu).
108

SEE ALSO

110       mknod (1)
111       RFC 1750, "Randomness Recommendations for Security"
112
113
114
115Linux                             2003-10-25                         RANDOM(4)
Impressum