1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
11 @file eax_decrypt_verify_memory.c
12 EAX implementation, decrypt block of memory, by Tom St Denis
19 Decrypt a block of memory and verify the provided MAC tag with EAX
20 @param cipher The index of the cipher desired
21 @param key The secret key
22 @param keylen The length of the key (octets)
23 @param nonce The nonce data (use once) for the session
24 @param noncelen The length of the nonce data.
25 @param header The session header data
26 @param headerlen The length of the header (octets)
27 @param ct The ciphertext
28 @param ctlen The length of the ciphertext (octets)
29 @param pt [out] The plaintext
30 @param tag The authentication tag provided by the encoder
31 @param taglen [in/out] The length of the tag (octets)
32 @param stat [out] The result of the decryption (1==valid tag, 0==invalid)
33 @return CRYPT_OK if successful regardless of the resulting tag comparison
35 int eax_decrypt_verify_memory(int cipher,
36 const unsigned char *key, unsigned long keylen,
37 const unsigned char *nonce, unsigned long noncelen,
38 const unsigned char *header, unsigned long headerlen,
39 const unsigned char *ct, unsigned long ctlen,
41 unsigned char *tag, unsigned long taglen,
49 LTC_ARGCHK(stat != NULL);
50 LTC_ARGCHK(key != NULL);
51 LTC_ARGCHK(pt != NULL);
52 LTC_ARGCHK(ct != NULL);
53 LTC_ARGCHK(tag != NULL);
59 taglen = MIN(taglen, MAXBLOCKSIZE);
62 buf = XMALLOC(taglen);
63 eax = XMALLOC(sizeof(*eax));
64 if (eax == NULL || buf == NULL) {
74 if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
78 if ((err = eax_decrypt(eax, ct, pt, ctlen)) != CRYPT_OK) {
83 if ((err = eax_done(eax, buf, &buflen)) != CRYPT_OK) {
88 if (buflen >= taglen && XMEM_NEQ(buf, tag, taglen) == 0) {
94 #ifdef LTC_CLEAN_STACK
96 zeromem(eax, sizeof(*eax));
107 /* ref: $Format:%D$ */
108 /* git commit: $Format:%H$ */
109 /* commit time: $Format:%ai$ */