2 ---------------------------------------------------------------------------
3 Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
8 The free distribution and use of this software in both source and binary
9 form is allowed (with or without changes) provided that:
11 1. distributions of this source code include the above copyright
12 notice, this list of conditions and the following disclaimer;
14 2. distributions in binary form include the above copyright
15 notice, this list of conditions and the following disclaimer
16 in the documentation and/or other associated materials;
18 3. the copyright holder's name is not used to endorse products
19 built using this software without specific written permission.
21 ALTERNATIVELY, provided that this notice is retained in full, this product
22 may be distributed under the terms of the GNU General Public License (GPL),
23 in which case the provisions of the GPL apply INSTEAD OF those given above.
27 This software is provided 'as is' with no explicit or implied warranties
28 in respect of its properties, including, but not limited to, correctness
29 and/or fitness for purpose.
30 ---------------------------------------------------------------------------
31 Issue Date: 24/01/2003
33 This is the header file for an implementation of a random data pool based on
34 the use of an external entropy function (inspired by Peter Gutmann's work).
42 #define PRNG_POOL_LEN 256 /* minimum random pool size */
43 #define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */
45 /* ensure that pool length is a multiple of the SHA1 digest size */
47 #define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE))
49 #if defined(__cplusplus)
54 /* A function for providing entropy is a parameter in the prng_init() */
55 /* call. This function has the following form and returns a maximum */
56 /* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */
57 /* return less than 'len' bytes but will be repeatedly called for more */
58 /* data in this case. */
60 typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len);
63 { unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */
64 unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */
65 unsigned int pos; /* output buffer position */
66 prng_entropy_fn entropy; /* entropy function pointer */
69 /* initialise the random stream generator */
70 void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]);
72 /* obtain random bytes from the generator */
73 void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]);
75 /* close the random stream generator */
76 void prng_end(prng_ctx ctx[1]);
78 #if defined(__cplusplus)