7 const unsigned char *in,
int n,
8 const unsigned char *key,
int k
11 unsigned char hashbuf[32];
12 unsigned char k_xor_ipad[128];
13 unsigned char k_xor_opad[128];
14 unsigned char *catbuf;
17 if(
sizeof(hashbuf) < (
size_t) hlen)
19 if(
sizeof(k_xor_ipad) < (
size_t) hblock)
21 if(
sizeof(k_xor_ipad) < (
size_t) hlen)
29 hfunc(k_xor_opad, key, k);
38 memcpy(k_xor_opad, key, k);
39 for(
i = k;
i < hblock; ++
i)
45 for(
i = 0;
i < hblock; ++
i)
47 k_xor_ipad[
i] = key[
i] ^ 0x36;
48 k_xor_opad[
i] = key[
i] ^ 0x5c;
51 memcpy(catbuf, k_xor_ipad, hblock);
52 memcpy(catbuf + hblock, in,
n);
53 hfunc(hashbuf, catbuf, hblock +
n);
54 memcpy(catbuf, k_xor_opad, hblock);
55 memcpy(catbuf + hblock, hashbuf, hlen);
56 hfunc(out, catbuf, hblock + hlen);
qbool hmac(hashfunc_t hfunc, int hlen, int hblock, unsigned char *out, const unsigned char *in, int n, const unsigned char *key, int k)