comparison libtomcrypt/src/headers/tomcrypt_prng.h @ 293:9d110777f345 contrib-blacklist

propagate from branch 'au.asn.ucc.matt.dropbear' (head 7ad1775ed65e75dbece27fe6b65bf1a234db386a) to branch 'au.asn.ucc.matt.dropbear.contrib.blacklist' (head 1d86a4f0a401cc68c2670d821a2f6366c37af143)
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Mar 2006 06:31:29 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
247:c07de41b53d7 293:9d110777f345
1 /* ---- PRNG Stuff ---- */
2 #ifdef YARROW
3 struct yarrow_prng {
4 int cipher, hash;
5 unsigned char pool[MAXBLOCKSIZE];
6 symmetric_CTR ctr;
7 };
8 #endif
9
10 #ifdef RC4
11 struct rc4_prng {
12 int x, y;
13 unsigned char buf[256];
14 };
15 #endif
16
17 #ifdef FORTUNA
18 struct fortuna_prng {
19 hash_state pool[FORTUNA_POOLS]; /* the pools */
20
21 symmetric_key skey;
22
23 unsigned char K[32], /* the current key */
24 IV[16]; /* IV for CTR mode */
25
26 unsigned long pool_idx, /* current pool we will add to */
27 pool0_len, /* length of 0'th pool */
28 wd;
29
30 ulong64 reset_cnt; /* number of times we have reset */
31 };
32 #endif
33
34 #ifdef SOBER128
35 struct sober128_prng {
36 ulong32 R[17], /* Working storage for the shift register */
37 initR[17], /* saved register contents */
38 konst, /* key dependent constant */
39 sbuf; /* partial word encryption buffer */
40
41 int nbuf, /* number of part-word stream bits buffered */
42 flag, /* first add_entropy call or not? */
43 set; /* did we call add_entropy to set key? */
44
45 };
46 #endif
47
48 typedef union Prng_state {
49 #ifdef YARROW
50 struct yarrow_prng yarrow;
51 #endif
52 #ifdef RC4
53 struct rc4_prng rc4;
54 #endif
55 #ifdef FORTUNA
56 struct fortuna_prng fortuna;
57 #endif
58 #ifdef SOBER128
59 struct sober128_prng sober128;
60 #endif
61 } prng_state;
62
63 extern struct ltc_prng_descriptor {
64 /** Name of the PRNG */
65 char *name;
66 /** size in bytes of exported state */
67 int export_size;
68 /** Start a PRNG state
69 @param prng [out] The state to initialize
70 @return CRYPT_OK if successful
71 */
72 int (*start)(prng_state *prng);
73 /** Add entropy to the PRNG
74 @param in The entropy
75 @param inlen Length of the entropy (octets)\
76 @param prng The PRNG state
77 @return CRYPT_OK if successful
78 */
79 int (*add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng);
80 /** Ready a PRNG state to read from
81 @param prng The PRNG state to ready
82 @return CRYPT_OK if successful
83 */
84 int (*ready)(prng_state *prng);
85 /** Read from the PRNG
86 @param out [out] Where to store the data
87 @param outlen Length of data desired (octets)
88 @param prng The PRNG state to read from
89 @return Number of octets read
90 */
91 unsigned long (*read)(unsigned char *out, unsigned long outlen, prng_state *prng);
92 /** Terminate a PRNG state
93 @param prng The PRNG state to terminate
94 @return CRYPT_OK if successful
95 */
96 int (*done)(prng_state *prng);
97 /** Export a PRNG state
98 @param out [out] The destination for the state
99 @param outlen [in/out] The max size and resulting size of the PRNG state
100 @param prng The PRNG to export
101 @return CRYPT_OK if successful
102 */
103 int (*pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng);
104 /** Import a PRNG state
105 @param in The data to import
106 @param inlen The length of the data to import (octets)
107 @param prng The PRNG to initialize/import
108 @return CRYPT_OK if successful
109 */
110 int (*pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng);
111 /** Self-test the PRNG
112 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
113 */
114 int (*test)(void);
115 } prng_descriptor[];
116
117 #ifdef YARROW
118 int yarrow_start(prng_state *prng);
119 int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
120 int yarrow_ready(prng_state *prng);
121 unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng);
122 int yarrow_done(prng_state *prng);
123 int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
124 int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
125 int yarrow_test(void);
126 extern const struct ltc_prng_descriptor yarrow_desc;
127 #endif
128
129 #ifdef FORTUNA
130 int fortuna_start(prng_state *prng);
131 int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
132 int fortuna_ready(prng_state *prng);
133 unsigned long fortuna_read(unsigned char *out, unsigned long outlen, prng_state *prng);
134 int fortuna_done(prng_state *prng);
135 int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
136 int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
137 int fortuna_test(void);
138 extern const struct ltc_prng_descriptor fortuna_desc;
139 #endif
140
141 #ifdef RC4
142 int rc4_start(prng_state *prng);
143 int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
144 int rc4_ready(prng_state *prng);
145 unsigned long rc4_read(unsigned char *out, unsigned long outlen, prng_state *prng);
146 int rc4_done(prng_state *prng);
147 int rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
148 int rc4_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
149 int rc4_test(void);
150 extern const struct ltc_prng_descriptor rc4_desc;
151 #endif
152
153 #ifdef SPRNG
154 int sprng_start(prng_state *prng);
155 int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
156 int sprng_ready(prng_state *prng);
157 unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng);
158 int sprng_done(prng_state *prng);
159 int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
160 int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
161 int sprng_test(void);
162 extern const struct ltc_prng_descriptor sprng_desc;
163 #endif
164
165 #ifdef SOBER128
166 int sober128_start(prng_state *prng);
167 int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
168 int sober128_ready(prng_state *prng);
169 unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state *prng);
170 int sober128_done(prng_state *prng);
171 int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
172 int sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
173 int sober128_test(void);
174 extern const struct ltc_prng_descriptor sober128_desc;
175 #endif
176
177 int find_prng(const char *name);
178 int register_prng(const struct ltc_prng_descriptor *prng);
179 int unregister_prng(const struct ltc_prng_descriptor *prng);
180 int prng_is_valid(int idx);
181 LTC_MUTEX_PROTO(ltc_prng_mutex);
182
183 /* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this
184 * might not work on all platforms as planned
185 */
186 unsigned long rng_get_bytes(unsigned char *out,
187 unsigned long outlen,
188 void (*callback)(void));
189
190 int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
191
192
193 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_prng.h,v $ */
194 /* $Revision: 1.3 $ */
195 /* $Date: 2005/06/19 18:00:28 $ */