TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tomcrypt_mac.h
Go to the documentation of this file.
1 #ifdef LTC_HMAC
2 typedef struct Hmac_state {
3  hash_state md;
4  int hash;
5  hash_state hashstate;
6  unsigned char *key;
7 } hmac_state;
8 
9 int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
10 int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
11 int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
12 int hmac_test(void);
13 int hmac_memory(int hash,
14  const unsigned char *key, unsigned long keylen,
15  const unsigned char *in, unsigned long inlen,
16  unsigned char *out, unsigned long *outlen);
17 int hmac_memory_multi(int hash,
18  const unsigned char *key, unsigned long keylen,
19  unsigned char *out, unsigned long *outlen,
20  const unsigned char *in, unsigned long inlen, ...);
21 int hmac_file(int hash, const char *fname, const unsigned char *key,
22  unsigned long keylen,
23  unsigned char *dst, unsigned long *dstlen);
24 #endif
25 
26 #ifdef LTC_OMAC
27 
28 typedef struct {
29  int cipher_idx,
30  buflen,
31  blklen;
32  unsigned char block[MAXBLOCKSIZE],
34  Lu[2][MAXBLOCKSIZE];
35  symmetric_key key;
36 } omac_state;
37 
38 int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
39 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
40 int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
41 int omac_memory(int cipher,
42  const unsigned char *key, unsigned long keylen,
43  const unsigned char *in, unsigned long inlen,
44  unsigned char *out, unsigned long *outlen);
45 int omac_memory_multi(int cipher,
46  const unsigned char *key, unsigned long keylen,
47  unsigned char *out, unsigned long *outlen,
48  const unsigned char *in, unsigned long inlen, ...);
49 int omac_file(int cipher,
50  const unsigned char *key, unsigned long keylen,
51  const char *filename,
52  unsigned char *out, unsigned long *outlen);
53 int omac_test(void);
54 #endif /* LTC_OMAC */
55 
56 #ifdef LTC_PMAC
57 
58 typedef struct {
59  unsigned char Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
60  Li[MAXBLOCKSIZE], /* value of Li [current value, we calc from previous recall] */
61  Lr[MAXBLOCKSIZE], /* L * x^-1 */
62  block[MAXBLOCKSIZE], /* currently accumulated block */
63  checksum[MAXBLOCKSIZE]; /* current checksum */
64 
65  symmetric_key key; /* scheduled key for cipher */
66  unsigned long block_index; /* index # for current block */
67  int cipher_idx, /* cipher idx */
68  block_len, /* length of block */
69  buflen; /* number of bytes in the buffer */
70 } pmac_state;
71 
72 int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
73 int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
74 int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
75 
76 int pmac_memory(int cipher,
77  const unsigned char *key, unsigned long keylen,
78  const unsigned char *msg, unsigned long msglen,
79  unsigned char *out, unsigned long *outlen);
80 
81 int pmac_memory_multi(int cipher,
82  const unsigned char *key, unsigned long keylen,
83  unsigned char *out, unsigned long *outlen,
84  const unsigned char *in, unsigned long inlen, ...);
85 
86 int pmac_file(int cipher,
87  const unsigned char *key, unsigned long keylen,
88  const char *filename,
89  unsigned char *out, unsigned long *outlen);
90 
91 int pmac_test(void);
92 
93 /* internal functions */
94 int pmac_ntz(unsigned long x);
95 void pmac_shift_xor(pmac_state *pmac);
96 
97 #endif /* PMAC */
98 
99 #ifdef LTC_EAX_MODE
100 
101 #if !(defined(LTC_OMAC) && defined(LTC_CTR_MODE))
102  #error LTC_EAX_MODE requires LTC_OMAC and CTR
103 #endif
104 
105 typedef struct {
106  unsigned char N[MAXBLOCKSIZE];
107  symmetric_CTR ctr;
108  omac_state headeromac, ctomac;
109 } eax_state;
110 
111 int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
112  const unsigned char *nonce, unsigned long noncelen,
113  const unsigned char *header, unsigned long headerlen);
114 
115 int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
116 int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
117 int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
118 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
119 
120 int eax_encrypt_authenticate_memory(int cipher,
121  const unsigned char *key, unsigned long keylen,
122  const unsigned char *nonce, unsigned long noncelen,
123  const unsigned char *header, unsigned long headerlen,
124  const unsigned char *pt, unsigned long ptlen,
125  unsigned char *ct,
126  unsigned char *tag, unsigned long *taglen);
127 
128 int eax_decrypt_verify_memory(int cipher,
129  const unsigned char *key, unsigned long keylen,
130  const unsigned char *nonce, unsigned long noncelen,
131  const unsigned char *header, unsigned long headerlen,
132  const unsigned char *ct, unsigned long ctlen,
133  unsigned char *pt,
134  unsigned char *tag, unsigned long taglen,
135  int *stat);
136 
137  int eax_test(void);
138 #endif /* EAX MODE */
139 
140 #ifdef LTC_OCB_MODE
141 typedef struct {
142  unsigned char L[MAXBLOCKSIZE], /* L value */
143  Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
144  Li[MAXBLOCKSIZE], /* value of Li [current value, we calc from previous recall] */
145  Lr[MAXBLOCKSIZE], /* L * x^-1 */
146  R[MAXBLOCKSIZE], /* R value */
147  checksum[MAXBLOCKSIZE]; /* current checksum */
148 
149  symmetric_key key; /* scheduled key for cipher */
150  unsigned long block_index; /* index # for current block */
151  int cipher, /* cipher idx */
152  block_len; /* length of block */
153 } ocb_state;
154 
155 int ocb_init(ocb_state *ocb, int cipher,
156  const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
157 
158 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
159 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
160 
161 int ocb_done_encrypt(ocb_state *ocb,
162  const unsigned char *pt, unsigned long ptlen,
163  unsigned char *ct,
164  unsigned char *tag, unsigned long *taglen);
165 
166 int ocb_done_decrypt(ocb_state *ocb,
167  const unsigned char *ct, unsigned long ctlen,
168  unsigned char *pt,
169  const unsigned char *tag, unsigned long taglen, int *stat);
170 
171 int ocb_encrypt_authenticate_memory(int cipher,
172  const unsigned char *key, unsigned long keylen,
173  const unsigned char *nonce,
174  const unsigned char *pt, unsigned long ptlen,
175  unsigned char *ct,
176  unsigned char *tag, unsigned long *taglen);
177 
178 int ocb_decrypt_verify_memory(int cipher,
179  const unsigned char *key, unsigned long keylen,
180  const unsigned char *nonce,
181  const unsigned char *ct, unsigned long ctlen,
182  unsigned char *pt,
183  const unsigned char *tag, unsigned long taglen,
184  int *stat);
185 
186 int ocb_test(void);
187 
188 /* internal functions */
189 void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
190 int ocb_ntz(unsigned long x);
191 int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
192  unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
193 
194 #endif /* LTC_OCB_MODE */
195 
196 #ifdef LTC_CCM_MODE
197 
198 #define CCM_ENCRYPT 0
199 #define CCM_DECRYPT 1
200 
201 int ccm_memory(int cipher,
202  const unsigned char *key, unsigned long keylen,
203  symmetric_key *uskey,
204  const unsigned char *nonce, unsigned long noncelen,
205  const unsigned char *header, unsigned long headerlen,
206  unsigned char *pt, unsigned long ptlen,
207  unsigned char *ct,
208  unsigned char *tag, unsigned long *taglen,
209  int direction);
210 
211 int ccm_test(void);
212 
213 #endif /* LTC_CCM_MODE */
214 
215 #if defined(LRW_MODE) || defined(LTC_GCM_MODE)
216 void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c);
217 #endif
218 
219 
220 /* table shared between GCM and LRW */
221 #if defined(LTC_GCM_TABLES) || defined(LRW_TABLES) || ((defined(LTC_GCM_MODE) || defined(LTC_GCM_MODE)) && defined(LTC_FAST))
222 extern const unsigned char gcm_shift_table[];
223 #endif
224 
225 #ifdef LTC_GCM_MODE
226 
227 #define GCM_ENCRYPT 0
228 #define GCM_DECRYPT 1
229 
230 #define LTC_GCM_MODE_IV 0
231 #define LTC_GCM_MODE_AAD 1
232 #define LTC_GCM_MODE_TEXT 2
233 
234 typedef struct {
235  symmetric_key K;
236  unsigned char H[16], /* multiplier */
237  X[16], /* accumulator */
238  Y[16], /* counter */
239  Y_0[16], /* initial counter */
240  buf[16]; /* buffer for stuff */
241 
242  int cipher, /* which cipher */
243  ivmode, /* Which mode is the IV in? */
244  mode, /* mode the GCM code is in */
245  buflen; /* length of data in buf */
246 
247  ulong64 totlen, /* 64-bit counter used for IV and AAD */
248  pttotlen; /* 64-bit counter for the PT */
249 
250 #ifdef LTC_GCM_TABLES
251  unsigned char PC[16][256][16] /* 16 tables of 8x128 */
252 #ifdef LTC_GCM_TABLES_SSE2
253 __attribute__ ((aligned (16)))
254 #endif
255 ;
256 #endif
257 } gcm_state;
258 
259 void gcm_mult_h(gcm_state *gcm, unsigned char *I);
260 
261 int gcm_init(gcm_state *gcm, int cipher,
262  const unsigned char *key, int keylen);
263 
264 int gcm_reset(gcm_state *gcm);
265 
266 int gcm_add_iv(gcm_state *gcm,
267  const unsigned char *IV, unsigned long IVlen);
268 
269 int gcm_add_aad(gcm_state *gcm,
270  const unsigned char *adata, unsigned long adatalen);
271 
272 int gcm_process(gcm_state *gcm,
273  unsigned char *pt, unsigned long ptlen,
274  unsigned char *ct,
275  int direction);
276 
277 int gcm_done(gcm_state *gcm,
278  unsigned char *tag, unsigned long *taglen);
279 
280 int gcm_memory( int cipher,
281  const unsigned char *key, unsigned long keylen,
282  const unsigned char *IV, unsigned long IVlen,
283  const unsigned char *adata, unsigned long adatalen,
284  unsigned char *pt, unsigned long ptlen,
285  unsigned char *ct,
286  unsigned char *tag, unsigned long *taglen,
287  int direction);
288 int gcm_test(void);
289 
290 #endif /* LTC_GCM_MODE */
291 
292 #ifdef LTC_PELICAN
293 
294 typedef struct pelican_state
295 {
296  symmetric_key K;
297  unsigned char state[16];
298  int buflen;
299 } pelican_state;
300 
301 int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen);
302 int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen);
303 int pelican_done(pelican_state *pelmac, unsigned char *out);
304 int pelican_test(void);
305 
306 int pelican_memory(const unsigned char *key, unsigned long keylen,
307  const unsigned char *in, unsigned long inlen,
308  unsigned char *out);
309 
310 #endif
311 
312 #ifdef LTC_XCBC
313 
314 /* add this to "keylen" to xcbc_init to use a pure three-key XCBC MAC */
315 #define LTC_XCBC_PURE 0x8000UL
316 
317 typedef struct {
318  unsigned char K[3][MAXBLOCKSIZE],
319  IV[MAXBLOCKSIZE];
320 
321  symmetric_key key;
322 
323  int cipher,
324  buflen,
325  blocksize;
326 } xcbc_state;
327 
328 int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen);
329 int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen);
330 int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen);
331 int xcbc_memory(int cipher,
332  const unsigned char *key, unsigned long keylen,
333  const unsigned char *in, unsigned long inlen,
334  unsigned char *out, unsigned long *outlen);
335 int xcbc_memory_multi(int cipher,
336  const unsigned char *key, unsigned long keylen,
337  unsigned char *out, unsigned long *outlen,
338  const unsigned char *in, unsigned long inlen, ...);
339 int xcbc_file(int cipher,
340  const unsigned char *key, unsigned long keylen,
341  const char *filename,
342  unsigned char *out, unsigned long *outlen);
343 int xcbc_test(void);
344 
345 #endif
346 
347 #ifdef LTC_F9_MODE
348 
349 typedef struct {
350  unsigned char akey[MAXBLOCKSIZE],
351  ACC[MAXBLOCKSIZE],
352  IV[MAXBLOCKSIZE];
353 
354  symmetric_key key;
355 
356  int cipher,
357  buflen,
358  keylen,
359  blocksize;
360 } f9_state;
361 
362 int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen);
363 int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen);
364 int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen);
365 int f9_memory(int cipher,
366  const unsigned char *key, unsigned long keylen,
367  const unsigned char *in, unsigned long inlen,
368  unsigned char *out, unsigned long *outlen);
369 int f9_memory_multi(int cipher,
370  const unsigned char *key, unsigned long keylen,
371  unsigned char *out, unsigned long *outlen,
372  const unsigned char *in, unsigned long inlen, ...);
373 int f9_file(int cipher,
374  const unsigned char *key, unsigned long keylen,
375  const char *filename,
376  unsigned char *out, unsigned long *outlen);
377 int f9_test(void);
378 
379 #endif
380 
381 
382 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_mac.h,v $ */
383 /* $Revision: 1.23 $ */
384 /* $Date: 2007/05/12 14:37:41 $ */
#define Z
Definition: CollisionDetection.cpp:2283
#define I(x, y, z)
#define hash
Definition: private_namespace.h:186
#define MAXBLOCKSIZE
Definition: tomcrypt.h:23
#define X
Definition: CollisionDetection.cpp:2281
LinuxKernelCmpxchgFunc pLinuxKernelCmpxchg __attribute__((weak))
unsigned long long ulong64
Definition: tomcrypt_macros.h:7
#define H(x, y, z)
Definition: tomcrypt_hash.h:105
float length(float v)
Definition: vectorMath.h:208
int prev(int i, int n)
Definition: RecastContour.cpp:468
Definition: tomcrypt_cipher.h:141
G3D::int16 x
Definition: Vector2int16.h:37
#define Y
Definition: CollisionDetection.cpp:2282