Path: blob/master/libs/tomcrypt/src/mac/pmac/pmac_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 pmac_memory.c12PMAC implementation, process a block of memory, by Tom St Denis13*/1415#ifdef LTC_PMAC1617/**18PMAC a block of memory19@param cipher The index of the cipher desired20@param key The secret key21@param keylen The length of the secret key (octets)22@param in The data you wish to send through PMAC23@param inlen The length of data you wish to send through PMAC (octets)24@param out [out] Destination for the authentication tag25@param outlen [in/out] The max size and resulting size of the authentication tag26@return CRYPT_OK if successful27*/28int pmac_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;34pmac_state *pmac;3536LTC_ARGCHK(key != NULL);37LTC_ARGCHK(in != NULL);38LTC_ARGCHK(out != NULL);39LTC_ARGCHK(outlen != NULL);4041/* allocate ram for pmac state */42pmac = XMALLOC(sizeof(pmac_state));43if (pmac == NULL) {44return CRYPT_MEM;45}4647if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {48goto LBL_ERR;49}50if ((err = pmac_process(pmac, in, inlen)) != CRYPT_OK) {51goto LBL_ERR;52}53if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {54goto LBL_ERR;55}5657err = CRYPT_OK;58LBL_ERR:59#ifdef LTC_CLEAN_STACK60zeromem(pmac, sizeof(pmac_state));61#endif6263XFREE(pmac);64return err;65}6667#endif686970