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, tomstdenis (at) gmail.com, http://libtomcrypt.com 10 */ 11 12 /** 13 @file eax_done.c 14 EAX implementation, terminate session, by Tom St Denis 15 */ 16 #include "tomcrypt.h" 17 18 #ifdef EAX_MODE 19 20 /** 21 Terminate an EAX session and get the tag. 22 @param eax The EAX state 23 @param tag [out] The destination of the authentication tag 24 @param taglen [in/out] The max length and resulting length of the authentication tag 25 @return CRYPT_OK if successful 26 */ 27 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen) 28 { 29 int err; 30 unsigned char *headermac, *ctmac; 31 unsigned long x, len; 32 33 LTC_ARGCHK(eax != NULL); 34 LTC_ARGCHK(tag != NULL); 35 LTC_ARGCHK(taglen != NULL); 36 37 /* allocate ram */ 38 headermac = XMALLOC(MAXBLOCKSIZE); 39 ctmac = XMALLOC(MAXBLOCKSIZE); 40 41 if (headermac == NULL || ctmac == NULL) { 42 if (headermac != NULL) { 43 XFREE(headermac); 44 } 45 if (ctmac != NULL) { 46 XFREE(ctmac); 47 } 48 return CRYPT_MEM; 49 } 50 51 /* finish ctomac */ 52 len = MAXBLOCKSIZE; 53 if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) { 54 goto LBL_ERR; 55 } 56 57 /* finish headeromac */ 58 59 /* note we specifically don't reset len so the two lens are minimal */ 60 61 if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) { 62 goto LBL_ERR; 63 } 64 65 /* terminate the CTR chain */ 66 if ((err = ctr_done(&eax->ctr)) != CRYPT_OK) { 67 goto LBL_ERR; 68 } 69 70 /* compute N xor H xor C */ 71 for (x = 0; x < len && x < *taglen; x++) { 72 tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x]; 73 } 74 *taglen = x; 75 76 err = CRYPT_OK; 77 LBL_ERR: 78 #ifdef LTC_CLEAN_STACK 79 zeromem(ctmac, MAXBLOCKSIZE); 80 zeromem(headermac, MAXBLOCKSIZE); 81 zeromem(eax, sizeof(*eax)); 82 #endif 83 84 XFREE(ctmac); 85 XFREE(headermac); 86 87 return err; 88 } 89 90 #endif 91 92 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_done.c,v $ */ 93 /* $Revision: 1.5 $ */ 94 /* $Date: 2006/03/31 14:15:35 $ */ 95