Path: blob/master/libs/tomcrypt/src/mac/xcbc/xcbc_process.c
5972 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/8#include "tomcrypt.h"910/**11@file xcbc_process.c12XCBC Support, process blocks with XCBC13*/1415#ifdef LTC_XCBC1617/** Process data through XCBC-MAC18@param xcbc The XCBC-MAC state19@param in Input data to process20@param inlen Length of input in octets21Return CRYPT_OK on success22*/23int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen)24{25int err;26#ifdef LTC_FAST27int x;28#endif2930LTC_ARGCHK(xcbc != NULL);31LTC_ARGCHK(in != NULL);3233/* check structure */34if ((err = cipher_is_valid(xcbc->cipher)) != CRYPT_OK) {35return err;36}3738if ((xcbc->blocksize > cipher_descriptor[xcbc->cipher].block_length) || (xcbc->blocksize < 0) ||39(xcbc->buflen > xcbc->blocksize) || (xcbc->buflen < 0)) {40return CRYPT_INVALID_ARG;41}4243#ifdef LTC_FAST44if (xcbc->buflen == 0) {45while (inlen > (unsigned long)xcbc->blocksize) {46for (x = 0; x < xcbc->blocksize; x += sizeof(LTC_FAST_TYPE)) {47*(LTC_FAST_TYPE_PTR_CAST(&(xcbc->IV[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(in[x])));48}49cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);50in += xcbc->blocksize;51inlen -= xcbc->blocksize;52}53}54#endif5556while (inlen) {57if (xcbc->buflen == xcbc->blocksize) {58cipher_descriptor[xcbc->cipher].ecb_encrypt(xcbc->IV, xcbc->IV, &xcbc->key);59xcbc->buflen = 0;60}61xcbc->IV[xcbc->buflen++] ^= *in++;62--inlen;63}64return CRYPT_OK;65}6667#endif686970