3
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
|
2 * |
|
3 * LibTomCrypt is a library that provides various cryptographic |
|
4 * algorithms in a highly modular and flexible manner. |
|
5 * |
|
6 * The library is free for all purposes without any express |
|
7 * guarantee it works. |
|
8 * |
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
|
10 */ |
|
11 |
|
12 /* EAX Implementation by Tom St Denis */ |
|
13 #include "mycrypt.h" |
|
14 |
|
15 #ifdef EAX_MODE |
|
16 |
|
17 int eax_encrypt_authenticate_memory(int cipher, |
|
18 const unsigned char *key, unsigned long keylen, |
|
19 const unsigned char *nonce, unsigned long noncelen, |
|
20 const unsigned char *header, unsigned long headerlen, |
|
21 const unsigned char *pt, unsigned long ptlen, |
|
22 unsigned char *ct, |
|
23 unsigned char *tag, unsigned long *taglen) |
|
24 { |
|
25 int err; |
143
|
26 eax_state *eax; |
3
|
27 |
143
|
28 eax = XMALLOC(sizeof(eax_state)); |
|
29 |
|
30 if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) { |
|
31 goto __ERR; |
3
|
32 } |
|
33 |
143
|
34 if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) { |
|
35 goto __ERR; |
3
|
36 } |
|
37 |
143
|
38 if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) { |
|
39 goto __ERR; |
3
|
40 } |
|
41 |
143
|
42 err = CRYPT_OK; |
|
43 __ERR: |
|
44 #ifdef CLEAN_STACK |
|
45 zeromem(eax, sizeof(eax_state)); |
|
46 #endif |
|
47 |
|
48 XFREE(eax); |
|
49 |
|
50 return err; |
3
|
51 } |
|
52 |
|
53 #endif |