3
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
|
2 * |
|
3 * LibTomCrypt is a library that provides various cryptographic |
|
4 * algorithms in a highly modular and flexible manner. |
|
5 * |
|
6 * The library is free for all purposes without any express |
|
7 * guarantee it works. |
|
8 * |
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
|
10 */ |
|
11 /* Submited by Dobes Vandermeer ([email protected]) */ |
|
12 |
|
13 #include "mycrypt.h" |
|
14 |
|
15 #ifdef HMAC |
|
16 |
|
17 int hmac_memory(int hash, const unsigned char *key, unsigned long keylen, |
|
18 const unsigned char *data, unsigned long len, |
|
19 unsigned char *dst, unsigned long *dstlen) |
|
20 { |
143
|
21 hmac_state *hmac; |
3
|
22 int err; |
|
23 |
|
24 _ARGCHK(key != NULL); |
|
25 _ARGCHK(data != NULL); |
|
26 _ARGCHK(dst != NULL); |
|
27 _ARGCHK(dstlen != NULL); |
143
|
28 |
|
29 /* allocate ram for hmac state */ |
|
30 hmac = XMALLOC(sizeof(hmac_state)); |
|
31 if (hmac == NULL) { |
|
32 return CRYPT_MEM; |
3
|
33 } |
|
34 |
143
|
35 if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) { |
|
36 goto __ERR; |
3
|
37 } |
|
38 |
143
|
39 if ((err = hmac_process(hmac, data, len)) != CRYPT_OK) { |
|
40 goto __ERR; |
|
41 } |
|
42 |
|
43 if ((err = hmac_done(hmac, dst, dstlen)) != CRYPT_OK) { |
|
44 goto __ERR; |
3
|
45 } |
|
46 |
143
|
47 err = CRYPT_OK; |
|
48 __ERR: |
|
49 #ifdef CLEAN_STACK |
|
50 zeromem(hmac, sizeof(hmac_state)); |
|
51 #endif |
|
52 |
|
53 XFREE(hmac); |
|
54 return err; |
3
|
55 } |
|
56 |
|
57 #endif |
|
58 |