comparison eax_decrypt_verify_memory.c @ 0:d7da3b1e1540 libtomcrypt

put back the 0.95 makefile which was inadvertently merged over
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:21:40 +0000
parents
children 5d99163f7e32
comparison
equal deleted inserted replaced
-1:000000000000 0:d7da3b1e1540
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_decrypt_verify_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 *ct, unsigned long ctlen,
22 unsigned char *pt,
23 unsigned char *tag, unsigned long taglen,
24 int *res)
25 {
26 int err;
27 eax_state eax;
28 unsigned char buf[MAXBLOCKSIZE];
29 unsigned long buflen;
30
31 _ARGCHK(res != NULL);
32
33 /* default to zero */
34 *res = 0;
35
36 if ((err = eax_init(&eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
37 return err;
38 }
39
40 if ((err = eax_decrypt(&eax, ct, pt, ctlen)) != CRYPT_OK) {
41 return err;
42 }
43
44 buflen = MIN(sizeof(buf), taglen);
45 if ((err = eax_done(&eax, buf, &buflen)) != CRYPT_OK) {
46 return err;
47 }
48
49 /* compare tags */
50 if (buflen >= taglen && memcmp(buf, tag, taglen) == 0) {
51 *res = 1;
52 }
53
54 #ifdef CLEAN_STACK
55 zeromem(buf, sizeof(buf));
56 #endif
57 return CRYPT_OK;
58 }
59
60 #endif