Rizin
unix-like reverse engineering framework and cli tools
md4.c File Reference
#include "md4.h"
#include <rz_types.h>
#include <rz_endian.h>
#include <rz_util.h>

Go to the source code of this file.

Macros

#define XAX(x, y, z)   (z ^ (x & (y ^ z)))
 
#define AAA(x, y, z)   ((x & y) | (x & z) | (y & z))
 
#define XXX(x, y, z)   (x ^ y ^ z)
 
#define md4_round(m, w, x, y, z, v, s)
 

Functions

void rz_md4_init (RzMD4 *context)
 
static ut32 rotate_left_32 (ut32 value, ut32 rot)
 
static void md4_digest_block (RzMD4 *context)
 
bool rz_md4_update (RzMD4 *context, const ut8 *data, ut64 length)
 
void md4_padding (RzMD4 *context)
 
void rz_md4_fini (ut8 *hash, RzMD4 *context)
 

Macro Definition Documentation

◆ AAA

#define AAA (   x,
  y,
 
)    ((x & y) | (x & z) | (y & z))

Definition at line 10 of file md4.c.

◆ md4_round

#define md4_round (   m,
  w,
  x,
  y,
  z,
  v,
  s 
)
Value:
w += m(x, y, z) + v; \
#define w
Definition: crypto_rc6.c:13
const char * v
Definition: dsignal.c:12
static ut32 rotate_left_32(ut32 value, ut32 rot)
Definition: md4.c:29
int x
Definition: mipsasm.c:20
static RzSocket * s
Definition: rtr.c:28

Definition at line 13 of file md4.c.

◆ XAX

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

Definition at line 9 of file md4.c.

◆ XXX

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

Definition at line 11 of file md4.c.

Function Documentation

◆ md4_digest_block()

static void md4_digest_block ( RzMD4 context)
static

Definition at line 33 of file md4.c.

33  {
34  // printb(context->block, 64);
35 
36  ut32 W[16];
37  ut32 A = context->digest[0];
38  ut32 B = context->digest[1];
39  ut32 C = context->digest[2];
40  ut32 D = context->digest[3];
41 
42  for (ut32 t = 0; t < 16; ++t) {
43  W[t] = rz_read_at_le32(context->block, t * 4);
44  }
45 
46  md4_round(XAX, A, B, C, D, W[/* */ 0], 3);
47  md4_round(XAX, D, A, B, C, W[/* */ 1], 7);
48  md4_round(XAX, C, D, A, B, W[/* */ 2], 11);
49  md4_round(XAX, B, C, D, A, W[/* */ 3], 19);
50  md4_round(XAX, A, B, C, D, W[/* */ 4], 3);
51  md4_round(XAX, D, A, B, C, W[/* */ 5], 7);
52  md4_round(XAX, C, D, A, B, W[/* */ 6], 11);
53  md4_round(XAX, B, C, D, A, W[/* */ 7], 19);
54  md4_round(XAX, A, B, C, D, W[/* */ 8], 3);
55  md4_round(XAX, D, A, B, C, W[/* */ 9], 7);
56  md4_round(XAX, C, D, A, B, W[ 10], 11);
57  md4_round(XAX, B, C, D, A, W[ 11], 19);
58  md4_round(XAX, A, B, C, D, W[ 12], 3);
59  md4_round(XAX, D, A, B, C, W[ 13], 7);
60  md4_round(XAX, C, D, A, B, W[ 14], 11);
61  md4_round(XAX, B, C, D, A, W[ 15], 19);
62 
63  md4_round(AAA, A, B, C, D, W[/* */ 0] + 0x5A827999, 3);
64  md4_round(AAA, D, A, B, C, W[/* */ 4] + 0x5A827999, 5);
65  md4_round(AAA, C, D, A, B, W[/* */ 8] + 0x5A827999, 9);
66  md4_round(AAA, B, C, D, A, W[ 12] + 0x5A827999, 13);
67  md4_round(AAA, A, B, C, D, W[/* */ 1] + 0x5A827999, 3);
68  md4_round(AAA, D, A, B, C, W[/* */ 5] + 0x5A827999, 5);
69  md4_round(AAA, C, D, A, B, W[/* */ 9] + 0x5A827999, 9);
70  md4_round(AAA, B, C, D, A, W[ 13] + 0x5A827999, 13);
71  md4_round(AAA, A, B, C, D, W[/* */ 2] + 0x5A827999, 3);
72  md4_round(AAA, D, A, B, C, W[/* */ 6] + 0x5A827999, 5);
73  md4_round(AAA, C, D, A, B, W[ 10] + 0x5A827999, 9);
74  md4_round(AAA, B, C, D, A, W[ 14] + 0x5A827999, 13);
75  md4_round(AAA, A, B, C, D, W[/* */ 3] + 0x5A827999, 3);
76  md4_round(AAA, D, A, B, C, W[/* */ 7] + 0x5A827999, 5);
77  md4_round(AAA, C, D, A, B, W[ 11] + 0x5A827999, 9);
78  md4_round(AAA, B, C, D, A, W[ 15] + 0x5A827999, 13);
79 
80  md4_round(XXX, A, B, C, D, W[/* */ 0] + 0x6ED9EBA1, 3);
81  md4_round(XXX, D, A, B, C, W[/* */ 8] + 0x6ED9EBA1, 9);
82  md4_round(XXX, C, D, A, B, W[/* */ 4] + 0x6ED9EBA1, 11);
83  md4_round(XXX, B, C, D, A, W[ 12] + 0x6ED9EBA1, 15);
84  md4_round(XXX, A, B, C, D, W[/* */ 2] + 0x6ED9EBA1, 3);
85  md4_round(XXX, D, A, B, C, W[ 10] + 0x6ED9EBA1, 9);
86  md4_round(XXX, C, D, A, B, W[/* */ 6] + 0x6ED9EBA1, 11);
87  md4_round(XXX, B, C, D, A, W[ 14] + 0x6ED9EBA1, 15);
88  md4_round(XXX, A, B, C, D, W[/* */ 1] + 0x6ED9EBA1, 3);
89  md4_round(XXX, D, A, B, C, W[/* */ 9] + 0x6ED9EBA1, 9);
90  md4_round(XXX, C, D, A, B, W[/* */ 5] + 0x6ED9EBA1, 11);
91  md4_round(XXX, B, C, D, A, W[ 13] + 0x6ED9EBA1, 15);
92  md4_round(XXX, A, B, C, D, W[/* */ 3] + 0x6ED9EBA1, 3);
93  md4_round(XXX, D, A, B, C, W[ 11] + 0x6ED9EBA1, 9);
94  md4_round(XXX, C, D, A, B, W[/* */ 7] + 0x6ED9EBA1, 11);
95  md4_round(XXX, B, C, D, A, W[ 15] + 0x6ED9EBA1, 15);
96 
97  context->digest[0] += A;
98  context->digest[1] += B;
99  context->digest[2] += C;
100  context->digest[3] += D;
101 
102  context->index = 0;
103 }
#define A(x)
Definition: arc.h:165
#define B(x)
Definition: arc.h:166
#define C(x)
Definition: arc.h:167
#define W(x, y, z)
#define D
Definition: block.c:38
uint32_t ut32
#define md4_round(m, w, x, y, z, v, s)
Definition: md4.c:13
#define XXX(x, y, z)
Definition: md4.c:11
#define XAX(x, y, z)
Definition: md4.c:9
#define AAA(x, y, z)
Definition: md4.c:10
static ut32 rz_read_at_le32(const void *src, size_t offset)
Definition: rz_endian.h:248

References A, AAA, B, C, D, md4_round, rz_read_at_le32(), W, XAX, and XXX.

Referenced by md4_padding(), and rz_md4_update().

◆ md4_padding()

void md4_padding ( RzMD4 context)

Definition at line 129 of file md4.c.

129  {
130  if (context->index > 55) {
131  context->block[context->index++] = 0x80;
132  for (; context->index < RZ_HASH_MD4_BLOCK_LENGTH;) {
133  context->block[context->index++] = 0;
134  }
135 
137 
138  for (; context->index < 56;) {
139  context->block[context->index++] = 0;
140  }
141  } else {
142  context->block[context->index++] = 0x80;
143  for (; context->index < 56;) {
144  context->block[context->index++] = 0;
145  }
146  }
147 
148  rz_write_le32(&context->block[56], context->len_low);
149  rz_write_le32(&context->block[60], context->len_high);
150 
152 }
static void md4_digest_block(RzMD4 *context)
Definition: md4.c:33
#define RZ_HASH_MD4_BLOCK_LENGTH
Definition: md4.h:10
static void rz_write_le32(void *dest, ut32 val)
Definition: rz_endian.h:256

References md4_digest_block(), RZ_HASH_MD4_BLOCK_LENGTH, and rz_write_le32().

Referenced by rz_md4_fini().

◆ rotate_left_32()

static ut32 rotate_left_32 ( ut32  value,
ut32  rot 
)
inlinestatic

Definition at line 29 of file md4.c.

29  {
30  return ((((value) << (rot)) & 0xFFFFFFFF) | ((value) >> (32 - (rot))));
31 }
static int value
Definition: cmd_api.c:93

References value.

◆ rz_md4_fini()

void rz_md4_fini ( ut8 hash,
RzMD4 context 
)

Definition at line 154 of file md4.c.

154  {
155  rz_return_if_fail(context && hash);
156 
158 
159  for (ut32 t = 0; t < 4; ++t) {
160  rz_write_at_le32(hash, context->digest[t], t * 4);
161  }
162 }
void md4_padding(RzMD4 *context)
Definition: md4.c:129
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
static void rz_write_at_le32(void *dest, ut32 val, size_t offset)
Definition: rz_endian.h:261

References md4_padding(), rz_return_if_fail, and rz_write_at_le32().

Referenced by plugin_md4_final(), and plugin_md4_small_block().

◆ rz_md4_init()

void rz_md4_init ( RzMD4 context)

Definition at line 17 of file md4.c.

17  {
19 
20  context->digest[0] = 0x67452301;
21  context->digest[1] = 0xEFCDAB89;
22  context->digest[2] = 0x98BADCFE;
23  context->digest[3] = 0x10325476;
24  context->index = 0;
25  context->len_high = 0;
26  context->len_low = 0;
27 }

References rz_return_if_fail.

Referenced by plugin_md4_init(), and plugin_md4_small_block().

◆ rz_md4_update()

bool rz_md4_update ( RzMD4 context,
const ut8 data,
ut64  length 
)

Definition at line 105 of file md4.c.

105  {
106  rz_return_val_if_fail(context && data, false);
107  for (ut64 i = 0; i < length; ++i) {
108  context->block[context->index++] = data[i];
109 
110  context->len_low += 8;
111  if (context->len_low > 0xFFFFFFFFull) {
112  context->len_low &= 0xFFFFFFFFull;
113  context->len_high++;
114  // check if digested data overflows UT64
115  if (context->len_high > 0xFFFFFFFFull) {
116  return false;
117  }
118  }
119 
120  // digest only 512 bit blocks
121  if (context->index == RZ_HASH_MD4_BLOCK_LENGTH) {
123  }
124  }
125 
126  return true;
127 }
lzma_index ** i
Definition: index.h:629
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References i, length, md4_digest_block(), RZ_HASH_MD4_BLOCK_LENGTH, rz_return_val_if_fail, and ut64().

Referenced by plugin_md4_small_block(), and plugin_md4_update().