Rizin
unix-like reverse engineering framework and cli tools
md5.h File Reference
#include <rz_types.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  MD5Context
 

Macros

#define RZ_HASH_MD5_DIGEST_SIZE   0x10
 
#define RZ_HASH_MD5_BLOCK_LENGTH   0x40
 
#define MD5_BLOCK_LENGTH   64
 
#define MD5_DIGEST_LENGTH   16
 

Typedefs

typedef struct MD5Context rz_MD5_CTX
 

Functions

RZ_IPI void rz_MD5Init (rz_MD5_CTX *)
 
RZ_IPI void rz_MD5Update (rz_MD5_CTX *, const ut8 *, size_t)
 
RZ_IPI void rz_MD5Final (ut8[MD5_DIGEST_LENGTH], rz_MD5_CTX *)
 

Macro Definition Documentation

◆ MD5_BLOCK_LENGTH

#define MD5_BLOCK_LENGTH   64

Definition at line 33 of file md5.h.

◆ MD5_DIGEST_LENGTH

#define MD5_DIGEST_LENGTH   16

Definition at line 34 of file md5.h.

◆ RZ_HASH_MD5_BLOCK_LENGTH

#define RZ_HASH_MD5_BLOCK_LENGTH   0x40

Definition at line 10 of file md5.h.

◆ RZ_HASH_MD5_DIGEST_SIZE

#define RZ_HASH_MD5_DIGEST_SIZE   0x10

Definition at line 9 of file md5.h.

Typedef Documentation

◆ rz_MD5_CTX

typedef struct MD5Context rz_MD5_CTX

Function Documentation

◆ rz_MD5Final()

RZ_IPI void rz_MD5Final ( ut8  digest[MD5_DIGEST_LENGTH],
rz_MD5_CTX ctx 
)

Definition at line 218 of file md5.c.

218  {
219  ut8 count[8];
220  size_t padlen;
221  int i;
222 
223  /* Convert count to 8 bytes in little endian order. */
224  PUT_64BIT_LE(count, ctx->count);
225 
226  /* Pad out to 56 mod 64. */
227  padlen = MD5_BLOCK_LENGTH -
228  ((ctx->count[0] >> 3) & (MD5_BLOCK_LENGTH - 1));
229  if (padlen < 1 + 8) {
230  padlen += MD5_BLOCK_LENGTH;
231  }
232  rz_MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
233  rz_MD5Update(ctx, count, 8);
234 
235  if (digest != NULL) {
236  for (i = 0; i < 4; i++) {
237  rz_write_le32(digest + i * 4, ctx->state[i]);
238  }
239  }
240  rz_mem_memzero(ctx, sizeof(*ctx)); /* in case it's sensitive */
241 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
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 count
Definition: sflib.h:98
uint8_t ut8
Definition: lh5801.h:11
static ut8 PADDING[MD5_BLOCK_LENGTH]
Definition: md5.c:50
#define PUT_64BIT_LE(cp, value)
Definition: md5.c:44
RZ_IPI void rz_MD5Update(rz_MD5_CTX *ctx, const unsigned char *input, size_t len)
Definition: md5.c:176
#define MD5_BLOCK_LENGTH
Definition: md5.h:33
static void rz_write_le32(void *dest, ut32 val)
Definition: rz_endian.h:256
RZ_API void rz_mem_memzero(void *, size_t)
Definition: mem.c:365

References count, i, MD5_BLOCK_LENGTH, NULL, PADDING, PUT_64BIT_LE, rz_MD5Update(), rz_mem_memzero(), and rz_write_le32().

Referenced by plugin_md5_final(), and plugin_md5_small_block().

◆ rz_MD5Init()

RZ_IPI void rz_MD5Init ( rz_MD5_CTX ctx)

Definition at line 163 of file md5.c.

163  {
164  ctx->count[0] = 0;
165  ctx->count[1] = 0;
166  ctx->state[0] = 0x67452301;
167  ctx->state[1] = 0xefcdab89;
168  ctx->state[2] = 0x98badcfe;
169  ctx->state[3] = 0x10325476;
170 }

Referenced by plugin_md5_init(), and plugin_md5_small_block().

◆ rz_MD5Update()

RZ_IPI void rz_MD5Update ( rz_MD5_CTX ctx,
const ut8 input,
size_t  len 
)

Definition at line 176 of file md5.c.

176  {
177  size_t have, need;
178 
179  /* Check how many bytes we already have and how many more we need. */
180  have = (size_t)((ctx->count[0] >> 3) & (MD5_BLOCK_LENGTH - 1));
181  need = MD5_BLOCK_LENGTH - have;
182 
183  /* Update bitcount */
184  /* ctx->count += (uint64_t)len << 3;*/
185  if ((ctx->count[0] += ((ut32)len << 3)) < (ut32)len) {
186  /* Overflowed ctx->count[0] */
187  ctx->count[1]++;
188  }
189  ctx->count[1] += ((ut32)len >> 29);
190 
191  if (len >= need) {
192  if (have != 0) {
193  memcpy(ctx->buffer + have, input, need);
194  MD5Transform(ctx->state, ctx->buffer);
195  input += need;
196  len -= need;
197  have = 0;
198  }
199 
200  /* Process data in MD5_BLOCK_LENGTH-byte chunks. */
201  while (len >= MD5_BLOCK_LENGTH) {
202  MD5Transform(ctx->state, input);
205  }
206  }
207 
208  /* Handle any remaining bytes of data. */
209  if (len != 0) {
210  memcpy(ctx->buffer + have, input, len);
211  }
212 }
size_t len
Definition: 6502dis.c:15
uint32_t ut32
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void MD5Transform(ut32 state[4], const ut8 block[MD5_BLOCK_LENGTH])
Definition: md5.c:73
int size_t
Definition: sftypes.h:40
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References input(), len, MD5_BLOCK_LENGTH, MD5Transform(), and memcpy().

Referenced by plugin_md5_small_block(), plugin_md5_update(), and rz_MD5Final().