OpenVAS Libraries  9.0.3
hmacmd5.h File Reference
#include "md5.h"
Include dependency graph for hmacmd5.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  HMACMD5Context
 

Macros

#define uchar   unsigned char
 
#define ZERO_STRUCT(x)   memset((char *)&(x), 0, sizeof(x))
 
#define SAFE_FREE(x)   do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
 
#define uint16   unsigned short
 
#define UCS2_SHIFT   0
 
#define UCS2_CHAR(c)   ((c) << UCS2_SHIFT)
 

Typedefs

typedef uint16 smb_ucs2_t
 

Functions

void hmac_md5_init_limK_to_64 (const uchar *key, int key_len, HMACMD5Context *ctx)
 The microsoft version of hmac_md5 initialisation. More...
 
void hmac_md5_update (const uchar *text, int text_len, HMACMD5Context *ctx)
 Update hmac_md5 "inner" buffer. More...
 
void hmac_md5_final (uchar *digest, HMACMD5Context *ctx)
 Finish off hmac_md5 "inner" buffer and generate outer one. More...
 
void hmac_md5 (uchar key[16], uchar *data, int data_len, uchar *digest)
 Function to calculate an HMAC MD5 digest from data. Use the microsoft hmacmd5 init method because the key is 16 bytes. More...
 

Macro Definition Documentation

◆ SAFE_FREE

#define SAFE_FREE (   x)    do { if ((x) != NULL) {free(x); x=NULL;} } while(0)

Free memory if the pointer and zero the pointer.

Note
You are explicitly allowed to pass NULL pointers – they will always be ignored.

Definition at line 49 of file hmacmd5.h.

◆ uchar

#define uchar   unsigned char

Definition at line 28 of file hmacmd5.h.

◆ UCS2_CHAR

#define UCS2_CHAR (   c)    ((c) << UCS2_SHIFT)

Definition at line 77 of file hmacmd5.h.

◆ UCS2_SHIFT

#define UCS2_SHIFT   0

Definition at line 73 of file hmacmd5.h.

◆ uint16

#define uint16   unsigned short

Definition at line 61 of file hmacmd5.h.

◆ ZERO_STRUCT

#define ZERO_STRUCT (   x)    memset((char *)&(x), 0, sizeof(x))

Definition at line 32 of file hmacmd5.h.

Typedef Documentation

◆ smb_ucs2_t

typedef uint16 smb_ucs2_t

Definition at line 68 of file hmacmd5.h.

Function Documentation

◆ hmac_md5()

void hmac_md5 ( uchar  key[16],
uchar data,
int  data_len,
uchar digest 
)

Function to calculate an HMAC MD5 digest from data. Use the microsoft hmacmd5 init method because the key is 16 bytes.

Definition at line 88 of file hmacmd5.c.

89 {
90  HMACMD5Context ctx;
91  hmac_md5_init_limK_to_64(key, 16, &ctx);
92  if (data_len != 0)
93  {
94  hmac_md5_update(data, data_len, &ctx);
95  }
96  hmac_md5_final(digest, &ctx);
97 }
void hmac_md5_init_limK_to_64(const uchar *key, int key_len, HMACMD5Context *ctx)
The microsoft version of hmac_md5 initialisation.
Definition: hmacmd5.c:33
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:71
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:63

References hmac_md5_final(), hmac_md5_init_limK_to_64(), and hmac_md5_update().

Referenced by ntlmssp_genauth_ntlm2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hmac_md5_final()

void hmac_md5_final ( uchar digest,
HMACMD5Context ctx 
)

Finish off hmac_md5 "inner" buffer and generate outer one.

Definition at line 71 of file hmacmd5.c.

73 {
74  struct MD5Context ctx_o;
75 
76  MD5Final(digest, &ctx->ctx);
77 
78  MD5Init(&ctx_o);
79  MD5Update(&ctx_o, ctx->k_opad, 64);
80  MD5Update(&ctx_o, digest, 16);
81  MD5Final(digest, &ctx_o);
82 }
struct MD5Context ctx
Definition: hmacmd5.h:36
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
Definition: md5.c:107
void MD5Init(struct MD5Context *ctx)
Definition: md5.c:44
Definition: md5.h:46
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition: md5.c:59
uchar k_opad[65]
Definition: hmacmd5.h:38

References HMACMD5Context::ctx, HMACMD5Context::k_opad, MD5Final(), MD5Init(), and MD5Update().

Referenced by hmac_md5(), nasl_ntv2_owf_gen(), SMBOWFencrypt_ntv2_ntlmssp(), and SMBsesskeygen_ntv2_ntlmssp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hmac_md5_init_limK_to_64()

void hmac_md5_init_limK_to_64 ( const uchar key,
int  key_len,
HMACMD5Context ctx 
)

The microsoft version of hmac_md5 initialisation.

Definition at line 33 of file hmacmd5.c.

35 {
36  int i;
37 
38  /* if key is longer than 64 bytes truncate it */
39  if (key_len > 64)
40  {
41  key_len = 64;
42  }
43 
44  /* start out by storing key in pads */
45  ZERO_STRUCT(ctx->k_ipad);
46  ZERO_STRUCT(ctx->k_opad);
47  memcpy( ctx->k_ipad, key, key_len);
48  memcpy( ctx->k_opad, key, key_len);
49 
50  /* XOR key with ipad and opad values */
51  for (i=0; i<64; i++) {
52  ctx->k_ipad[i] ^= 0x36;
53  ctx->k_opad[i] ^= 0x5c;
54  }
55 
56  MD5Init(&ctx->ctx);
57  MD5Update(&ctx->ctx, ctx->k_ipad, 64);
58 }
uchar k_ipad[65]
Definition: hmacmd5.h:37
struct MD5Context ctx
Definition: hmacmd5.h:36
void MD5Init(struct MD5Context *ctx)
Definition: md5.c:44
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition: md5.c:59
#define ZERO_STRUCT(x)
Definition: genrand.c:65
uchar k_opad[65]
Definition: hmacmd5.h:38

References HMACMD5Context::ctx, HMACMD5Context::k_ipad, HMACMD5Context::k_opad, MD5Init(), MD5Update(), and ZERO_STRUCT.

Referenced by hmac_md5(), nasl_ntv2_owf_gen(), SMBOWFencrypt_ntv2_ntlmssp(), and SMBsesskeygen_ntv2_ntlmssp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hmac_md5_update()

void hmac_md5_update ( const uchar text,
int  text_len,
HMACMD5Context ctx 
)

Update hmac_md5 "inner" buffer.

Definition at line 63 of file hmacmd5.c.

64 {
65  MD5Update(&ctx->ctx, text, text_len); /* then text of datagram */
66 }
struct MD5Context ctx
Definition: hmacmd5.h:36
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition: md5.c:59

References HMACMD5Context::ctx, and MD5Update().

Referenced by hmac_md5(), nasl_ntv2_owf_gen(), SMBOWFencrypt_ntv2_ntlmssp(), and SMBsesskeygen_ntv2_ntlmssp().

Here is the call graph for this function:
Here is the caller graph for this function: