OpenVAS Scanner  22.7.9
hmacmd5.c
Go to the documentation of this file.
1 /* SPDX-FileCopyrightText: 2023 Greenbone AG
2  * SPDX-FileCopyrightText: 1996-2000 Luke Kenneth Casson Leighton
3  * SPDX-FileCopyrightText: 1992-2000 Andrew Tridgell
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7 
16 #include "hmacmd5.h"
17 
18 #include <string.h> /* for memset */
19 
23 void
24 hmac_md5_init_limK_to_64 (const uchar *key, int key_len, HMACMD5Context *ctx)
25 {
26  int i;
27 
28  /* if key is longer than 64 bytes truncate it */
29  if (key_len > 64)
30  {
31  key_len = 64;
32  }
33 
34  /* start out by storing key in pads */
35  ZERO_STRUCT (ctx->k_ipad);
36  ZERO_STRUCT (ctx->k_opad);
37  memcpy (ctx->k_ipad, key, key_len);
38  memcpy (ctx->k_opad, key, key_len);
39 
40  /* XOR key with ipad and opad values */
41  for (i = 0; i < 64; i++)
42  {
43  ctx->k_ipad[i] ^= 0x36;
44  ctx->k_opad[i] ^= 0x5c;
45  }
46 
47  MD5Init (&ctx->ctx);
48  MD5Update (&ctx->ctx, ctx->k_ipad, 64);
49 }
50 
54 void
55 hmac_md5_update (const uchar *text, int text_len, HMACMD5Context *ctx)
56 {
57  MD5Update (&ctx->ctx, text, text_len); /* then text of datagram */
58 }
59 
63 void
65 
66 {
67  struct MD5Context ctx_o;
68 
69  MD5Final (digest, &ctx->ctx);
70 
71  MD5Init (&ctx_o);
72  MD5Update (&ctx_o, ctx->k_opad, 64);
73  MD5Update (&ctx_o, digest, 16);
74  MD5Final (digest, &ctx_o);
75 }
76 
81 void
82 hmac_md5 (uchar key[16], uchar *data, int data_len, uchar *digest)
83 {
84  HMACMD5Context ctx;
85  hmac_md5_init_limK_to_64 (key, 16, &ctx);
86  if (data_len != 0)
87  {
88  hmac_md5_update (data, data_len, &ctx);
89  }
90  hmac_md5_final (digest, &ctx);
91 }
HMACMD5Context
Definition: hmacmd5.h:29
ZERO_STRUCT
#define ZERO_STRUCT(x)
Definition: genrand.c:56
uchar
#define uchar
Definition: hmacmd5.h:22
HMACMD5Context::k_ipad
uchar k_ipad[65]
Definition: hmacmd5.h:31
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:24
MD5Update
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition: md5.c:71
hmac_md5_update
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition: hmacmd5.c:55
HMACMD5Context::k_opad
uchar k_opad[65]
Definition: hmacmd5.h:32
hmacmd5.h
Unix SMB/CIFS implementation. HMAC MD5 code for use in NTLMv2.
hmac_md5_final
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition: hmacmd5.c:64
MD5Init
void MD5Init(struct MD5Context *ctx)
Definition: md5.c:55
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...
Definition: hmacmd5.c:82
MD5Context
Definition: md5.h:52
MD5Final
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
Definition: md5.c:123
HMACMD5Context::ctx
struct MD5Context ctx
Definition: hmacmd5.h:30