The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions | Variables
md5.c File Reference

A local MD5 implementation. More...

#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/md5.h>
+ Include dependency graph for md5.c:

Go to the source code of this file.

Data Structures

struct  fr_md5_ctx_local_t
 
struct  fr_md5_free_list_t
 

Macros

#define ARRAY_SIZE   (8)
 The thread local free list. More...
 
#define MD5_BLOCK_LENGTH   64
 
#define MD5_F1(x, y, z)   (z ^ (x & (y ^ z)))
 
#define MD5_F2(x, y, z)   MD5_F1(z, x, y)
 
#define MD5_F3(x, y, z)   (x ^ y ^ z)
 
#define MD5_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)
 
#define PUT_32BIT_LE(cp, value)
 
#define PUT_64BIT_LE(cp, value)
 

Functions

static int _md5_ctx_free_on_exit (void *arg)
 
void fr_md5_calc (uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
 Calculate the MD5 hash of the contents of a buffer. More...
 
fr_md5_ctx_tfr_md5_ctx_alloc_from_list (void)
 
void fr_md5_ctx_free_from_list (fr_md5_ctx_t **ctx)
 
static fr_md5_ctx_tfr_md5_local_ctx_alloc (void)
 
static void fr_md5_local_ctx_copy (fr_md5_ctx_t *dst, fr_md5_ctx_t const *src)
 
static void fr_md5_local_ctx_free (fr_md5_ctx_t **ctx)
 
static void fr_md5_local_ctx_reset (fr_md5_ctx_t *ctx)
 
static void fr_md5_local_final (uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx)
 
static void fr_md5_local_transform (uint32_t state[static 4], uint8_t const block[static MD5_BLOCK_LENGTH])
 The core of the MD5 algorithm. More...
 
static void fr_md5_local_update (fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen)
 

Variables

fr_md5_ctx_alloc_t fr_md5_ctx_alloc = fr_md5_local_ctx_alloc
 
fr_md5_ctx_copy_t fr_md5_ctx_copy = fr_md5_local_ctx_copy
 
fr_md5_ctx_free_t fr_md5_ctx_free = fr_md5_local_ctx_free
 
fr_md5_ctx_reset_t fr_md5_ctx_reset = fr_md5_local_ctx_reset
 
fr_md5_final_t fr_md5_final = fr_md5_local_final
 
fr_md5_update_t fr_md5_update = fr_md5_local_update
 
static _Thread_local fr_md5_free_list_tmd5_array
 
static const uint8_t PADDING [MD5_BLOCK_LENGTH]
 
static const uint8_tzero = (uint8_t[]){ 0x00 }
 

Detailed Description

A local MD5 implementation.

Note
license is LGPL, but largely derived from a public domain source.

Definition in file md5.c.


Data Structure Documentation

◆ fr_md5_ctx_local_t

struct fr_md5_ctx_local_t

Definition at line 118 of file md5.c.

Data Fields
uint8_t buffer[MD5_BLOCK_LENGTH] Input buffer.
uint32_t count[2] Number of bits, mod 2^64.
uint32_t state[4] State.

◆ fr_md5_free_list_t

struct fr_md5_free_list_t

Definition at line 24 of file md5.c.

Data Fields
fr_md5_ctx_t * md_ctx
bool used

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE   (8)

The thread local free list.

Any entries remaining in the list will be freed when the thread is joined

Definition at line 23 of file md5.c.

◆ MD5_BLOCK_LENGTH

#define MD5_BLOCK_LENGTH   64

Definition at line 117 of file md5.c.

◆ MD5_F1

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

Definition at line 166 of file md5.c.

◆ MD5_F2

#define MD5_F2 (   x,
  y,
 
)    MD5_F1(z, x, y)

Definition at line 167 of file md5.c.

◆ MD5_F3

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

Definition at line 168 of file md5.c.

◆ MD5_F4

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

Definition at line 169 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 172 of file md5.c.

◆ PUT_32BIT_LE

#define PUT_32BIT_LE (   cp,
  value 
)
Value:
do {\
(cp)[3] = (value) >> 24;\
(cp)[2] = (value) >> 16;\
(cp)[1] = (value) >> 8;\
(cp)[0] = (value);\
} while (0)
Test enumeration values.
Definition: dict_test.h:92

Definition at line 151 of file md5.c.

◆ PUT_64BIT_LE

#define PUT_64BIT_LE (   cp,
  value 
)
Value:
do {\
(cp)[7] = (value)[1] >> 24;\
(cp)[6] = (value)[1] >> 16;\
(cp)[5] = (value)[1] >> 8;\
(cp)[4] = (value)[1];\
(cp)[3] = (value)[0] >> 24;\
(cp)[2] = (value)[0] >> 16;\
(cp)[1] = (value)[0] >> 8;\
(cp)[0] = (value)[0];\
} while (0)

Definition at line 140 of file md5.c.

Function Documentation

◆ _md5_ctx_free_on_exit()

static int _md5_ctx_free_on_exit ( void *  arg)
static

Definition at line 461 of file md5.c.

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

◆ fr_md5_calc()

void fr_md5_calc ( uint8_t  out[static MD5_DIGEST_LENGTH],
uint8_t const *  in,
size_t  inlen 
)

Calculate the MD5 hash of the contents of a buffer.

Perform a single digest operation on a single input buffer.

Parameters
[out]outWhere to write the MD5 digest. Must be a minimum of MD5_DIGEST_LENGTH.
[in]inData to hash.
[in]inlenLength of the data.

Definition at line 451 of file md5.c.

+ Here is the call graph for this function:

◆ fr_md5_ctx_alloc_from_list()

fr_md5_ctx_t* fr_md5_ctx_alloc_from_list ( void  )

Allocate an MD5 context from a free list.

Definition at line 477 of file md5.c.

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

◆ fr_md5_ctx_free_from_list()

void fr_md5_ctx_free_from_list ( fr_md5_ctx_t **  ctx)

Release an MD5 context back to a free list.

Definition at line 522 of file md5.c.

+ Here is the caller graph for this function:

◆ fr_md5_local_ctx_alloc()

static fr_md5_ctx_t* fr_md5_local_ctx_alloc ( void  )
static

Definition at line 306 of file md5.c.

+ Here is the call graph for this function:

◆ fr_md5_local_ctx_copy()

static void fr_md5_local_ctx_copy ( fr_md5_ctx_t dst,
fr_md5_ctx_t const *  src 
)
static

Definition at line 295 of file md5.c.

◆ fr_md5_local_ctx_free()

static void fr_md5_local_ctx_free ( fr_md5_ctx_t **  ctx)
static

Definition at line 347 of file md5.c.

+ Here is the call graph for this function:

◆ fr_md5_local_ctx_reset()

static void fr_md5_local_ctx_reset ( fr_md5_ctx_t ctx)
static

Definition at line 279 of file md5.c.

+ Here is the caller graph for this function:

◆ fr_md5_local_final()

static void fr_md5_local_final ( uint8_t  out[static MD5_DIGEST_LENGTH],
fr_md5_ctx_t ctx 
)
static

Definition at line 411 of file md5.c.

◆ fr_md5_local_transform()

static void fr_md5_local_transform ( uint32_t  state[static 4],
uint8_t const  block[static MD5_BLOCK_LENGTH] 
)
static

The core of the MD5 algorithm.

This alters an existing MD5 hash to reflect the addition of 16 longwords of new data. fr_md5_update blocks the data and converts bytes into longwords for this routine.

Parameters
[in]state16 bytes of data to feed into the hashing function.
[in,out]blockMD5 digest block to update.

Definition at line 183 of file md5.c.

+ Here is the caller graph for this function:

◆ fr_md5_local_update()

static void fr_md5_local_update ( fr_md5_ctx_t ctx,
uint8_t const *  in,
size_t  inlen 
)
static

Definition at line 358 of file md5.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_md5_ctx_alloc

Definition at line 440 of file md5.c.

◆ fr_md5_ctx_copy

Definition at line 439 of file md5.c.

◆ fr_md5_ctx_free

Definition at line 441 of file md5.c.

◆ fr_md5_ctx_reset

Definition at line 438 of file md5.c.

◆ fr_md5_final

Definition at line 443 of file md5.c.

◆ fr_md5_update

Definition at line 442 of file md5.c.

◆ md5_array

_Thread_local fr_md5_free_list_t* md5_array
static

Definition at line 28 of file md5.c.

◆ PADDING

const uint8_t PADDING[MD5_BLOCK_LENGTH]
static
Initial value:
= {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 158 of file md5.c.

◆ zero

const uint8_t* zero = (uint8_t[]){ 0x00 }
static

Definition at line 353 of file md5.c.