comparison libtomcrypt/src/mac/blake2/blake2smac_memory_multi.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 #include <stdarg.h>
12
13 #ifdef LTC_BLAKE2SMAC
14
15 /**
16 BLAKE2S MAC multiple blocks 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 mac [out] Destination of the authentication tag
20 @param maclen [in/out] Max size and resulting size of authentication tag
21 @param in The data to BLAKE2S MAC
22 @param inlen The length of the data to BLAKE2S MAC (octets)
23 @param ... tuples of (data,len) pairs to BLAKE2S MAC, terminated with a (NULL,x) (x=don't care)
24 @return CRYPT_OK if successful
25 */
26 int blake2smac_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...)
27 {
28 blake2smac_state st;
29 int err;
30 va_list args;
31 const unsigned char *curptr;
32 unsigned long curlen;
33
34 LTC_ARGCHK(key != NULL);
35 LTC_ARGCHK(in != NULL);
36 LTC_ARGCHK(mac != NULL);
37 LTC_ARGCHK(maclen != NULL);
38
39 va_start(args, inlen);
40 curptr = in;
41 curlen = inlen;
42 if ((err = blake2smac_init(&st, *maclen, key, keylen)) != CRYPT_OK) { goto LBL_ERR; }
43 for (;;) {
44 if ((err = blake2smac_process(&st, curptr, curlen)) != CRYPT_OK) { goto LBL_ERR; }
45 curptr = va_arg(args, const unsigned char*);
46 if (curptr == NULL) break;
47 curlen = va_arg(args, unsigned long);
48 }
49 err = blake2smac_done(&st, mac, maclen);
50 LBL_ERR:
51 #ifdef LTC_CLEAN_STACK
52 zeromem(&st, sizeof(blake2smac_state));
53 #endif
54 va_end(args);
55 return err;
56 }
57
58 #endif
59
60 /* ref: $Format:%D$ */
61 /* git commit: $Format:%H$ */
62 /* commit time: $Format:%ai$ */