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, process a file, Tom St Denis/Dobes Vandermeer
22
@param hash The index of the hash you wish to use
23
@param fname The name of the file you wish to HMAC
24
@param key The secret key
25
@param keylen The length of the secret key
26
@param out [out] The HMAC authentication tag
27
@param outlen [in/out] The max size and resulting size of the authentication tag
28
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
30
int hmac_file(int hash, const char *fname,
31
const unsigned char *key, unsigned long keylen,
32
unsigned char *out, unsigned long *outlen)
39
unsigned char buf[512];
43
LTC_ARGCHK(fname != NULL);
44
LTC_ARGCHK(key != NULL);
45
LTC_ARGCHK(out != NULL);
46
LTC_ARGCHK(outlen != NULL);
48
if((err = hash_is_valid(hash)) != CRYPT_OK) {
52
if ((err = hmac_init(&hmac, hash, key, keylen)) != CRYPT_OK) {
56
in = fopen(fname, "rb");
58
return CRYPT_FILE_NOTFOUND;
61
/* process the file contents */
63
x = fread(buf, 1, sizeof(buf), in);
64
if ((err = hmac_process(&hmac, buf, (unsigned long)x)) != CRYPT_OK) {
65
/* we don't trap this error since we're already returning an error! */
69
} while (x == sizeof(buf));
71
if (fclose(in) != 0) {
76
if ((err = hmac_done(&hmac, out, outlen)) != CRYPT_OK) {
80
#ifdef LTC_CLEAN_STACK
82
zeromem(buf, sizeof(buf));
91
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_file.c,v $ */
92
/* $Revision: 1.3 $ */
93
/* $Date: 2005/05/05 14:35:58 $ */