1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 @file hmac_memory_multi.c
14 HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer
20 HMAC multiple blocks of memory to produce the authentication tag
21 @param hash The index of the hash to use
22 @param key The secret key
23 @param keylen The length of the secret key (octets)
24 @param out [out] Destination of the authentication tag
25 @param outlen [in/out] Max size and resulting size of authentication tag
26 @param in The data to HMAC
27 @param inlen The length of the data to HMAC (octets)
28 @param ... tuples of (data,len) pairs to HMAC, terminated with a (NULL,x) (x=don't care)
29 @return CRYPT_OK if successful
31 int hmac_memory_multi(int hash,
32 const unsigned char *key, unsigned long keylen,
33 unsigned char *out, unsigned long *outlen,
34 const unsigned char *in, unsigned long inlen, ...)
40 const unsigned char *curptr;
43 LTC_ARGCHK(key != NULL);
44 LTC_ARGCHK(in != NULL);
45 LTC_ARGCHK(out != NULL);
46 LTC_ARGCHK(outlen != NULL);
48 /* allocate ram for hmac state */
49 hmac = XMALLOC(sizeof(hmac_state));
54 if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) {
58 va_start(args, inlen);
63 if ((err = hmac_process(hmac, curptr, curlen)) != CRYPT_OK) {
67 curptr = va_arg(args, const unsigned char*);
71 curlen = va_arg(args, unsigned long);
73 if ((err = hmac_done(hmac, out, outlen)) != CRYPT_OK) {
77 #ifdef LTC_CLEAN_STACK
78 zeromem(hmac, sizeof(hmac_state));
88 /* ref: $Format:%D$ */
89 /* git commit: $Format:%H$ */
90 /* commit time: $Format:%ai$ */