Mercurial > dropbear
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:6362d3854bb4 | 143:5d99163f7e32 |
---|---|
15 #ifdef EAX_MODE | 15 #ifdef EAX_MODE |
16 | 16 |
17 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen) | 17 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen) |
18 { | 18 { |
19 int err; | 19 int err; |
20 unsigned char headermac[MAXBLOCKSIZE], ctmac[MAXBLOCKSIZE]; | 20 unsigned char *headermac, *ctmac; |
21 unsigned long x, len; | 21 unsigned long x, len; |
22 | 22 |
23 _ARGCHK(eax != NULL); | 23 _ARGCHK(eax != NULL); |
24 _ARGCHK(tag != NULL); | 24 _ARGCHK(tag != NULL); |
25 _ARGCHK(taglen != NULL); | 25 _ARGCHK(taglen != NULL); |
26 | 26 |
27 /* allocate ram */ | |
28 headermac = XMALLOC(MAXBLOCKSIZE); | |
29 ctmac = XMALLOC(MAXBLOCKSIZE); | |
30 | |
31 if (headermac == NULL || ctmac == NULL) { | |
32 if (headermac != NULL) { | |
33 XFREE(headermac); | |
34 } | |
35 if (ctmac != NULL) { | |
36 XFREE(ctmac); | |
37 } | |
38 return CRYPT_MEM; | |
39 } | |
40 | |
27 /* finish ctomac */ | 41 /* finish ctomac */ |
28 len = sizeof(ctmac); | 42 len = MAXBLOCKSIZE; |
29 if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) { | 43 if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) { |
30 return err; | 44 goto __ERR; |
31 } | 45 } |
32 | 46 |
33 /* finish headeromac */ | 47 /* finish headeromac */ |
34 | 48 |
35 /* note we specifically don't reset len so the two lens are minimal */ | 49 /* note we specifically don't reset len so the two lens are minimal */ |
36 | 50 |
37 if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) { | 51 if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) { |
38 return err; | 52 goto __ERR; |
39 } | 53 } |
40 | 54 |
41 /* compute N xor H xor C */ | 55 /* compute N xor H xor C */ |
42 for (x = 0; x < len && x < *taglen; x++) { | 56 for (x = 0; x < len && x < *taglen; x++) { |
43 tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x]; | 57 tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x]; |
44 } | 58 } |
45 *taglen = x; | 59 *taglen = x; |
46 | 60 |
61 err = CRYPT_OK; | |
62 __ERR: | |
47 #ifdef CLEAN_STACK | 63 #ifdef CLEAN_STACK |
48 zeromem(ctmac, sizeof(ctmac)); | 64 zeromem(ctmac, MAXBLOCKSIZE); |
49 zeromem(headermac, sizeof(headermac)); | 65 zeromem(headermac, MAXBLOCKSIZE); |
50 zeromem(eax, sizeof(*eax)); | 66 zeromem(eax, sizeof(*eax)); |
51 #endif | 67 #endif |
52 | 68 |
53 return CRYPT_OK; | 69 XFREE(ctmac); |
70 XFREE(headermac); | |
71 | |
72 return err; | |
54 } | 73 } |
55 | 74 |
56 #endif | 75 #endif |