Path: blob/master/libs/tomcrypt/src/mac/xcbc/xcbc_memory.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, XCBC-MAC a block of memory13*/1415#ifdef LTC_XCBC1617/** XCBC-MAC a block of memory18@param cipher Index of cipher to use19@param key [in] Secret key20@param keylen Length of key in octets21@param in [in] Message to MAC22@param inlen Length of input in octets23@param out [out] Destination for the MAC tag24@param outlen [in/out] Output size and final tag size25Return CRYPT_OK on success.26*/27int xcbc_memory(int cipher,28const unsigned char *key, unsigned long keylen,29const unsigned char *in, unsigned long inlen,30unsigned char *out, unsigned long *outlen)31{32xcbc_state *xcbc;33int err;3435/* is the cipher valid? */36if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {37return err;38}3940/* Use accelerator if found */41if (cipher_descriptor[cipher].xcbc_memory != NULL) {42return cipher_descriptor[cipher].xcbc_memory(key, keylen, in, inlen, out, outlen);43}4445xcbc = XCALLOC(1, sizeof(*xcbc));46if (xcbc == NULL) {47return CRYPT_MEM;48}4950if ((err = xcbc_init(xcbc, cipher, key, keylen)) != CRYPT_OK) {51goto done;52}5354if ((err = xcbc_process(xcbc, in, inlen)) != CRYPT_OK) {55goto done;56}5758err = xcbc_done(xcbc, out, outlen);59done:60XFREE(xcbc);61return err;62}6364#endif656667