1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10
11 #include "tomcrypt_private.h"
12
13 #ifdef LTC_BLAKE2BMAC
14
15 /**
16 BLAKE2B MAC a block of memory to produce the authentication tag
17 @param key The secret key
18 @param keylen The length of the secret key (octets)
19 @param in The data to BLAKE2B MAC
20 @param inlen The length of the data to BLAKE2B MAC (octets)
21 @param mac [out] Destination of the authentication tag
22 @param maclen [in/out] Max size and resulting size of authentication tag
23 @return CRYPT_OK if successful
24 */
blake2bmac_memory(const unsigned char * key,unsigned long keylen,const unsigned char * in,unsigned long inlen,unsigned char * mac,unsigned long * maclen)25 int blake2bmac_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen)
26 {
27 blake2bmac_state st;
28 int err;
29
30 LTC_ARGCHK(key != NULL);
31 LTC_ARGCHK(in != NULL);
32 LTC_ARGCHK(mac != NULL);
33 LTC_ARGCHK(maclen != NULL);
34
35 if ((err = blake2bmac_init(&st, *maclen, key, keylen)) != CRYPT_OK) { goto LBL_ERR; }
36 if ((err = blake2bmac_process(&st, in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
37 err = blake2bmac_done(&st, mac, maclen);
38 LBL_ERR:
39 #ifdef LTC_CLEAN_STACK
40 zeromem(&st, sizeof(blake2bmac_state));
41 #endif
42 return err;
43 }
44
45 #endif
46
47 /* ref: $Format:%D$ */
48 /* git commit: $Format:%H$ */
49 /* commit time: $Format:%ai$ */
50