1 .\" $NetBSD: rnd.9,v 1.16 2008/04/30 13:10:58 martin Exp $
3 .\" Copyright (c) 1997 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This documentation is derived from text contributed to The NetBSD
7 .\" Foundation by S.P.Zeidler (aka stargazer).
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
30 .Dd September 16, 2008
35 .Nm rnd_attach_source ,
36 .Nm rnd_detach_source ,
39 .Nd functions to make a device available for entropy collection
43 .Fn rnd_attach_source "rndsource_element_t *rnd_source" "char *devname" "uint32_t source_type" "uint32_t flags"
45 .Fn rnd_detach_source "rndsource_element_t *rnd_source"
47 .Fn rnd_add_data "rndsource_element_t *rnd_source" "void *data" "uint32_t len" "uint32_t entropy"
49 .Fn rnd_add_uint32 "rndsource_element_t *rnd_source" "uint32_t datum"
53 functions make a device available for entropy collection for
56 Ideally the first argument
58 of these functions gets included in the devices' entity struct,
59 but any means to permanently (static) attach one such argument
60 to one incarnation of the device is ok.
63 structures between two devices.
66 .It Fn rnd_attach_source "rndsource_element_t *rnd_source" "char *devname" "uint32_t source_type" "uint32_t flags"
67 This function announces the availability of a device for entropy collection.
68 It must be called before the source struct pointed to by
70 is used in any of the following functions.
73 is the name of the device.
74 It is used to print a message (if the kernel is compiled with
75 ``options RND_VERBOSE'') and also for status information printed with
89 for a random number generator.
91 is not to be used as a type.
92 It is used internally to the rnd system.
96 .Dv RND_FLAG_NO_COLLECT
97 (don't collect or estimate)
98 .Dv RND_FLAG_NO_ESTIMATE
100 to control the default setting for collection and estimation.
101 Note that devices of type
104 .Dv RND_FLAG_NO_ESTIMATE .
106 .It Fn rnd_detach_source "rndsource_element_t *rnd_source"
107 This function disconnects the device from entropy collection.
108 .It Fn rnd_add_uint32 "rndsource_element_t *rnd_source" "uint32_t datum"
109 This function adds the value of
112 No entropy is assumed to be collected from this value, it merely helps
113 stir the entropy pool.
114 All entropy is gathered from jitter between the timing of events.
116 Note that using a constant for
118 does not weaken security, but it does
120 Try to use something that can change, such as an interrupt status register
121 which might have a bit set for receive ready or transmit ready, or other
122 device status information.
124 To allow the system to gather the timing information accurately, this call
125 should be placed within the actual hardware interrupt service routine.
126 Care must be taken to ensure that the interrupt was actually serviced by
127 the interrupt handler, since on some systems interrupts can be shared.
129 This function loses nearly all usefulness if it is called from a scheduled
131 If that is the only way to add the device as an entropy source, don't.
133 If it is desired to mix in the
135 and to add in a timestamp, but not to actually estimate entropy from a source
136 of randomness, passing
140 is permitted, and the device does not need to be attached.
141 .It Fn rnd_add_data "rndsource_element_t *rnd_source" "void *data" "uint32_t len" "uint32_t entropy"
142 adds (hopefully) random
146 is the number of bytes in
150 is an "entropy quality" measurement.
153 is known to be random,
155 is the number of bits in
158 Timing information is also used to add entropy into the system, using
161 If it is desired to mix in the
163 and to add in a timestamp, but not to actually estimate entropy from a source
164 of randomness, passing
168 is permitted, and the device does not need to be attached.
172 These functions are declared in src/sys/sys/rnd.h and defined in
178 The random device was introduced in
181 This implementation was written by Michael Graff \*[Lt]explorer@flame.org\*[Gt]
182 using ideas and algorithms gathered from many sources, including
183 the driver written by Ted Ts'o.
185 The only good sources of randomness are quantum mechanical, and most
186 computers avidly avoid having true sources of randomness included.
187 Don't expect to surpass "pretty good".