Mercurial > dropbear
diff eax_done.c @ 143:5d99163f7e32 libtomcrypt-orig
import of libtomcrypt 0.99
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:34:45 +0000 |
parents | 7faae8f46238 |
children |
line wrap: on
line diff
--- a/eax_done.c Tue Jun 15 14:07:21 2004 +0000 +++ b/eax_done.c Sun Dec 19 11:34:45 2004 +0000 @@ -17,17 +17,31 @@ int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen) { int err; - unsigned char headermac[MAXBLOCKSIZE], ctmac[MAXBLOCKSIZE]; + unsigned char *headermac, *ctmac; unsigned long x, len; _ARGCHK(eax != NULL); _ARGCHK(tag != NULL); _ARGCHK(taglen != NULL); + /* 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; + } + /* finish ctomac */ - len = sizeof(ctmac); + len = MAXBLOCKSIZE; if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) { - return err; + goto __ERR; } /* finish headeromac */ @@ -35,7 +49,7 @@ /* note we specifically don't reset len so the two lens are minimal */ if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) { - return err; + goto __ERR; } /* compute N xor H xor C */ @@ -44,13 +58,18 @@ } *taglen = x; + err = CRYPT_OK; +__ERR: #ifdef CLEAN_STACK - zeromem(ctmac, sizeof(ctmac)); - zeromem(headermac, sizeof(headermac)); - zeromem(eax, sizeof(*eax)); + zeromem(ctmac, MAXBLOCKSIZE); + zeromem(headermac, MAXBLOCKSIZE); + zeromem(eax, sizeof(*eax)); #endif - return CRYPT_OK; + XFREE(ctmac); + XFREE(headermac); + + return err; } #endif