comparison src/encauth/eax/eax_done.c @ 192:9cc34777b479 libtomcrypt

propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 9ba8f01f44320e9cb9f19881105ae84f84a43ea9) to branch 'au.asn.ucc.matt.dropbear.ltc' (head dbf51c569bc34956ad948e4cc87a0eeb2170b768)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 08 May 2005 06:36:47 +0000
parents 1c15b283127b
children 39d5d58461d6
comparison
equal deleted inserted replaced
164:cd1143579f00 192:9cc34777b479
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, [email protected], http://libtomcrypt.org
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