• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, tomstdenis@gmail.com, http://libtomcrypt.com
10  */
11 #include "tomcrypt.h"
12 
13 /**
14   @file f9_process.c
15   f9 Support, process blocks with f9
16 */
17 
18 #ifdef LTC_F9_MODE
19 
20 /** Process data through f9-MAC
21   @param f9       The f9-MAC state
22   @param in       Input data to process
23   @param inlen    Length of input in octets
24   Return CRYPT_OK on success
25 */
f9_process(f9_state * f9,const unsigned char * in,unsigned long inlen)26 int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen)
27 {
28    int err, x;
29 
30    LTC_ARGCHK(f9 != NULL);
31    LTC_ARGCHK(in   != NULL);
32 
33    /* check structure */
34    if ((err = cipher_is_valid(f9->cipher)) != CRYPT_OK) {
35       return err;
36    }
37 
38    if ((f9->blocksize > cipher_descriptor[f9->cipher].block_length) || (f9->blocksize < 0) ||
39        (f9->buflen > f9->blocksize) || (f9->buflen < 0)) {
40       return CRYPT_INVALID_ARG;
41    }
42 
43 #ifdef LTC_FAST
44    if (f9->buflen == 0) {
45        while (inlen >= (unsigned long)f9->blocksize) {
46            for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
47               *((LTC_FAST_TYPE*)&(f9->IV[x])) ^= *((LTC_FAST_TYPE*)&(in[x]));
48            }
49            cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
50            for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
51               *((LTC_FAST_TYPE*)&(f9->ACC[x])) ^= *((LTC_FAST_TYPE*)&(f9->IV[x]));
52            }
53            in    += f9->blocksize;
54            inlen -= f9->blocksize;
55        }
56   }
57 #endif
58 
59    while (inlen) {
60      if (f9->buflen == f9->blocksize) {
61          cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
62          for (x = 0; x < f9->blocksize; x++) {
63             f9->ACC[x] ^= f9->IV[x];
64          }
65          f9->buflen = 0;
66      }
67      f9->IV[f9->buflen++] ^= *in++;
68      --inlen;
69   }
70   return CRYPT_OK;
71 }
72 
73 #endif
74 
75 /* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_process.c,v $ */
76 /* $Revision: 1.3 $ */
77 /* $Date: 2006/12/16 17:41:21 $ */
78 
79