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
12 EAX implementation, terminate session, by Tom St Denis
19 Terminate an EAX session and get the tag.
20 @param eax The EAX state
21 @param tag [out] The destination of the authentication tag
22 @param taglen [in/out] The max length and resulting length of the authentication tag
23 @return CRYPT_OK if successful
25 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen)
28 unsigned char *headermac, *ctmac;
31 LTC_ARGCHK(eax != NULL);
32 LTC_ARGCHK(tag != NULL);
33 LTC_ARGCHK(taglen != NULL);
36 headermac = XMALLOC(MAXBLOCKSIZE);
37 ctmac = XMALLOC(MAXBLOCKSIZE);
39 if (headermac == NULL || ctmac == NULL) {
40 if (headermac != NULL) {
51 if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) {
55 /* finish headeromac */
57 /* note we specifically don't reset len so the two lens are minimal */
59 if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) {
63 /* terminate the CTR chain */
64 if ((err = ctr_done(&eax->ctr)) != CRYPT_OK) {
68 /* compute N xor H xor C */
69 for (x = 0; x < len && x < *taglen; x++) {
70 tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x];
76 #ifdef LTC_CLEAN_STACK
77 zeromem(ctmac, MAXBLOCKSIZE);
78 zeromem(headermac, MAXBLOCKSIZE);
79 zeromem(eax, sizeof(*eax));
90 /* ref: $Format:%D$ */
91 /* git commit: $Format:%H$ */
92 /* commit time: $Format:%ai$ */