5 hashfunc_t hfunc, int hlen, int hblock,
7 unsigned char *in, int n,
8 unsigned char *key, int k
11 static unsigned char hashbuf[32];
12 static unsigned char k_xor_ipad[128];
13 static unsigned char k_xor_opad[128];
14 static unsigned char catbuf[4096];
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)
23 if(sizeof(catbuf) < (size_t) hblock + (size_t) hlen)
25 if(sizeof(catbuf) < (size_t) hblock + (size_t) n)
30 // hash the key if it is too long
31 hfunc(k_xor_opad, key, k);
38 // zero pad the key if it is too short
40 memcpy(k_xor_opad, key, k);
41 for(i = k; i < hblock; ++i)
47 for(i = 0; i < hblock; ++i)
49 k_xor_ipad[i] = key[i] ^ 0x36;
50 k_xor_opad[i] = key[i] ^ 0x5c;
53 memcpy(catbuf, k_xor_ipad, hblock);
54 memcpy(catbuf + hblock, in, n);
55 hfunc(hashbuf, catbuf, hblock + n);
56 memcpy(catbuf, k_xor_opad, hblock);
57 memcpy(catbuf + hblock, hashbuf, hlen);
58 hfunc(out, catbuf, hblock + hlen);