]> pd.if.org Git - zpackage/blob - libtomcrypt/src/mac/blake2/blake2bmac_memory_multi.c
commit files needed for zpm-fetchurl
[zpackage] / libtomcrypt / src / mac / blake2 / blake2bmac_memory_multi.c
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_BLAKE2BMAC
14
15 /**
16    BLAKE2B 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 BLAKE2B MAC
22    @param inlen     The length of the data to BLAKE2B MAC (octets)
23    @param ...       tuples of (data,len) pairs to BLAKE2B MAC, terminated with a (NULL,x) (x=don't care)
24    @return CRYPT_OK if successful
25 */
26 int blake2bmac_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in,  unsigned long inlen, ...)
27 {
28    blake2bmac_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 = blake2bmac_init(&st, *maclen, key, keylen)) != CRYPT_OK)          { goto LBL_ERR; }
43    for (;;) {
44       if ((err = blake2bmac_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 = blake2bmac_done(&st, mac, maclen);
50 LBL_ERR:
51 #ifdef LTC_CLEAN_STACK
52    zeromem(&st, sizeof(blake2bmac_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$ */