Mercurial > dropbear
comparison libtomcrypt/src/mac/hmac/hmac_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 | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 #include <stdarg.h> | 10 #include <stdarg.h> |
13 | 11 |
14 /** | 12 /** |
15 @file hmac_memory_multi.c | 13 @file hmac_memory_multi.c |
16 LTC_HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer | 14 HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer |
17 */ | 15 */ |
18 | 16 |
19 #ifdef LTC_HMAC | 17 #ifdef LTC_HMAC |
20 | 18 |
21 /** | 19 /** |
22 LTC_HMAC multiple blocks of memory to produce the authentication tag | 20 HMAC multiple blocks of memory to produce the authentication tag |
23 @param hash The index of the hash to use | 21 @param hash The index of the hash to use |
24 @param key The secret key | 22 @param key The secret key |
25 @param keylen The length of the secret key (octets) | 23 @param keylen The length of the secret key (octets) |
26 @param out [out] Destination of the authentication tag | 24 @param out [out] Destination of the authentication tag |
27 @param outlen [in/out] Max size and resulting size of authentication tag | 25 @param outlen [in/out] Max size and resulting size of authentication tag |
28 @param in The data to LTC_HMAC | 26 @param in The data to HMAC |
29 @param inlen The length of the data to LTC_HMAC (octets) | 27 @param inlen The length of the data to HMAC (octets) |
30 @param ... tuples of (data,len) pairs to LTC_HMAC, terminated with a (NULL,x) (x=don't care) | 28 @param ... tuples of (data,len) pairs to HMAC, terminated with a (NULL,x) (x=don't care) |
31 @return CRYPT_OK if successful | 29 @return CRYPT_OK if successful |
32 */ | 30 */ |
33 int hmac_memory_multi(int hash, | 31 int hmac_memory_multi(int hash, |
34 const unsigned char *key, unsigned long keylen, | 32 const unsigned char *key, unsigned long keylen, |
35 unsigned char *out, unsigned long *outlen, | 33 unsigned char *out, unsigned long *outlen, |
36 const unsigned char *in, unsigned long inlen, ...) | 34 const unsigned char *in, unsigned long inlen, ...) |
37 | 35 |
38 { | 36 { |
42 const unsigned char *curptr; | 40 const unsigned char *curptr; |
43 unsigned long curlen; | 41 unsigned long curlen; |
44 | 42 |
45 LTC_ARGCHK(key != NULL); | 43 LTC_ARGCHK(key != NULL); |
46 LTC_ARGCHK(in != NULL); | 44 LTC_ARGCHK(in != NULL); |
47 LTC_ARGCHK(out != NULL); | 45 LTC_ARGCHK(out != NULL); |
48 LTC_ARGCHK(outlen != NULL); | 46 LTC_ARGCHK(outlen != NULL); |
49 | 47 |
50 /* allocate ram for hmac state */ | 48 /* allocate ram for hmac state */ |
51 hmac = XMALLOC(sizeof(hmac_state)); | 49 hmac = XMALLOC(sizeof(hmac_state)); |
52 if (hmac == NULL) { | 50 if (hmac == NULL) { |
56 if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) { | 54 if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) { |
57 goto LBL_ERR; | 55 goto LBL_ERR; |
58 } | 56 } |
59 | 57 |
60 va_start(args, inlen); | 58 va_start(args, inlen); |
61 curptr = in; | 59 curptr = in; |
62 curlen = inlen; | 60 curlen = inlen; |
63 for (;;) { | 61 for (;;) { |
64 /* process buf */ | 62 /* process buf */ |
65 if ((err = hmac_process(hmac, curptr, curlen)) != CRYPT_OK) { | 63 if ((err = hmac_process(hmac, curptr, curlen)) != CRYPT_OK) { |
66 goto LBL_ERR; | 64 goto LBL_ERR; |
79 #ifdef LTC_CLEAN_STACK | 77 #ifdef LTC_CLEAN_STACK |
80 zeromem(hmac, sizeof(hmac_state)); | 78 zeromem(hmac, sizeof(hmac_state)); |
81 #endif | 79 #endif |
82 XFREE(hmac); | 80 XFREE(hmac); |
83 va_end(args); | 81 va_end(args); |
84 return err; | 82 return err; |
85 } | 83 } |
86 | 84 |
87 #endif | 85 #endif |
88 | 86 |
89 | 87 |
90 /* $Source$ */ | 88 /* ref: $Format:%D$ */ |
91 /* $Revision$ */ | 89 /* git commit: $Format:%H$ */ |
92 /* $Date$ */ | 90 /* commit time: $Format:%ai$ */ |