OpenVAS Scanner 23.32.3
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
15
16#include "hmacmd5.h"
17
18#include <string.h> /* for memset */
19
23void
24hmac_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
54void
55hmac_md5_update (const uchar *text, int text_len, HMACMD5Context *ctx)
56{
57 MD5Update (&ctx->ctx, text, text_len); /* then text of datagram */
58}
59
63void
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
81void
82hmac_md5 (uchar key[16], uchar *data, int data_len, uchar *digest)
83{
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}
#define ZERO_STRUCT(x)
Definition genrand.c:56
void hmac_md5_final(uchar *digest, HMACMD5Context *ctx)
Finish off hmac_md5 "inner" buffer and generate outer one.
Definition hmacmd5.c:64
void hmac_md5_update(const uchar *text, int text_len, HMACMD5Context *ctx)
Update hmac_md5 "inner" buffer.
Definition hmacmd5.c:55
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
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
Unix SMB/CIFS implementation. HMAC MD5 code for use in NTLMv2.
#define uchar
Definition hmacmd5.h:22
void MD5Init(struct MD5Context *ctx)
Definition md5.c:55
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
Definition md5.c:123
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
Definition md5.c:71
uchar k_ipad[65]
Definition hmacmd5.h:31
struct MD5Context ctx
Definition hmacmd5.h:30
uchar k_opad[65]
Definition hmacmd5.h:32