DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
hmac.h File Reference
#include "qtypes.h"
+ Include dependency graph for hmac.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HMAC_MDFOUR_16BYTES(out, in, n, key, k)
 
#define HMAC_SHA256_32BYTES(out, in, n, key, k)
 

Typedefs

typedef void(* hashfunc_t) (unsigned char *out, const unsigned char *in, int n)
 

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)
 

Macro Definition Documentation

◆ HMAC_MDFOUR_16BYTES

#define HMAC_MDFOUR_16BYTES ( out,
in,
n,
key,
k )
Value:
hmac(mdfour, 16, 64, out, in, n, key, k)
#define n(x, y)
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 hmac.c:4
void mdfour(unsigned char *out, const unsigned char *in, int n)
Definition mdfour.c:182

Definition at line 14 of file hmac.h.

Referenced by CL_Rcon_f(), hmac_mdfour_challenge_matching(), hmac_mdfour_time_matching(), and NetConn_ClientParsePacket().

◆ HMAC_SHA256_32BYTES

#define HMAC_SHA256_32BYTES ( out,
in,
n,
key,
k )
Value:
hmac(sha256, 32, 64, out, in, n, key, k)
void sha256(unsigned char *out, const unsigned char *in, int n)
Definition crypto.c:383

Definition at line 15 of file hmac.h.

Referenced by Crypto_DecryptPacket(), and Crypto_EncryptPacket().

Typedef Documentation

◆ hashfunc_t

typedef void(* hashfunc_t) (unsigned char *out, const unsigned char *in, int n)

Definition at line 6 of file hmac.h.

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 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.