OpenVAS Scanner  7.0.0~git
hmacmd5.c File Reference

Unix SMB/CIFS implementation. HMAC MD5 code for use in NTLMv2. More...

#include "hmacmd5.h"
#include <string.h>
Include dependency graph for hmacmd5.c:

Go to the source code of this file.

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

Detailed Description

Unix SMB/CIFS implementation. HMAC MD5 code for use in NTLMv2.

taken direct from rfc2104 implementation and modified for suitable use for ntlmv2.

Definition in file hmacmd5.c.

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 95 of file hmacmd5.c.

96 {
97  HMACMD5Context ctx;
98  hmac_md5_init_limK_to_64 (key, 16, &ctx);
99  if (data_len != 0)
100  {
101  hmac_md5_update (data, data_len, &ctx);
102  }
103  hmac_md5_final (digest, &ctx);
104 }

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 77 of file hmacmd5.c.

79 {
80  struct MD5Context ctx_o;
81 
82  MD5Final (digest, &ctx->ctx);
83 
84  MD5Init (&ctx_o);
85  MD5Update (&ctx_o, ctx->k_opad, 64);
86  MD5Update (&ctx_o, digest, 16);
87  MD5Final (digest, &ctx_o);
88 }

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 37 of file hmacmd5.c.

38 {
39  int i;
40 
41  /* if key is longer than 64 bytes truncate it */
42  if (key_len > 64)
43  {
44  key_len = 64;
45  }
46 
47  /* start out by storing key in pads */
48  ZERO_STRUCT (ctx->k_ipad);
49  ZERO_STRUCT (ctx->k_opad);
50  memcpy (ctx->k_ipad, key, key_len);
51  memcpy (ctx->k_opad, key, key_len);
52 
53  /* XOR key with ipad and opad values */
54  for (i = 0; i < 64; i++)
55  {
56  ctx->k_ipad[i] ^= 0x36;
57  ctx->k_opad[i] ^= 0x5c;
58  }
59 
60  MD5Init (&ctx->ctx);
61  MD5Update (&ctx->ctx, ctx->k_ipad, 64);
62 }

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 68 of file hmacmd5.c.

69 {
70  MD5Update (&ctx->ctx, text, text_len); /* then text of datagram */
71 }

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:
HMACMD5Context
Definition: hmacmd5.h:41
ZERO_STRUCT
#define ZERO_STRUCT(x)
Definition: genrand.c:70
HMACMD5Context::k_ipad
uchar k_ipad[65]
Definition: hmacmd5.h:44
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: hmacmd5.c:37
MD5Update
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition: md5.c:66
hmac_md5_update
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:68
HMACMD5Context::k_opad
uchar k_opad[65]
Definition: hmacmd5.h:45
hmac_md5_final
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:77
MD5Init
void MD5Init(struct MD5Context *ctx)
Definition: md5.c:50
MD5Context
Definition: md5.h:46
MD5Final
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
Definition: md5.c:118
HMACMD5Context::ctx
struct MD5Context ctx
Definition: hmacmd5.h:43