1 .\" Copyright (c) 2001 Mark R V Murray. All rights reserved.
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\" notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\" notice, this list of conditions and the following disclaimer in the
10 .\" documentation and/or other materials provided with the distribution.
12 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .Nd the entropy device
38 returns an endless supply of random bytes when read.
39 It also accepts and reads data
40 as any ordinary (and willing) file,
41 but discards data written to it.
42 The device will probe for
43 certain hardware entropy sources,
44 and use these in preference to the fallback,
45 which is a generator implemented in software.
47 If the device is using
48 the software generator,
51 would perturb the internal state.
52 This perturbation of the internal state
53 is the only userland method of introducing
54 extra entropy into the device.
55 If the writer has superuser privilege,
56 then closing the device after writing
57 will make the software generator reseed itself.
58 This can be used for extra security,
59 as it immediately introduces any/all new entropy
61 The hardware generators will generate
62 sufficient quantities of entropy,
63 and will therefore ignore user-supplied input.
66 device may be controlled with
69 To see the current settings of the software
71 device, use the command line:
73 .Dl sysctl kern.random
75 which results in something like:
77 .Bd -literal -offset indent
78 kern.random.sys.seeded: 1
79 kern.random.sys.harvest.ethernet: 1
80 kern.random.sys.harvest.point_to_point: 1
81 kern.random.sys.harvest.interrupt: 1
82 kern.random.sys.harvest.swi: 0
83 kern.random.yarrow.gengateinterval: 10
84 kern.random.yarrow.bins: 10
85 kern.random.yarrow.fastthresh: 192
86 kern.random.yarrow.slowthresh: 256
87 kern.random.yarrow.slowoverthresh: 2
90 (These would not be seen if a
91 hardware generator is present.)
93 All settings are read/write.
96 .Va kern.random.sys.seeded
97 variable indicates whether or not the
99 device is in an acceptably secure state
100 as a result of reseeding.
101 If set to 0, the device will block (on read) until the next reseed
102 (which can be from an explicit write,
103 or as a result of entropy harvesting).
104 A reseed will set the value to 1 (non-blocking).
107 .Va kern.random.sys.harvest.ethernet
108 variable is used to select LAN traffic as an entropy source.
109 A 0 (zero) value means that LAN traffic
110 is not considered as an entropy source.
111 Set the variable to 1 (one)
112 if you wish to use LAN traffic for entropy harvesting.
115 .Va kern.random.sys.harvest.point_to_point
116 variable is used to select serial line traffic as an entropy source.
117 (Serial line traffic includes PPP, SLIP and all tun0 traffic.)
118 A 0 (zero) value means such traffic
119 is not considered as an entropy source.
120 Set the variable to 1 (one)
121 if you wish to use it for entropy harvesting.
124 .Va kern.random.sys.harvest.interrupt
125 variable is used to select hardware interrupts
126 as an entropy source.
127 A 0 (zero) value means hardware interrupts
128 are not considered as an entropy source.
129 Set the variable to 1 (one)
130 if you wish to use them for entropy harvesting.
131 All hardware interrupt harvesting is set up by the
132 individual device drivers.
135 .Va kern.random.sys.harvest.swi
136 variable is used to select software interrupts
137 as an entropy source.
138 A 0 (zero) value means software interrupts
139 are not considered as an entropy source.
140 Set the variable to 1 (one)
141 if you wish to use them for entropy harvesting.
143 The other variables are explained in the paper describing the
146 .Pa http://www.counterpane.com/yarrow.html .
148 These variables are all limited
149 in terms of the values they may contain:
150 .Bl -tag -width "kern.random.yarrow.gengateinterval" -compact -offset indent
151 .It Va kern.random.yarrow.gengateinterval
153 .It Va kern.random.yarrow.bins
155 .It Va kern.random.yarrow.fastthresh
157 .It Va kern.random.yarrow.slowthresh
159 .It Va kern.random.yarrow.slowoverthresh
165 handlers force the above variables
166 into the stated ranges.
168 The use of randomness in the field of computing
169 is a rather subtle issue because randomness means
170 different things to different people.
171 Consider generating a password randomly,
172 simulating a coin tossing experiment or
173 choosing a random back-off period when a server does not respond.
174 Each of these tasks requires random numbers,
175 but the random numbers in each case have different requirements.
177 Generation of passwords, session keys and the like
178 requires cryptographic randomness.
179 A cryptographic random number generator should be designed
180 so that its output is difficult to guess,
181 even if a lot of auxiliary information is known
182 (such as when it was seeded, subsequent or previous output, and so on).
185 seeding for cryptographic random number generators is provided by the
188 which provides real randomness.
191 library call provides a pseudo-random sequence
192 which is generally reckoned to be suitable for
193 simple cryptographic use.
194 The OpenSSL library also provides functions for managing randomness
195 via functions such as
199 Note that OpenSSL uses the
201 device for seeding automatically.
203 Randomness for simulation is required in engineering or
204 scientific software and games.
205 The first requirement of these applications is
206 that the random numbers produced conform to some well-known,
207 usually uniform, distribution.
208 The sequence of numbers should also appear numerically uncorrelated,
209 as simulation often assumes independence of its random inputs.
210 Often it is desirable to reproduce
211 the results of a simulation exactly,
212 so that if the generator is seeded in the same way,
213 it should produce the same results.
214 A peripheral concern for simulation is
215 the speed of a random number generator.
217 Another issue in simulation is
218 the size of the state associated with the random number generator, and
219 how frequently it repeats itself.
221 a program which shuffles a pack of cards should have 52!\& possible outputs,
222 which requires the random number generator to have 52!\& starting states.
223 This means the seed should have at least log_2(52!) ~ 226 bits of state
224 if the program is to stand a chance of outputting all possible sequences,
225 and the program needs some unbiased way of generating these bits.
229 device could be used for seeding here,
230 but in practice, smaller seeds are usually considered acceptable.
233 provides two families of functions which are considered
234 suitable for simulation.
237 family of functions provides a random integer
239 .if t 2\u\s731\s10\d\(mi1.
246 are provided for deterministically setting
247 the state of the generator and
250 is provided for setting the state via the
255 family of functions are also provided,
256 which provide random floating point numbers in various ranges.
258 Randomness that is used for collision avoidance
259 (for example, in certain network protocols)
260 has slightly different semantics again.
261 It is usually expected that the numbers will be uniform,
262 as this produces the lowest chances of collision.
264 the seeding of the generator is very important,
265 as it is required that different instances of
266 the generator produce independent sequences.
267 However, the guessability or reproducibility of the sequence is unimportant,
268 unlike the previous cases.
270 One final consideration for the seeding of random number generators
271 is a bootstrapping problem.
272 In some cases, it may be difficult to find enough randomness to
273 seed a random number generator until a system is fully operational,
274 but the system requires random numbers to become fully operational.
275 There is no substitute for careful thought here,
280 which is based on the Yarrow system,
281 should be of some help in this area.
284 does also provide the traditional
287 for compatibility purposes.
289 it is known to be poor for simulation and
290 absolutely unsuitable for cryptographic purposes,
291 so its use is discouraged.
293 .Bl -tag -width ".Pa /dev/random"
309 The early version was taken from Theodore Ts'o's entropy driver for Linux.
310 The current software implementation,
313 is a complete rewrite by
314 .An Mark R V Murray ,
315 and is an implementation of the
317 algorithm by Bruce Schneier,
319 The only hardware implementation
322 (stepping 3 or greater)
324 More will be added in the future.
326 The author gratefully acknowledges
327 significant assistance from VIA Technologies, Inc.