added iOS source code
[wl-app.git] / iOS / Pods / SSZipArchive / SSZipArchive / minizip / aes / prng.h
1 /*
2  ---------------------------------------------------------------------------
3  Copyright (c) 2002, Dr Brian Gladman <                 >, Worcester, UK.
4  All rights reserved.
5
6  LICENSE TERMS
7
8  The free distribution and use of this software in both source and binary
9  form is allowed (with or without changes) provided that:
10
11    1. distributions of this source code include the above copyright
12       notice, this list of conditions and the following disclaimer;
13
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;
17
18    3. the copyright holder's name is not used to endorse products
19       built using this software without specific written permission.
20
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.
24
25  DISCLAIMER
26
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
32
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).
35 */
36
37 #ifndef _PRNG_H
38 #define _PRNG_H
39
40 #include "sha1.h"
41
42 #define PRNG_POOL_LEN    256    /* minimum random pool size             */
43 #define PRNG_MIN_MIX      20    /* min initial pool mixing iterations   */
44
45 /* ensure that pool length is a multiple of the SHA1 digest size        */
46
47 #define PRNG_POOL_SIZE  (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE))
48
49 #if defined(__cplusplus)
50 extern "C"
51 {
52 #endif
53
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.                                                   */
59
60 typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len);
61
62 typedef struct
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 */
67 } prng_ctx;
68
69 /* initialise the random stream generator   */
70 void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]);
71
72 /* obtain random bytes from the generator   */
73 void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]);
74
75 /* close the random stream generator        */
76 void prng_end(prng_ctx ctx[1]);
77
78 #if defined(__cplusplus)
79 }
80 #endif
81
82 #endif