OpenVAS Libraries  9.0.3
md5.c File Reference
#include <string.h>
#include "md5.h"
Include dependency graph for md5.c:

Go to the source code of this file.

Macros

#define F1(x, y, z)   (z ^ (x & (y ^ z)))
 
#define F2(x, y, z)   F1(z, x, y)
 
#define F3(x, y, z)   (x ^ y ^ z)
 
#define F4(x, y, z)   (y ^ (x | ~z))
 
#define MD5STEP(f, w, x, y, z, data, s)   ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
 

Functions

void MD5Init (struct MD5Context *ctx)
 
void MD5Update (struct MD5Context *ctx, unsigned char const *buf, unsigned len)
 
void MD5Final (unsigned char digest[16], struct MD5Context *ctx)
 

Macro Definition Documentation

◆ F1

#define F1 (   x,
  y,
 
)    (z ^ (x & (y ^ z)))

Definition at line 151 of file md5.c.

◆ F2

#define F2 (   x,
  y,
 
)    F1(z, x, y)

Definition at line 152 of file md5.c.

◆ F3

#define F3 (   x,
  y,
 
)    (x ^ y ^ z)

Definition at line 153 of file md5.c.

◆ F4

#define F4 (   x,
  y,
 
)    (y ^ (x | ~z))

Definition at line 154 of file md5.c.

◆ MD5STEP

#define MD5STEP (   f,
  w,
  x,
  y,
  z,
  data,
 
)    ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )

Definition at line 157 of file md5.c.

Function Documentation

◆ MD5Final()

void MD5Final ( unsigned char  digest[16],
struct MD5Context ctx 
)

Definition at line 107 of file md5.c.

108 {
109  unsigned int count;
110  unsigned char *p;
111 
112  /* Compute number of bytes mod 64 */
113  count = (ctx->bits[0] >> 3) & 0x3F;
114 
115  /* Set the first char of padding to 0x80. This is safe since there is
116  always at least one byte free */
117  p = ctx->in + count;
118  *p++ = 0x80;
119 
120  /* Bytes of padding needed to make 64 bytes */
121  count = 64 - 1 - count;
122 
123  /* Pad out to 56 mod 64 */
124  if (count < 8) {
125  /* Two lots of padding: Pad the first block to 64 bytes */
126  memset(p, 0, count);
127  byteReverse(ctx->in, 16);
128  MD5Transform(ctx->buf, (uint32 *) ctx->in);
129 
130  /* Now fill the next block with 56 bytes */
131  memset(ctx->in, 0, 56);
132  } else {
133  /* Pad block to 56 bytes */
134  memset(p, 0, count - 8);
135  }
136  byteReverse(ctx->in, 14);
137 
138  /* Append length in bits and transform */
139  ((uint32 *) ctx->in)[14] = ctx->bits[0];
140  ((uint32 *) ctx->in)[15] = ctx->bits[1];
141 
142  MD5Transform(ctx->buf, (uint32 *) ctx->in);
143  byteReverse((unsigned char *) ctx->buf, 4);
144  memmove(digest, ctx->buf, 16);
145  memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
146 }
#define uint32
Definition: genrand.c:49
unsigned char in[64]
Definition: md5.h:49
uint32 buf[4]
Definition: md5.h:47
uint32 bits[2]
Definition: md5.h:48

References MD5Context::bits, and MD5Context::in.

Referenced by hmac_md5_final(), ntlmssp_genauth_ntlm2(), and simple_packet_signature_ntlmssp().

Here is the caller graph for this function:

◆ MD5Init()

void MD5Init ( struct MD5Context ctx)

Definition at line 44 of file md5.c.

45 {
46  ctx->buf[0] = 0x67452301;
47  ctx->buf[1] = 0xefcdab89;
48  ctx->buf[2] = 0x98badcfe;
49  ctx->buf[3] = 0x10325476;
50 
51  ctx->bits[0] = 0;
52  ctx->bits[1] = 0;
53 }
uint32 buf[4]
Definition: md5.h:47
uint32 bits[2]
Definition: md5.h:48

References MD5Context::bits, and MD5Context::buf.

Referenced by hmac_md5_final(), hmac_md5_init_limK_to_64(), ntlmssp_genauth_ntlm2(), and simple_packet_signature_ntlmssp().

Here is the caller graph for this function:

◆ MD5Update()

void MD5Update ( struct MD5Context ctx,
unsigned char const *  buf,
unsigned  len 
)

Definition at line 59 of file md5.c.

60 {
61  register uint32 t;
62 
63  /* Update bitcount */
64 
65  t = ctx->bits[0];
66  if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
67  ctx->bits[1]++; /* Carry from low to high */
68  ctx->bits[1] += len >> 29;
69 
70  t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
71 
72  /* Handle any leading odd-sized chunks */
73 
74  if (t) {
75  unsigned char *p = (unsigned char *) ctx->in + t;
76 
77  t = 64 - t;
78  if (len < t) {
79  memmove(p, buf, len);
80  return;
81  }
82  memmove(p, buf, t);
83  byteReverse(ctx->in, 16);
84  MD5Transform(ctx->buf, (uint32 *) ctx->in);
85  buf += t;
86  len -= t;
87  }
88  /* Process data in 64-byte chunks */
89 
90  while (len >= 64) {
91  memmove(ctx->in, buf, 64);
92  byteReverse(ctx->in, 16);
93  MD5Transform(ctx->buf, (uint32 *) ctx->in);
94  buf += 64;
95  len -= 64;
96  }
97 
98  /* Handle any remaining bytes of data. */
99 
100  memmove(ctx->in, buf, len);
101 }
#define uint32
Definition: genrand.c:49
unsigned char in[64]
Definition: md5.h:49
uint32 buf[4]
Definition: md5.h:47
uint32 bits[2]
Definition: md5.h:48

References MD5Context::bits, MD5Context::in, and uint32.

Referenced by hmac_md5_final(), hmac_md5_init_limK_to_64(), hmac_md5_update(), ntlmssp_genauth_ntlm2(), and simple_packet_signature_ntlmssp().

Here is the caller graph for this function: