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, process blocks with f9
18 /** Process data through f9-MAC
19 @param f9 The f9-MAC state
20 @param in Input data to process
21 @param inlen Length of input in octets
22 Return CRYPT_OK on success
24 int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen)
28 LTC_ARGCHK(f9 != NULL);
29 LTC_ARGCHK(in != NULL);
32 if ((err = cipher_is_valid(f9->cipher)) != CRYPT_OK) {
36 if ((f9->blocksize > cipher_descriptor[f9->cipher].block_length) || (f9->blocksize < 0) ||
37 (f9->buflen > f9->blocksize) || (f9->buflen < 0)) {
38 return CRYPT_INVALID_ARG;
42 if (f9->buflen == 0) {
43 while (inlen >= (unsigned long)f9->blocksize) {
44 for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
45 *(LTC_FAST_TYPE_PTR_CAST(&(f9->IV[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(in[x])));
47 cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
48 for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
49 *(LTC_FAST_TYPE_PTR_CAST(&(f9->ACC[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(f9->IV[x])));
52 inlen -= f9->blocksize;
58 if (f9->buflen == f9->blocksize) {
59 cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
60 for (x = 0; x < f9->blocksize; x++) {
61 f9->ACC[x] ^= f9->IV[x];
65 f9->IV[f9->buflen++] ^= *in++;
73 /* ref: $Format:%D$ */
74 /* git commit: $Format:%H$ */
75 /* commit time: $Format:%ai$ */