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@iahu.ca, http://libtomcrypt.org
11
/* Submited by Dobes Vandermeer (dobes@smartt.com) */
17
/* hmac_file added by Tom St Denis */
18
int hmac_file(int hash, const char *fname,
19
const unsigned char *key, unsigned long keylen,
20
unsigned char *dst, unsigned long *dstlen)
27
unsigned char buf[512];
31
_ARGCHK(fname != NULL);
34
_ARGCHK(dstlen != NULL);
36
if((err = hash_is_valid(hash)) != CRYPT_OK) {
40
if ((err = hmac_init(&hmac, hash, key, keylen)) != CRYPT_OK) {
44
in = fopen(fname, "rb");
46
return CRYPT_FILE_NOTFOUND;
49
/* process the file contents */
51
x = fread(buf, 1, sizeof(buf), in);
52
if ((err = hmac_process(&hmac, buf, (unsigned long)x)) != CRYPT_OK) {
53
/* we don't trap this error since we're already returning an error! */
57
} while (x == sizeof(buf));
59
if (fclose(in) != 0) {
64
if ((err = hmac_done(&hmac, dst, dstlen)) != CRYPT_OK) {
70
zeromem(buf, sizeof(buf));