Mercurial > dropbear
comparison libtomcrypt/src/mac/xcbc/xcbc_done.c @ 382:0cbe8f6dbf9e
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f)
to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 11 Jan 2007 02:41:05 +0000 |
parents | |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
379:b66a00272a90 | 382:0cbe8f6dbf9e |
---|---|
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.com | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file xcbc_done.c | |
15 XCBC Support, terminate the state | |
16 */ | |
17 | |
18 #ifdef LTC_XCBC | |
19 | |
20 /** Terminate the XCBC-MAC state | |
21 @param xcbc XCBC state to terminate | |
22 @param out [out] Destination for the MAC tag | |
23 @param outlen [in/out] Destination size and final tag size | |
24 Return CRYPT_OK on success | |
25 */ | |
26 int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen) | |
27 { | |
28 int err, x; | |
29 LTC_ARGCHK(xcbc != NULL); | |
30 LTC_ARGCHK(out != NULL); | |
31 | |
32 /* check structure */ | |
33 if ((err = cipher_is_valid(xcbc->cipher)) != CRYPT_OK) { | |
34 return err; | |
35 } | |
36 | |
37 if ((xcbc->blocksize > cipher_descriptor[xcbc->cipher].block_length) || (xcbc->blocksize < 0) || | |
38 (xcbc->buflen > xcbc->blocksize) || (xcbc->buflen < 0)) { | |
39 return CRYPT_INVALID_ARG; | |
40 } | |
41 | |
42 /* which key do we use? */ | |
43 if (xcbc->buflen == xcbc->blocksize) { | |
44 /* k2 */ | |
45 for (x = 0; x < xcbc->blocksize; x++) { | |
46 xcbc->IV[x] ^= xcbc->K[1][x]; | |
47 } | |
48 } else { | |
49 xcbc->IV[xcbc->buflen] ^= 0x80; | |
50 /* k3 */ | |
51 for (x = 0; x < xcbc->blocksize; x++) { | |
52 xcbc->IV[x] ^= xcbc->K[2][x]; | |
53 } | |
54 } | |
55 | |
56 /* encrypt */ | |
57 cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key); | |
58 cipher_descriptor[xcbc->cipher].done(&xcbc->key); | |
59 | |
60 /* extract tag */ | |
61 for (x = 0; x < xcbc->blocksize && (unsigned long)x < *outlen; x++) { | |
62 out[x] = xcbc->IV[x]; | |
63 } | |
64 *outlen = x; | |
65 | |
66 #ifdef LTC_CLEAN_STACK | |
67 zeromem(xcbc, sizeof(*xcbc)); | |
68 #endif | |
69 return CRYPT_OK; | |
70 } | |
71 | |
72 #endif | |
73 | |
74 /* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_done.c,v $ */ | |
75 /* $Revision: 1.4 $ */ | |
76 /* $Date: 2006/11/07 03:23:46 $ */ | |
77 |