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, process blocks with XCBC
18 /** Process data through XCBC-MAC
19 @param xcbc The XCBC-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 xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen)
31 LTC_ARGCHK(xcbc != NULL);
32 LTC_ARGCHK(in != NULL);
35 if ((err = cipher_is_valid(xcbc->cipher)) != CRYPT_OK) {
39 if ((xcbc->blocksize > cipher_descriptor[xcbc->cipher].block_length) || (xcbc->blocksize < 0) ||
40 (xcbc->buflen > xcbc->blocksize) || (xcbc->buflen < 0)) {
41 return CRYPT_INVALID_ARG;
45 if (xcbc->buflen == 0) {
46 while (inlen > (unsigned long)xcbc->blocksize) {
47 for (x = 0; x < xcbc->blocksize; x += sizeof(LTC_FAST_TYPE)) {
48 *(LTC_FAST_TYPE_PTR_CAST(&(xcbc->IV[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(in[x])));
50 cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
51 in += xcbc->blocksize;
52 inlen -= xcbc->blocksize;
58 if (xcbc->buflen == xcbc->blocksize) {
59 cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);
62 xcbc->IV[xcbc->buflen++] ^= *in++;
70 /* ref: $Format:%D$ */
71 /* git commit: $Format:%H$ */
72 /* commit time: $Format:%ai$ */