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 HMAC support, process a block of memory, Tom St Denis/Dobes Vandermeer
19 HMAC a block of memory to produce the authentication tag
20 @param hash The index of the hash to use
21 @param key The secret key
22 @param keylen The length of the secret key (octets)
23 @param in The data to HMAC
24 @param inlen The length of the data to HMAC (octets)
25 @param out [out] Destination of the authentication tag
26 @param outlen [in/out] Max size and resulting size of authentication tag
27 @return CRYPT_OK if successful
29 int hmac_memory(int hash,
30 const unsigned char *key, unsigned long keylen,
31 const unsigned char *in, unsigned long inlen,
32 unsigned char *out, unsigned long *outlen)
37 LTC_ARGCHK(key != NULL);
38 LTC_ARGCHK(in != NULL);
39 LTC_ARGCHK(out != NULL);
40 LTC_ARGCHK(outlen != NULL);
42 /* make sure hash descriptor is valid */
43 if ((err = hash_is_valid(hash)) != CRYPT_OK) {
47 /* is there a descriptor? */
48 if (hash_descriptor[hash].hmac_block != NULL) {
49 return hash_descriptor[hash].hmac_block(key, keylen, in, inlen, out, outlen);
52 /* nope, so call the hmac functions */
53 /* allocate ram for hmac state */
54 hmac = XMALLOC(sizeof(hmac_state));
59 if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) {
63 if ((err = hmac_process(hmac, in, inlen)) != CRYPT_OK) {
67 if ((err = hmac_done(hmac, out, outlen)) != CRYPT_OK) {
73 #ifdef LTC_CLEAN_STACK
74 zeromem(hmac, sizeof(hmac_state));
84 /* ref: $Format:%D$ */
85 /* git commit: $Format:%H$ */
86 /* commit time: $Format:%ai$ */