comparison libtomcrypt/src/encauth/eax/eax_done.c @ 297:79bf1023cf11 agent-client

propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712) to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Mar 2006 16:20:59 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
225:ca7e76d981d9 297:79bf1023cf11
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
91
92 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_done.c,v $ */
93 /* $Revision: 1.4 $ */
94 /* $Date: 2005/05/05 14:35:58 $ */