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 f9 Support, terminate the state
18 /** Terminate the f9-MAC state
19 @param f9 f9 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 f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen)
27 LTC_ARGCHK(f9 != NULL);
28 LTC_ARGCHK(out != NULL);
31 if ((err = cipher_is_valid(f9->cipher)) != CRYPT_OK) {
35 if ((f9->blocksize > cipher_descriptor[f9->cipher].block_length) || (f9->blocksize < 0) ||
36 (f9->buflen > f9->blocksize) || (f9->buflen < 0)) {
37 return CRYPT_INVALID_ARG;
40 if (f9->buflen != 0) {
42 cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
44 for (x = 0; x < f9->blocksize; x++) {
45 f9->ACC[x] ^= f9->IV[x];
49 /* schedule modified key */
50 if ((err = cipher_descriptor[f9->cipher].setup(f9->akey, f9->keylen, 0, &f9->key)) != CRYPT_OK) {
55 cipher_descriptor[f9->cipher].ecb_encrypt(f9->ACC, f9->ACC, &f9->key);
56 cipher_descriptor[f9->cipher].done(&f9->key);
59 for (x = 0; x < f9->blocksize && (unsigned long)x < *outlen; x++) {
64 #ifdef LTC_CLEAN_STACK
65 zeromem(f9, sizeof(*f9));
72 /* ref: $Format:%D$ */
73 /* git commit: $Format:%H$ */
74 /* commit time: $Format:%ai$ */