comparison libtomcrypt/src/mac/blake2/blake2bmac.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9
10 #include "tomcrypt.h"
11
12 #ifdef LTC_BLAKE2BMAC
13
14 /**
15 Initialize an BLAKE2B MAC context.
16 @param st The BLAKE2B MAC state
17 @param outlen The size of the MAC output (octets)
18 @param key The secret key
19 @param keylen The length of the secret key (octets)
20 @return CRYPT_OK if successful
21 */
22 int blake2bmac_init(blake2bmac_state *st, unsigned long outlen, const unsigned char *key, unsigned long keylen)
23 {
24 LTC_ARGCHK(st != NULL);
25 LTC_ARGCHK(key != NULL);
26 return blake2b_init(st, outlen, key, keylen);
27 }
28
29 /**
30 Process data through BLAKE2B MAC
31 @param st The BLAKE2B MAC state
32 @param in The data to send through HMAC
33 @param inlen The length of the data to HMAC (octets)
34 @return CRYPT_OK if successful
35 */
36 int blake2bmac_process(blake2bmac_state *st, const unsigned char *in, unsigned long inlen)
37 {
38 if (inlen == 0) return CRYPT_OK; /* nothing to do */
39 LTC_ARGCHK(st != NULL);
40 LTC_ARGCHK(in != NULL);
41 return blake2b_process(st, in, inlen);
42 }
43
44 /**
45 Terminate a BLAKE2B MAC session
46 @param st The BLAKE2B MAC state
47 @param mac [out] The destination of the BLAKE2B MAC authentication tag
48 @param maclen [in/out] The max size and resulting size of the BLAKE2B MAC authentication tag
49 @return CRYPT_OK if successful
50 */
51 int blake2bmac_done(blake2bmac_state *st, unsigned char *mac, unsigned long *maclen)
52 {
53 LTC_ARGCHK(st != NULL);
54 LTC_ARGCHK(mac != NULL);
55 LTC_ARGCHK(maclen != NULL);
56 LTC_ARGCHK(*maclen >= st->blake2b.outlen);
57
58 *maclen = st->blake2b.outlen;
59 return blake2b_done(st, mac);
60 }
61
62 #endif
63
64 /* ref: $Format:%D$ */
65 /* git commit: $Format:%H$ */
66 /* commit time: $Format:%ai$ */