DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
hmac.c File Reference
#include "darkplaces.h"
#include "hmac.h"
+ Include dependency graph for hmac.c:

Go to the source code of this file.

Functions

qbool hmac (hashfunc_t hfunc, int hlen, int hblock, unsigned char *out, const unsigned char *in, int n, const unsigned char *key, int k)
 

Function Documentation

◆ hmac()

qbool hmac ( hashfunc_t hfunc,
int hlen,
int hblock,
unsigned char * out,
const unsigned char * in,
int n,
const unsigned char * key,
int k )

Definition at line 4 of file hmac.c.

10{
11 unsigned char hashbuf[32];
12 unsigned char k_xor_ipad[128];
13 unsigned char k_xor_opad[128];
14 unsigned char *catbuf;
15 int i;
16
17 if(sizeof(hashbuf) < (size_t) hlen)
18 return false;
19 if(sizeof(k_xor_ipad) < (size_t) hblock)
20 return false;
21 if(sizeof(k_xor_ipad) < (size_t) hlen)
22 return false;
23
24 catbuf = (unsigned char *)Mem_Alloc(tempmempool, (size_t) hblock + max((size_t) hlen, (size_t) n));
25
26 if(k > hblock)
27 {
28 // hash the key if it is too long
29 hfunc(k_xor_opad, key, k);
30 key = k_xor_opad;
31 k = hlen;
32 }
33
34 if(k < hblock)
35 {
36 // zero pad the key if it is too short
37 if(key != k_xor_opad)
38 memcpy(k_xor_opad, key, k);
39 for(i = k; i < hblock; ++i)
40 k_xor_opad[i] = 0;
41 key = k_xor_opad;
42 k = hblock;
43 }
44
45 for(i = 0; i < hblock; ++i)
46 {
47 k_xor_ipad[i] = key[i] ^ 0x36;
48 k_xor_opad[i] = key[i] ^ 0x5c;
49 }
50
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);
57
58 Mem_Free(catbuf);
59
60 return true;
61}
#define n(x, y)
#define max(A, B)
Definition mathlib.h:38
int i
mempool_t * tempmempool
Definition zone.c:794
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92

References i, max, Mem_Alloc, Mem_Free, n, and tempmempool.