xref: /netbsd-src/share/man/man9/rnd.9 (revision 08c81a9c2dc8c7300e893321eb65c0925d60871c)
1.\"	$NetBSD: rnd.9,v 1.12 2002/08/19 17:41:46 wiz Exp $
2.\"
3.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This documentation is derived from text contributed to The NetBSD
7.\" Foundation by S.P.Zeidler (aka stargazer).
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd October 20, 1997
38.Dt RND 9
39.Os
40.Sh NAME
41.Nm RND ,
42.Nm rnd_attach_source ,
43.Nm rnd_detach_source ,
44.Nm rnd_add_data ,
45.Nm rnd_add_uint32
46.Nd functions to make a device available for entropy collection
47.Sh SYNOPSIS
48.Fd #include \*[Lt]sys/rnd.h\*[Gt]
49.Ft void
50.Fn rnd_attach_source "rndsource_element_t *rnd_source" "char *devname" "u_int32_t source_type" "u_int32_t flags"
51.Ft void
52.Fn rnd_detach_source "rndsource_element_t *rnd_source"
53.Ft void
54.Fn rnd_add_data "rndsource_element_t *rnd_source" "void *data" "u_int32_t len" "u_int32_t entropy"
55.Ft void
56.Fn rnd_add_uint32 "rndsource_element_t *rnd_source" "u_int32_t datum"
57.Sh DESCRIPTION
58These
59.Nm
60functions make a device available for entropy collection for
61.Pa /dev/random .
62.Pp
63Ideally the first argument
64.Fa rnd_source
65of these functions gets included in the devices' entity struct,
66but any means to permanently (static) attach one such argument
67to one incarnation of the device is ok.  Do not share
68.Fa rnd_source
69structures between two devices.
70.Pp
71.Bl -tag -width 8n
72.It Fn rnd_attach_source "rndsource_element_t *rnd_source" "char *devname" "u_int32_t source_type" "u_int32_t flags"
73This function announces the availability of a device for entropy collection.
74It must be called before the source struct pointed to by
75.Fa rnd_source
76is used in any of the following functions.
77.Pp
78.Fa devname
79is the name of the device.  It is used to print a message (if the kernel is
80compiled with ``options RND_VERBOSE'') and also for status information printed
81with
82.Xr rndctl 8 .
83.Pp
84.Fa source_type
85is
86.Dv RND_TYPE_NET
87for network devices,
88.Dv RND_TYPE_DISK
89for physical disks,
90.Dv RND_TYPE_TAPE
91for a tape drive, and
92.Dv RND_TYPE_TTY
93for a tty.
94.Dv RND_TYPE_UNKNOWN
95is not to be used as a type.  It is used internally to the rnd system.
96.Pp
97.Fa flags
98are the logical OR of
99.Dv RND_FLAG_NO_COLLECT
100(don't collect or estimate)
101.Dv RND_FLAG_NO_ESTIMATE
102(don't estimate)
103to control the default setting for collection and estimation.  Note that
104devices of type
105.Dv RND_TYPE_NET
106default to
107.Dv RND_FLAG_NO_ESTIMATE .
108.Pp
109.It Fn rnd_detach_source "rndsource_element_t *rnd_source"
110This function disconnects the device from entropy collection.
111.It Fn rnd_add_uint32 "rndsource_element_t *rnd_source" "u_int32_t datum"
112This function adds the value of
113.Va datum
114to the entropy pool.  No entropy is assumed to be collected from this value,
115it merely helps stir the entropy pool.  All entropy is gathered from
116jitter between the timing of events.
117.Pp
118Note that using a constant for
119.Va datum
120does not weaken security, but it does
121not help.  Try to use something that can change, such as an interrupt status
122register which might have a bit set for receive ready or transmit ready,
123or other device status information.
124.Pp
125To allow the system to gather the timing information accurately, this call
126should be placed within the actual hardware interrupt service routine.  Care
127must be taken to ensure that the interrupt was actually serviced by the
128interrupt handler, since on some systems interrupts can be shared.
129.Pp
130This function loses nearly all usefulness if it is called from a scheduled
131software interrupt.  If that is the only way to add the device as an entropy
132source, don't.
133.Pp
134If it is desired to mix in the
135.Va datum
136and to add in a timestamp, but not to actually estimate entropy from a source
137of randomness, passing
138.Dv NULL
139for
140.Va rnd_source
141is permitted, and the device does not need to be attached.
142.It Fn rnd_add_data "rndsource_element_t *rnd_source" "void *data" "u_int32_t len" "u_int32_t entropy"
143adds (hopefully) random
144.Fa data
145to the entropy pool.
146.Fa len
147is the number of bytes in
148.Fa data
149and
150.Fa entropy
151is an "entropy quality" measurement.
152If every bit of
153.Fa data
154is known to be random,
155.Fa entropy
156is the number of bits in
157.Fa data .
158.Pp
159Timing information is also used to add entropy into the system, using
160inter-event timings.
161.Pp
162If it is desired to mix in the
163.Va data
164and to add in a timestamp, but not to actually estimate entropy from a source
165of randomness, passing
166.Dv NULL
167for
168.Va rnd_source
169is permitted, and the device does not need to be attached.
170.El
171.\" .Sh ERRORS
172.Sh FILES
173These functions are declared in src/sys/sys/rnd.h and defined in
174src/sys/dev/rnd.c.
175.Sh SEE ALSO
176.Xr rnd 4 ,
177.Xr rndctl 8
178.Sh HISTORY
179The random device was introduced in
180.Nx 1.3 .
181.Sh AUTHORS
182This implementation was written by Michael Graff \*[Lt]explorer@flame.org\*[Gt]
183using ideas and algorithms gathered from many sources, including
184the driver written by Ted Ts'o.
185.Sh BUGS
186The only good sources of randomness are quantum mechanical, and most
187computers avidly avoid having true sources of randomness included.
188Don't expect to surpass "pretty good".
189