1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 XCBC Support, terminate the state
18 /** Terminate the XCBC-MAC state
19 @param xcbc XCBC state to terminate
20 @param out [out] Destination for the MAC tag
21 @param outlen [in/out] Destination size and final tag size
22 Return CRYPT_OK on success
24 int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen)
27 LTC_ARGCHK(xcbc != NULL);
28 LTC_ARGCHK(out != NULL);
31 if ((err = cipher_is_valid(xcbc->cipher)) != CRYPT_OK) {
35 if ((xcbc->blocksize > cipher_descriptor[xcbc->cipher].block_length) || (xcbc->blocksize < 0) ||
36 (xcbc->buflen > xcbc->blocksize) || (xcbc->buflen < 0)) {
37 return CRYPT_INVALID_ARG;
40 /* which key do we use? */
41 if (xcbc->buflen == xcbc->blocksize) {
43 for (x = 0; x < xcbc->blocksize; x++) {
44 xcbc->IV[x] ^= xcbc->K[1][x];
47 xcbc->IV[xcbc->buflen] ^= 0x80;
49 for (x = 0; x < xcbc->blocksize; x++) {
50 xcbc->IV[x] ^= xcbc->K[2][x];
55 cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
56 cipher_descriptor[xcbc->cipher].done(&xcbc->key);
59 for (x = 0; x < xcbc->blocksize && (unsigned long)x < *outlen; x++) {
64 #ifdef LTC_CLEAN_STACK
65 zeromem(xcbc, sizeof(*xcbc));
72 /* ref: $Format:%D$ */
73 /* git commit: $Format:%H$ */
74 /* commit time: $Format:%ai$ */