]> git.ipfire.org Git - thirdparty/strongswan.git/blame - doc/manpage.d/ipsec_prng_bytes.3.html
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / doc / manpage.d / ipsec_prng_bytes.3.html
CommitLineData
997358a6
MW
1Content-type: text/html
2
3<HTML><HEAD><TITLE>Manpage of IPSEC_PRNG</TITLE>
4</HEAD><BODY>
5<H1>IPSEC_PRNG</H1>
6Section: C Library Functions (3)<BR>Updated: 1 April 2002<BR><A HREF="#index">Index</A>
7<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
8
9
10<A NAME="lbAB">&nbsp;</A>
11<H2>NAME</H2>
12
13ipsec prng_init - initialize IPsec pseudorandom-number generator
14<BR>
15
16ipsec prng_bytes - get bytes from IPsec pseudorandom-number generator
17<BR>
18
19ipsec prng_final - close down IPsec pseudorandom-number generator
20<A NAME="lbAC">&nbsp;</A>
21<H2>SYNOPSIS</H2>
22
23<B>#include &lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
24
25<P>
26<B>void prng_init(struct prng *prng,</B>
27
28<BR>
29&nbsp;
30<B>const unsigned char *key, size_t keylen);</B>
31
32<BR>
33
34<B>void prng_bytes(struct prng *prng, char *dst,</B>
35
36<BR>
37&nbsp;
38<B>size_t dstlen);</B>
39
40<BR>
41
42<B>unsigned long prng_count(struct prng *prng);</B>
43
44<BR>
45
46<B>void prng_final(struct prng *prng);</B>
47
48<A NAME="lbAD">&nbsp;</A>
49<H2>DESCRIPTION</H2>
50
51<I>Prng_init</I>
52
53initializes a crypto-quality pseudo-random-number generator from a key;
54<I>prng_bytes</I>
55
56obtains pseudo-random bytes from it;
57<I>prng_count</I>
58
59reports the number of bytes extracted from it to date;
60<I>prng_final</I>
61
62closes it down.
63It is the user's responsibility to initialize a PRNG before using it,
64and not to use it again after it is closed down.
65<P>
66
67<I>Prng_init</I>
68
69initializes,
70or re-initializes,
71the specified
72<I>prng</I>
73
74from the
75<I>key</I>,
76
77whose length is given by
78<I>keylen</I>.
79
80The user must allocate the
81<B>struct prng</B>
82
83pointed to by
84<I>prng</I>.
85
86There is no particular constraint on the length of the key,
87although a key longer than 256 bytes is unnecessary because
88only the first 256 would be used.
89Initialization requires on the order of 3000 integer operations,
90independent of key length.
91<P>
92
93<I>Prng_bytes</I>
94
95obtains
96<I>dstlen</I>
97
98pseudo-random bytes from the PRNG and puts them in
99<I>buf</I>.
100
101This is quite fast,
102on the order of 10 integer operations per byte.
103<P>
104
105<I>Prng_count</I>
106
107reports the number of bytes obtained from the PRNG
108since it was (last) initialized.
109<P>
110
111<I>Prng_final</I>
112
113closes down a PRNG by
114zeroing its internal memory,
115obliterating all trace of the state used to generate its previous output.
116This requires on the order of 250 integer operations.
117<P>
118
119The
120<B>&lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>
121
122header file supplies the definition of the
123<B>prng</B>
124
125structure.
126Examination of its innards is discouraged, as they may change.
127<P>
128
129The PRNG algorithm
130used by these functions is currently identical to that of RC4(TM).
131This algorithm is cryptographically strong,
132sufficiently unpredictable that even a hostile observer will
133have difficulty determining the next byte of output from past history,
134provided it is initialized from a reasonably large key composed of
135highly random bytes (see
136<I><A HREF="random.4.html">random</A></I>(4)).
137
138The usual run of software pseudo-random-number generators
139(e.g.
140<I><A HREF="random.3.html">random</A></I>(3))
141
142are
143<I>not</I>
144
145cryptographically strong.
146<P>
147
148The well-known attacks against RC4(TM),
149e.g. as found in 802.11b's WEP encryption system,
150apply only if multiple PRNGs are initialized with closely-related keys
151(e.g., using a counter appended to a base key).
152If such keys are used, the first few hundred pseudo-random bytes
153from each PRNG should be discarded,
154to give the PRNGs a chance to randomize their innards properly.
155No useful attacks are known if the key is well randomized to begin with.
156<A NAME="lbAE">&nbsp;</A>
157<H2>SEE ALSO</H2>
158
159<A HREF="random.3.html">random</A>(3), <A HREF="random.4.html">random</A>(4)
160<BR>
161
162Bruce Schneier,
163<I>Applied Cryptography</I>, 2nd ed., 1996, ISBN 0-471-11709-9,
164pp. 397-8.
165<A NAME="lbAF">&nbsp;</A>
166<H2>HISTORY</H2>
167
168Written for the FreeS/WAN project by Henry Spencer.
169<A NAME="lbAG">&nbsp;</A>
170<H2>BUGS</H2>
171
172If an attempt is made to obtain more than 4e9 bytes
173between initializations,
174the PRNG will continue to work but
175<I>prng_count</I>'s
176
177output will stick at
178<B>4000000000</B>.
179
180Fixing this would require a longer integer type and does
181not seem worth the trouble,
182since you should probably re-initialize before then anyway...
183<P>
184
185``RC4'' is a trademark of RSA Data Security, Inc.
186<P>
187
188<HR>
189<A NAME="index">&nbsp;</A><H2>Index</H2>
190<DL>
191<DT><A HREF="#lbAB">NAME</A><DD>
192<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
193<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
194<DT><A HREF="#lbAE">SEE ALSO</A><DD>
195<DT><A HREF="#lbAF">HISTORY</A><DD>
196<DT><A HREF="#lbAG">BUGS</A><DD>
197</DL>
198<HR>
199This document was created by
200<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
201using the manual pages.<BR>
202Time: 21:40:18 GMT, November 11, 2003
203</BODY>
204</HTML>