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 Initialize an BLAKE2B MAC context.
17 @param st The BLAKE2B MAC state
18 @param outlen The size of the MAC output (octets)
19 @param key The secret key
20 @param keylen The length of the secret key (octets)
21 @return CRYPT_OK if successful
22 */
blake2bmac_init(blake2bmac_state * st,unsigned long outlen,const unsigned char * key,unsigned long keylen)23 int blake2bmac_init(blake2bmac_state *st, unsigned long outlen, const unsigned char *key, unsigned long keylen)
24 {
25 LTC_ARGCHK(st != NULL);
26 LTC_ARGCHK(key != NULL);
27 return blake2b_init(st, outlen, key, keylen);
28 }
29
30 /**
31 Process data through BLAKE2B MAC
32 @param st The BLAKE2B MAC state
33 @param in The data to send through HMAC
34 @param inlen The length of the data to HMAC (octets)
35 @return CRYPT_OK if successful
36 */
blake2bmac_process(blake2bmac_state * st,const unsigned char * in,unsigned long inlen)37 int blake2bmac_process(blake2bmac_state *st, const unsigned char *in, unsigned long inlen)
38 {
39 if (inlen == 0) return CRYPT_OK; /* nothing to do */
40 LTC_ARGCHK(st != NULL);
41 LTC_ARGCHK(in != NULL);
42 return blake2b_process(st, in, inlen);
43 }
44
45 /**
46 Terminate a BLAKE2B MAC session
47 @param st The BLAKE2B MAC state
48 @param mac [out] The destination of the BLAKE2B MAC authentication tag
49 @param maclen [in/out] The max size and resulting size of the BLAKE2B MAC authentication tag
50 @return CRYPT_OK if successful
51 */
blake2bmac_done(blake2bmac_state * st,unsigned char * mac,unsigned long * maclen)52 int blake2bmac_done(blake2bmac_state *st, unsigned char *mac, unsigned long *maclen)
53 {
54 LTC_ARGCHK(st != NULL);
55 LTC_ARGCHK(mac != NULL);
56 LTC_ARGCHK(maclen != NULL);
57 LTC_ARGCHK(*maclen >= st->blake2b.outlen);
58
59 *maclen = st->blake2b.outlen;
60 return blake2b_done(st, mac);
61 }
62
63 #endif
64
65 /* ref: $Format:%D$ */
66 /* git commit: $Format:%H$ */
67 /* commit time: $Format:%ai$ */
68