Path: blob/master/libs/tomcrypt/src/mac/omac/omac_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 omac_memory.c12OMAC1 support, process a block of memory, Tom St Denis13*/1415#ifdef LTC_OMAC1617/**18OMAC a block of memory19@param cipher The index of the desired cipher20@param key The secret key21@param keylen The length of the secret key (octets)22@param in The data to send through OMAC23@param inlen The length of the data to send through OMAC (octets)24@param out [out] The destination of the authentication tag25@param outlen [in/out] The max size and resulting size of the authentication tag (octets)26@return CRYPT_OK if successful27*/28int omac_memory(int cipher,29const unsigned char *key, unsigned long keylen,30const unsigned char *in, unsigned long inlen,31unsigned char *out, unsigned long *outlen)32{33int err;34omac_state *omac;3536LTC_ARGCHK(key != NULL);37LTC_ARGCHK(in != NULL);38LTC_ARGCHK(out != NULL);39LTC_ARGCHK(outlen != NULL);4041/* is the cipher valid? */42if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {43return err;44}4546/* Use accelerator if found */47if (cipher_descriptor[cipher].omac_memory != NULL) {48return cipher_descriptor[cipher].omac_memory(key, keylen, in, inlen, out, outlen);49}5051/* allocate ram for omac state */52omac = XMALLOC(sizeof(omac_state));53if (omac == NULL) {54return CRYPT_MEM;55}5657/* omac process the message */58if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {59goto LBL_ERR;60}61if ((err = omac_process(omac, in, inlen)) != CRYPT_OK) {62goto LBL_ERR;63}64if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {65goto LBL_ERR;66}6768err = CRYPT_OK;69LBL_ERR:70#ifdef LTC_CLEAN_STACK71zeromem(omac, sizeof(omac_state));72#endif7374XFREE(omac);75return err;76}7778#endif798081