tomcrypt/src/encauth/eax/eax_done.c

95 lines
2.1 KiB
C
Raw Normal View History

2004-05-12 20:42:16 +00:00
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*
2007-07-20 17:48:02 +00:00
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
2004-05-12 20:42:16 +00:00
*/
2004-12-30 23:55:53 +00:00
/**
@file eax_done.c
EAX implementation, terminate session, by Tom St Denis
*/
#include "tomcrypt.h"
2004-05-12 20:42:16 +00:00
2007-07-20 17:48:02 +00:00
#ifdef LTC_EAX_MODE
2004-05-12 20:42:16 +00:00
2004-12-30 23:55:53 +00:00
/**
Terminate an EAX session and get the tag.
@param eax The EAX state
@param tag [out] The destination of the authentication tag
@param taglen [in/out] The max length and resulting length of the authentication tag
@return CRYPT_OK if successful
*/
2004-05-12 20:42:16 +00:00
int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen)
{
int err;
2004-06-20 02:41:49 +00:00
unsigned char *headermac, *ctmac;
2004-05-12 20:42:16 +00:00
unsigned long x, len;
2004-12-30 23:55:53 +00:00
LTC_ARGCHK(eax != NULL);
LTC_ARGCHK(tag != NULL);
LTC_ARGCHK(taglen != NULL);
2004-05-12 20:42:16 +00:00
2004-06-20 02:41:49 +00:00
/* allocate ram */
headermac = XMALLOC(MAXBLOCKSIZE);
ctmac = XMALLOC(MAXBLOCKSIZE);
if (headermac == NULL || ctmac == NULL) {
if (headermac != NULL) {
XFREE(headermac);
}
if (ctmac != NULL) {
XFREE(ctmac);
}
return CRYPT_MEM;
}
2004-05-12 20:42:16 +00:00
/* finish ctomac */
2004-06-20 02:41:49 +00:00
len = MAXBLOCKSIZE;
2004-05-12 20:42:16 +00:00
if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) {
2004-12-30 23:55:53 +00:00
goto LBL_ERR;
2004-05-12 20:42:16 +00:00
}
/* finish headeromac */
/* note we specifically don't reset len so the two lens are minimal */
if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) {
2004-12-30 23:55:53 +00:00
goto LBL_ERR;
2004-05-12 20:42:16 +00:00
}
2005-04-17 11:37:13 +00:00
/* terminate the CTR chain */
if ((err = ctr_done(&eax->ctr)) != CRYPT_OK) {
goto LBL_ERR;
}
2004-05-12 20:42:16 +00:00
/* compute N xor H xor C */
for (x = 0; x < len && x < *taglen; x++) {
tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x];
}
*taglen = x;
2004-06-20 02:41:49 +00:00
err = CRYPT_OK;
2004-12-30 23:55:53 +00:00
LBL_ERR:
#ifdef LTC_CLEAN_STACK
2004-06-20 02:41:49 +00:00
zeromem(ctmac, MAXBLOCKSIZE);
zeromem(headermac, MAXBLOCKSIZE);
zeromem(eax, sizeof(*eax));
2004-05-12 20:42:16 +00:00
#endif
2004-06-20 02:41:49 +00:00
XFREE(ctmac);
XFREE(headermac);
return err;
2004-05-12 20:42:16 +00:00
}
#endif
2005-06-09 00:08:13 +00:00
/* $Source$ */
/* $Revision$ */
/* $Date$ */