]> Pileus Git - ~andy/crypt/blob - hmac.c
Add some initial code
[~andy/crypt] / hmac.c
1 /* HMAC */
2 static void hmac_gen(hash_t hash, int iter,
3                 const char *out,  int nout,
4                 const char *msg,  int nmsg,
5                 const char *pass, int npass,
6                 const char *salt, int nsalt);
7 {
8         // iter - ??
9
10         uint8_t *opad = alloc0(nout);
11         uint8_t *ipad = alloc0(nout);
12         uint8_t *buf  = alloc0(nout);
13         uint8_t *tmp1 = alloc0(nout+nmsg);
14         uint8_t *tmp2 = alloc0(nout+2);
15
16         if (npass > nout)
17                 hash(buf, key);
18         else if (npass < nout)
19                 memcpy(buf, key, npass);
20
21         for (int i = 0; i < nout; i++) {
22                 opad[i] = 0x5c ^ key[i];
23                 ipad[i] = 0x36 ^ key[i];
24         }
25
26         memcpy(tmp1, ipad, message);
27         hash(tmp, ipad + message);
28         hash(out, opad + tmp)
29 }