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
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
15
HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
20
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
23
Terminate an HMAC session
24
@param hmac The HMAC state
25
@param out [out] The destination of the HMAC authentication tag
26
@param outlen [in/out] The max size and resulting size of the HMAC authentication tag
27
@return CRYPT_OK if successful
29
int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
31
unsigned char *buf, *isha;
32
unsigned long hashsize, i;
35
LTC_ARGCHK(hmac != NULL);
36
LTC_ARGCHK(out != NULL);
40
if((err = hash_is_valid(hash)) != CRYPT_OK) {
44
/* get the hash message digest size */
45
hashsize = hash_descriptor[hash].hashsize;
47
/* allocate buffers */
48
buf = XMALLOC(HMAC_BLOCKSIZE);
49
isha = XMALLOC(hashsize);
50
if (buf == NULL || isha == NULL) {
60
/* Get the hash of the first HMAC vector plus the data */
61
if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
65
/* Create the second HMAC vector vector for step (3) */
66
for(i=0; i < HMAC_BLOCKSIZE; i++) {
67
buf[i] = hmac->key[i] ^ 0x5C;
70
/* Now calculate the "outer" hash for step (5), (6), and (7) */
71
if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
74
if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
77
if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) {
80
if ((err = hash_descriptor[hash].done(&hmac->md, buf)) != CRYPT_OK) {
85
for (i = 0; i < hashsize && i < *outlen; i++) {
93
#ifdef LTC_CLEAN_STACK
94
zeromem(isha, hashsize);
95
zeromem(buf, hashsize);
96
zeromem(hmac, sizeof(*hmac));
107
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_done.c,v $ */
108
/* $Revision: 1.3 $ */
109
/* $Date: 2005/05/05 14:35:58 $ */