GNU libmicrohttpd 1.0.6
Loading...
Searching...
No Matches
md5.c File Reference

Calculation of MD5 digest as defined in RFC 1321. More...

#include "md5.h"
#include <string.h>
#include "mhd_bithelpers.h"
#include "mhd_assert.h"
Include dependency graph for md5.c:

Go to the source code of this file.

Macros

#define F_FUNC(x, y, z)
#define G_FUNC_1(x, y, z)
#define G_FUNC_2(x, y, z)
#define H_FUNC(x, y, z)
#define I_FUNC(x, y, z)
#define MD5STEP_R1(va, vb, vc, vd, vX, vs, vT)
#define GET_X_FROM_DATA(buf, t)
#define MD5STEP_R2(va, vb, vc, vd, vX, vs, vT)
#define MD5STEP_R3(va, vb, vc, vd, vX, vs, vT)
#define MD5STEP_R4(va, vb, vc, vd, vX, vs, vT)
#define MD5_SIZE_OF_LEN_ADD_BITS   64
#define MD5_SIZE_OF_LEN_ADD   (MD5_SIZE_OF_LEN_ADD_BITS / 8)

Functions

void MHD_MD5_init (struct Md5Ctx *ctx)
static MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ void md5_transform (uint32_t H[MD5_HASH_SIZE_WORDS], const void *M)
void MHD_MD5_update (struct Md5Ctx *ctx, const uint8_t *data, size_t length)
void MHD_MD5_finish (struct Md5Ctx *ctx, uint8_t digest[MD5_DIGEST_SIZE])

Detailed Description

Calculation of MD5 digest as defined in RFC 1321.

Author
Karlson2k (Evgeny Grin)

Definition in file md5.c.

Macro Definition Documentation

◆ F_FUNC

#define F_FUNC ( x,
y,
z )
Value:
((((y) ^ (z)) & (x)) ^ (z))

◆ G_FUNC_1

#define G_FUNC_1 ( x,
y,
z )
Value:
((~(z)) & (y))

◆ G_FUNC_2

#define G_FUNC_2 ( x,
y,
z )
Value:
((z) & (x))

◆ GET_X_FROM_DATA

#define GET_X_FROM_DATA ( buf,
t )
Value:
_MHD_GET_32BIT_LE (((const uint32_t*) (buf)) + (t))
#define _MHD_GET_32BIT_LE(addr)

Referenced by md5_transform().

◆ H_FUNC

#define H_FUNC ( x,
y,
z )
Value:
((x) ^ (y) ^ (z)) /* Original version */

◆ I_FUNC

#define I_FUNC ( x,
y,
z )
Value:
(((~(z)) | (x)) ^ (y))

◆ MD5_SIZE_OF_LEN_ADD

#define MD5_SIZE_OF_LEN_ADD   (MD5_SIZE_OF_LEN_ADD_BITS / 8)

Size of "length" insertion in bytes.

Definition at line 452 of file md5.c.

Referenced by MHD_MD5_finish().

◆ MD5_SIZE_OF_LEN_ADD_BITS

#define MD5_SIZE_OF_LEN_ADD_BITS   64

Size of "length" insertion in bits. See RFC 1321, end of Clause 3.2 (step 2).

Definition at line 447 of file md5.c.

◆ MD5STEP_R1

#define MD5STEP_R1 ( va,
vb,
vc,
vd,
vX,
vs,
vT )
Value:
do { \
(va) += (vX) + (vT); \
(va) += F_FUNC((vb),(vc),(vd)); \
(va) = _MHD_ROTL32((va),(vs)) + (vb); } while (0)
#define F_FUNC(x, y, z)
_MHD_static_inline uint32_t _MHD_ROTL32(uint32_t value32, int bits)

Referenced by md5_transform().

◆ MD5STEP_R2

#define MD5STEP_R2 ( va,
vb,
vc,
vd,
vX,
vs,
vT )
Value:
do { \
(va) += (vX) + (vT); \
(va) += G_FUNC_1((vb),(vc),(vd)); \
(va) += G_FUNC_2((vb),(vc),(vd)); \
(va) = _MHD_ROTL32((va),(vs)) + (vb); } while (0)
#define G_FUNC_1(x, y, z)
#define G_FUNC_2(x, y, z)

Referenced by md5_transform().

◆ MD5STEP_R3

#define MD5STEP_R3 ( va,
vb,
vc,
vd,
vX,
vs,
vT )
Value:
do { \
(va) += (vX) + (vT); \
(va) += H_FUNC((vb),(vc),(vd)); \
(va) = _MHD_ROTL32((va),(vs)) + (vb); } while (0)
#define H_FUNC(x, y, z)

Referenced by md5_transform().

◆ MD5STEP_R4

#define MD5STEP_R4 ( va,
vb,
vc,
vd,
vX,
vs,
vT )
Value:
do { \
(va) += (vX) + (vT); \
(va) += I_FUNC((vb),(vc),(vd)); \
(va) = _MHD_ROTL32((va),(vs)) + (vb); } while (0)
#define I_FUNC(x, y, z)

Referenced by md5_transform().

Function Documentation

◆ md5_transform()

MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ void md5_transform ( uint32_t H[MD5_HASH_SIZE_WORDS],
const void * M )
static

Base of MD5 transformation. Gets full 64 bytes block of data and updates hash values;

Parameters
Hhash values
Mthe data buffer with MD5_BLOCK_SIZE bytes block

Definition at line 66 of file md5.c.

References _MHD_UINT32_ALIGN, GET_X_FROM_DATA, MD5_HASH_SIZE_WORDS, MD5STEP_R1, MD5STEP_R2, MD5STEP_R3, and MD5STEP_R4.

Referenced by MHD_MD5_finish(), and MHD_MD5_update().

Here is the caller graph for this function:

◆ MHD_MD5_finish()

void MHD_MD5_finish ( struct Md5Ctx * ctx,
uint8_t digest[MD5_DIGEST_SIZE] )

Finalise MD5 calculation, return digest.

Parameters
ctxthe calculation context
[out]digestset to the hash, must be MD5_DIGEST_SIZE bytes

< Number of processed bits

< Number of bytes in the context buffer

Definition at line 461 of file md5.c.

References _MHD_PUT_32BIT_LE, _MHD_PUT_64BIT_LE_SAFE(), _MHD_UINT32_ALIGN, Md5Ctx::buffer, Md5Ctx::count, Md5Ctx::H, MD5_BLOCK_SIZE, MD5_BLOCK_SIZE_WORDS, MD5_BYTES_IN_WORD, MD5_DIGEST_SIZE, MD5_DIGEST_SIZE_WORDS, MD5_SIZE_OF_LEN_ADD, and md5_transform().

Referenced by digest_calc_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_MD5_init()

void MHD_MD5_init ( struct Md5Ctx * ctx)

Initialise structure for MD5 calculation.

Parameters
ctxthe calculation context

Definition at line 41 of file md5.c.

References Md5Ctx::count, and Md5Ctx::H.

◆ MHD_MD5_update()

void MHD_MD5_update ( struct Md5Ctx * ctx,
const uint8_t * data,
size_t length )

Process portion of bytes.

Parameters
ctxthe calculation context
databytes to add to hash
lengthnumber of bytes in data

MD5 process portion of bytes.

Parameters
ctxthe calculation context
databytes to add to hash
lengthnumber of bytes in data

< Number of bytes in the context buffer

Definition at line 393 of file md5.c.

References Md5Ctx::buffer, Md5Ctx::count, data, Md5Ctx::H, MD5_BLOCK_SIZE, md5_transform(), mhd_assert, and NULL.

Referenced by digest_update().

Here is the call graph for this function:
Here is the caller graph for this function: