aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/prng.h
blob: a81ed8e4ac05dba214f9396d0965f961b8e067bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 ---------------------------------------------------------------------------
 Copyright (c) 2002, Dr Brian Gladman <                 >, Worcester, UK.
 All rights reserved.

 LICENSE TERMS

 The free distribution and use of this software in both source and binary
 form is allowed (with or without changes) provided that:

   1. distributions of this source code include the above copyright
      notice, this list of conditions and the following disclaimer;

   2. distributions in binary form include the above copyright
      notice, this list of conditions and the following disclaimer
      in the documentation and/or other associated materials;

   3. the copyright holder's name is not used to endorse products
      built using this software without specific written permission.

 ALTERNATIVELY, provided that this notice is retained in full, this product
 may be distributed under the terms of the GNU General Public License (GPL),
 in which case the provisions of the GPL apply INSTEAD OF those given above.

 DISCLAIMER

 This software is provided 'as is' with no explicit or implied warranties
 in respect of its properties, including, but not limited to, correctness
 and/or fitness for purpose.
 ---------------------------------------------------------------------------
 Issue Date: 24/01/2003

 This is the header file for an implementation of a random data pool based on
 the use of an external entropy function (inspired by Peter Gutmann's work).
*/

#ifndef _PRNG_H
#define _PRNG_H

#include "sha1.h"

#define PRNG_POOL_LEN    256    /* minimum random pool size             */
#define PRNG_MIN_MIX      20    /* min initial pool mixing iterations   */

/* ensure that pool length is a multiple of the SHA1 digest size        */

#define PRNG_POOL_SIZE  (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE))

/* A function for providing entropy is a parameter in the prng_init()   */
/* call.  This function has the following form and returns a maximum    */
/* of 'len' bytes of pseudo random data in the buffer 'buf'.  It can    */
/* return less than 'len' bytes but will be repeatedly called for more  */
/* data in this case.                                                   */

typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len);

typedef struct
{   unsigned char   rbuf[PRNG_POOL_SIZE];   /* the random pool          */
    unsigned char   obuf[PRNG_POOL_SIZE];   /* pool output buffer       */
    unsigned int    pos;                    /* output buffer position   */
    prng_entropy_fn entropy;                /* entropy function pointer */
} prng_ctx;

/* initialise the random stream generator   */
void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]);

/* obtain random bytes from the generator   */
void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]);

/* close the random stream generator        */
void prng_end(prng_ctx ctx[1]);

#endif