comparison libtomcrypt/src/mac/blake2/blake2smac.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_BLAKE2SMAC
13
14 /**
15 Initialize an BLAKE2S MAC context.
16 @param st The BLAKE2S 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 blake2smac_init(blake2smac_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 blake2s_init(st, outlen, key, keylen);
27 }
28
29 /**
30 Process data through BLAKE2S MAC
31 @param st The BLAKE2S 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 blake2smac_process(blake2smac_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 blake2s_process(st, in, inlen);
42 }
43
44 /**
45 Terminate a BLAKE2S MAC session
46 @param st The BLAKE2S MAC state
47 @param mac [out] The destination of the BLAKE2S MAC authentication tag
48 @param maclen [in/out] The max size and resulting size of the BLAKE2S MAC authentication tag
49 @return CRYPT_OK if successful
50 */
51 int blake2smac_done(blake2smac_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->blake2s.outlen);
57
58 *maclen = st->blake2s.outlen;
59 return blake2s_done(st, mac);
60 }
61
62 #endif
63
64 /* ref: $Format:%D$ */
65 /* git commit: $Format:%H$ */
66 /* commit time: $Format:%ai$ */