Blender  V3.3
Classes | Macros | Typedefs | Functions | Variables
hash_md5.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "BLI_hash_md5.h"

Go to the source code of this file.

Classes

struct  md5_ctx
 

Macros

#define UINT_MAX_32_BITS   0xFFFFFFFF
 
#define UINT_MAX   UINT_MAX_32_BITS
 
#define SWAP(n)   (n)
 
#define FF(b, c, d)   (d ^ (b & (c ^ d)))
 
#define FG(b, c, d)   FF(d, b, c)
 
#define FH(b, c, d)   (b ^ c ^ d)
 
#define FI(b, c, d)   (c ^ (b | ~d))
 
#define CYCLIC(w, s)   (w = (w << s) | (w >> (32 - s)))
 
#define OP(a, b, c, d, s, T)
 
#define OP(f, a, b, c, d, k, s, T)
 
#define BLOCKSIZE   4096 /* IMPORTANT: must be a multiple of 64. */
 

Typedefs

typedef unsigned int md5_uint32
 

Functions

static void md5_init_ctx (struct md5_ctx *ctx)
 
static void md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
 
static voidmd5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
 
int BLI_hash_md5_stream (FILE *stream, void *resblock)
 
voidBLI_hash_md5_buffer (const char *buffer, size_t len, void *resblock)
 
char * BLI_hash_md5_to_hexdigest (void *resblock, char r_hex_digest[33])
 

Variables

static const unsigned char fillbuf [64] = {0x80, 0 }
 

Detailed Description

Functions to compute MD5 message digest of files or memory blocks according to the definition of MD5 in RFC 1321 from April 1992.

Definition in file hash_md5.c.

Macro Definition Documentation

◆ BLOCKSIZE

#define BLOCKSIZE   4096 /* IMPORTANT: must be a multiple of 64. */

◆ CYCLIC

#define CYCLIC (   w,
 
)    (w = (w << s) | (w >> (32 - s)))

◆ FF

#define FF (   b,
  c,
 
)    (d ^ (b & (c ^ d)))

◆ FG

#define FG (   b,
  c,
 
)    FF(d, b, c)

◆ FH

#define FH (   b,
  c,
 
)    (b ^ c ^ d)

◆ FI

#define FI (   b,
  c,
 
)    (c ^ (b | ~d))

◆ OP [1/2]

#define OP (   a,
  b,
  c,
  d,
  s,
  T 
)
Value:
a += FF(b, c, d) + (*cwp++ = SWAP(*words)) + T; \
words++; \
CYCLIC(a, s); \
a += b; \
(void)0
SyclQueue void void size_t num_bytes void
#define FF(b, c, d)
#define SWAP(n)
Definition: hash_md5.c:75
#define T
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)

◆ OP [2/2]

#define OP (   f,
  a,
  b,
  c,
  d,
  k,
  s,
  T 
)
Value:
a += f(b, c, d) + correct_words[k] + T; \
CYCLIC(a, s); \
a += b; \
(void)0

◆ SWAP

#define SWAP (   n)    (n)

Definition at line 75 of file hash_md5.c.

◆ UINT_MAX

#define UINT_MAX   UINT_MAX_32_BITS

Definition at line 43 of file hash_md5.c.

◆ UINT_MAX_32_BITS

#define UINT_MAX_32_BITS   0xFFFFFFFF

Definition at line 33 of file hash_md5.c.

Typedef Documentation

◆ md5_uint32

typedef unsigned int md5_uint32

Definition at line 47 of file hash_md5.c.

Function Documentation

◆ BLI_hash_md5_buffer()

void* BLI_hash_md5_buffer ( const char *  buffer,
size_t  len,
void resblock 
)

Compute MD5 message digest for 'len' bytes beginning at 'buffer'. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest.

Definition at line 345 of file hash_md5.c.

References buffer, fillbuf, len, md5_init_ctx(), md5_process_block(), md5_read_ctx(), pad, and SWAP.

Referenced by IMB_thumb_load_font_get_hash(), render_result_exr_file_cache_path(), and thumbpathname_from_uri().

◆ BLI_hash_md5_stream()

int BLI_hash_md5_stream ( FILE *  stream,
void resblock 
)

Compute MD5 message digest for bytes read from 'stream'. The resulting message digest number will be written into the 16 bytes beginning at 'resblock'.

Returns
Non-zero if an error occurred.

Definition at line 272 of file hash_md5.c.

References BLOCKSIZE, buffer, fillbuf, len, md5_init_ctx(), md5_process_block(), md5_read_ctx(), pad, sum(), and SWAP.

◆ BLI_hash_md5_to_hexdigest()

char* BLI_hash_md5_to_hexdigest ( void resblock,
char  r_hex_digest[33] 
)

◆ md5_init_ctx()

static void md5_init_ctx ( struct md5_ctx ctx)
static

Initialize structure containing state of computation. (RFC 1321, 3.3: Step 3)

Definition at line 86 of file hash_md5.c.

References md5_ctx::A, md5_ctx::B, md5_ctx::C, and md5_ctx::D.

Referenced by BLI_hash_md5_buffer(), and BLI_hash_md5_stream().

◆ md5_process_block()

static void md5_process_block ( const void buffer,
size_t  len,
struct md5_ctx ctx 
)
static

Starting with the result of former calls of this function (or the initialization), this function updates the 'ctx' context for the next 'len' bytes starting at 'buffer'. It is necessary that 'len' is a multiple of 64!!!

Definition at line 99 of file hash_md5.c.

References A, md5_ctx::A, B, md5_ctx::B, buffer, md5_ctx::C, C, md5_ctx::D, D(), FG, FH, FI, len, and OP.

Referenced by BLI_hash_md5_buffer(), and BLI_hash_md5_stream().

◆ md5_read_ctx()

static void* md5_read_ctx ( const struct md5_ctx ctx,
void resbuf 
)
static

Put result from 'ctx' in first 16 bytes of 'resbuf'. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest.

Definition at line 259 of file hash_md5.c.

References md5_ctx::A, md5_ctx::B, md5_ctx::C, md5_ctx::D, and SWAP.

Referenced by BLI_hash_md5_buffer(), and BLI_hash_md5_stream().

Variable Documentation

◆ fillbuf

const unsigned char fillbuf[64] = {0x80, 0 }
static

Definition at line 80 of file hash_md5.c.

Referenced by BLI_hash_md5_buffer(), and BLI_hash_md5_stream().