TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tomcrypt_prng.h
Go to the documentation of this file.
1 /* ---- PRNG Stuff ---- */
2 #ifdef LTC_YARROW
3 struct yarrow_prng {
4  int cipher, hash;
5  unsigned char pool[MAXBLOCKSIZE];
6  symmetric_CTR ctr;
7  LTC_MUTEX_TYPE(prng_lock)
8 };
9 #endif
10 
11 #ifdef LTC_RC4
12 struct rc4_prng {
13  int x, y;
14  unsigned char buf[256];
15 };
16 #endif
17 
18 #ifdef LTC_FORTUNA
19 struct fortuna_prng {
20  hash_state pool[LTC_FORTUNA_POOLS]; /* the pools */
21 
22  symmetric_key skey;
23 
24  unsigned char K[32], /* the current key */
25  IV[16]; /* IV for CTR mode */
26 
27  unsigned long pool_idx, /* current pool we will add to */
28  pool0_len, /* length of 0'th pool */
29  wd;
30 
31  ulong64 reset_cnt; /* number of times we have reset */
32  LTC_MUTEX_TYPE(prng_lock)
33 };
34 #endif
35 
36 #ifdef LTC_SOBER128
37 struct sober128_prng {
38  ulong32 R[17], /* Working storage for the shift register */
39  initR[17], /* saved register contents */
40  konst, /* key dependent constant */
41  sbuf; /* partial word encryption buffer */
42 
43  int nbuf, /* number of part-word stream bits buffered */
44  flag, /* first add_entropy call or not? */
45  set; /* did we call add_entropy to set key? */
46 
47 };
48 #endif
49 
50 typedef union Prng_state {
51  char dummy[1];
52 #ifdef LTC_YARROW
53  struct yarrow_prng yarrow;
54 #endif
55 #ifdef LTC_RC4
56  struct rc4_prng rc4;
57 #endif
58 #ifdef LTC_FORTUNA
59  struct fortuna_prng fortuna;
60 #endif
61 #ifdef LTC_SOBER128
62  struct sober128_prng sober128;
63 #endif
64 } prng_state;
65 
67 extern struct ltc_prng_descriptor {
69  char *name;
76  int (*start)(prng_state *prng);
83  int (*add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng);
88  int (*ready)(prng_state *prng);
95  unsigned long (*read)(unsigned char *out, unsigned long outlen, prng_state *prng);
100  int (*done)(prng_state *prng);
107  int (*pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng);
114  int (*pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng);
118  int (*test)(void);
119 } prng_descriptor[];
120 
121 #ifdef LTC_YARROW
122 int yarrow_start(prng_state *prng);
123 int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
124 int yarrow_ready(prng_state *prng);
125 unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng);
126 int yarrow_done(prng_state *prng);
127 int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
128 int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
129 int yarrow_test(void);
130 extern const struct ltc_prng_descriptor yarrow_desc;
131 #endif
132 
133 #ifdef LTC_FORTUNA
134 int fortuna_start(prng_state *prng);
135 int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
136 int fortuna_ready(prng_state *prng);
137 unsigned long fortuna_read(unsigned char *out, unsigned long outlen, prng_state *prng);
138 int fortuna_done(prng_state *prng);
139 int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
140 int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
141 int fortuna_test(void);
142 extern const struct ltc_prng_descriptor fortuna_desc;
143 #endif
144 
145 #ifdef LTC_RC4
146 int rc4_start(prng_state *prng);
147 int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
148 int rc4_ready(prng_state *prng);
149 unsigned long rc4_read(unsigned char *out, unsigned long outlen, prng_state *prng);
150 int rc4_done(prng_state *prng);
151 int rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
152 int rc4_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
153 int rc4_test(void);
154 extern const struct ltc_prng_descriptor rc4_desc;
155 #endif
156 
157 #ifdef LTC_SPRNG
158 int sprng_start(prng_state *prng);
159 int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
160 int sprng_ready(prng_state *prng);
161 unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng);
162 int sprng_done(prng_state *prng);
163 int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
164 int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
165 int sprng_test(void);
166 extern const struct ltc_prng_descriptor sprng_desc;
167 #endif
168 
169 #ifdef LTC_SOBER128
170 int sober128_start(prng_state *prng);
171 int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
172 int sober128_ready(prng_state *prng);
173 unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state *prng);
174 int sober128_done(prng_state *prng);
175 int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
176 int sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
177 int sober128_test(void);
178 extern const struct ltc_prng_descriptor sober128_desc;
179 #endif
180 
181 int find_prng(const char *name);
182 int register_prng(const struct ltc_prng_descriptor *prng);
183 int unregister_prng(const struct ltc_prng_descriptor *prng);
184 int prng_is_valid(int idx);
185 LTC_MUTEX_PROTO(ltc_prng_mutex)
186 
187 /* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this
188  * might not work on all platforms as planned
189  */
190 unsigned long rng_get_bytes(unsigned char *out,
191  unsigned long outlen,
192  void (*callback)(void));
193 
194 int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
195 
196 
197 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_prng.h,v $ */
198 /* $Revision: 1.9 $ */
199 /* $Date: 2007/05/12 14:32:35 $ */
int(* pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng)
Definition: tomcrypt_prng.h:107
#define hash
Definition: private_namespace.h:186
unsigned long(* read)(unsigned char *out, unsigned long outlen, prng_state *prng)
Definition: tomcrypt_prng.h:95
#define LTC_MUTEX_PROTO(x)
Definition: tomcrypt_custom.h:405
int(* test)(void)
Definition: tomcrypt_prng.h:118
#define MAXBLOCKSIZE
Definition: tomcrypt.h:23
int(* start)(prng_state *prng)
Definition: tomcrypt_prng.h:76
char dummy[1]
Definition: tomcrypt_prng.h:51
char * name
Definition: tomcrypt_prng.h:69
unsigned long ulong32
Definition: tomcrypt_macros.h:16
int(* ready)(prng_state *prng)
Definition: tomcrypt_prng.h:88
unsigned long long ulong64
Definition: tomcrypt_macros.h:7
unsigned long rng_get_bytes(unsigned char *out, unsigned long outlen, void(*callback)(void))
#define LTC_MUTEX_TYPE(x)
Definition: tomcrypt_custom.h:406
int prng_is_valid(int idx)
int rng_make_prng(int bits, int wprng, prng_state *prng, void(*callback)(void))
int(* done)(prng_state *prng)
Definition: tomcrypt_prng.h:100
int unregister_prng(const struct ltc_prng_descriptor *prng)
int register_prng(const struct ltc_prng_descriptor *prng)
union Prng_state prng_state
G3D::int16 y
Definition: Vector2int16.h:38
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
Definition: tomcrypt_hash.h:105
struct ltc_prng_descriptor prng_descriptor[]
int(* pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng)
Definition: tomcrypt_prng.h:114
Definition: tomcrypt_cipher.h:141
Definition: tomcrypt_prng.h:67
int export_size
Definition: tomcrypt_prng.h:71
G3D::int16 x
Definition: Vector2int16.h:37
int(* add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng)
Definition: tomcrypt_prng.h:83
Definition: tomcrypt_prng.h:50
int find_prng(const char *name)