1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3
4 #include "tomcrypt_private.h"
5
6 #ifdef LTC_BLAKE2BMAC
7
8 /**
9 Initialize an BLAKE2B MAC context.
10 @param st The BLAKE2B MAC state
11 @param outlen The size of the MAC output (octets)
12 @param key The secret key
13 @param keylen The length of the secret key (octets)
14 @return CRYPT_OK if successful
15 */
blake2bmac_init(blake2bmac_state * st,unsigned long outlen,const unsigned char * key,unsigned long keylen)16 int blake2bmac_init(blake2bmac_state *st, unsigned long outlen, const unsigned char *key, unsigned long keylen)
17 {
18 LTC_ARGCHK(st != NULL);
19 LTC_ARGCHK(key != NULL);
20 return blake2b_init(st, outlen, key, keylen);
21 }
22
23 /**
24 Process data through BLAKE2B MAC
25 @param st The BLAKE2B MAC state
26 @param in The data to send through HMAC
27 @param inlen The length of the data to HMAC (octets)
28 @return CRYPT_OK if successful
29 */
blake2bmac_process(blake2bmac_state * st,const unsigned char * in,unsigned long inlen)30 int blake2bmac_process(blake2bmac_state *st, const unsigned char *in, unsigned long inlen)
31 {
32 if (inlen == 0) return CRYPT_OK; /* nothing to do */
33 LTC_ARGCHK(st != NULL);
34 LTC_ARGCHK(in != NULL);
35 return blake2b_process(st, in, inlen);
36 }
37
38 /**
39 Terminate a BLAKE2B MAC session
40 @param st The BLAKE2B MAC state
41 @param mac [out] The destination of the BLAKE2B MAC authentication tag
42 @param maclen [in/out] The max size and resulting size of the BLAKE2B MAC authentication tag
43 @return CRYPT_OK if successful
44 */
blake2bmac_done(blake2bmac_state * st,unsigned char * mac,unsigned long * maclen)45 int blake2bmac_done(blake2bmac_state *st, unsigned char *mac, unsigned long *maclen)
46 {
47 LTC_ARGCHK(st != NULL);
48 LTC_ARGCHK(mac != NULL);
49 LTC_ARGCHK(maclen != NULL);
50 LTC_ARGCHK(*maclen >= st->blake2b.outlen);
51
52 *maclen = st->blake2b.outlen;
53 return blake2b_done(st, mac);
54 }
55
56 #endif
57