The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
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.
 
#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.
 
fr_md5_ctx_tfr_md5_ctx_alloc_from_list (void)
 Allocation function for MD5 digest context.
 
void fr_md5_ctx_free_from_list (fr_md5_ctx_t **ctx)
 Free function for MD5 digest ctx.
 
static fr_md5_ctx_tfr_md5_local_ctx_alloc (void)
 Allocation function for MD5 digest context.
 
static void fr_md5_local_ctx_copy (fr_md5_ctx_t *dst, fr_md5_ctx_t const *src)
 Copy the contents of a ctx.
 
static void fr_md5_local_ctx_free (fr_md5_ctx_t **ctx)
 Free function for MD5 digest ctx.
 
static void fr_md5_local_ctx_reset (fr_md5_ctx_t *ctx)
 Reset the ctx to allow reuse.
 
static void fr_md5_local_final (uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx)
 Finalise the ctx, producing the digest.
 
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.
 
static void fr_md5_local_update (fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen)
 Ingest plaintext into the digest.
 

Variables

fr_md5_funcs_t const * fr_md5_funcs = &md5_local_funcs
 Swap a single pointer, so all functions get swapped as an atomic operation.
 
static _Thread_local fr_md5_free_list_tmd5_array
 
static fr_md5_funcs_t md5_local_funcs
 
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 150 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 149 of file md5.c.

◆ MD5_F1

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

Definition at line 198 of file md5.c.

◆ MD5_F2

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

Definition at line 199 of file md5.c.

◆ MD5_F3

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

Definition at line 200 of file md5.c.

◆ MD5_F4

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

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

Function Documentation

◆ _md5_ctx_free_on_exit()

static int _md5_ctx_free_on_exit ( void *  arg)
static

Definition at line 483 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 473 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  )

Allocation function for MD5 digest context.

Allocate an MD5 context from a free list.

Returns
  • An MD5 ctx.
  • NULL if out of memory.

Definition at line 499 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)

Free function for MD5 digest ctx.

Release an MD5 context back to a free list.

Parameters
[in]ctxMD5 ctx to free. If the shared ctx is passed in then the ctx is reset but not freed.

Definition at line 544 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

Allocation function for MD5 digest context.

Returns
  • An MD5 ctx.
  • NULL if out of memory.

Definition at line 338 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

Copy the contents of a ctx.

Parameters
[in]dstWhere to copy the context to.
[in]srcWhere to copy the context from.

Definition at line 327 of file md5.c.

◆ fr_md5_local_ctx_free()

static void fr_md5_local_ctx_free ( fr_md5_ctx_t **  ctx)
static

Free function for MD5 digest ctx.

Parameters
[in]ctxMD5 ctx to free. If the shared ctx is passed in then the ctx is reset but not freed.

Definition at line 379 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

Reset the ctx to allow reuse.

Parameters
[in]ctxTo reuse.

Definition at line 311 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

Finalise the ctx, producing the digest.

Parameters
[out]outThe MD5 digest.
[in]ctxTo finalise.

Definition at line 443 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 215 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

Ingest plaintext into the digest.

Parameters
[in]ctxTo ingest data into.
[in]inData to ingest.
[in]inlenLength of data to ingest.

Definition at line 390 of file md5.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_md5_funcs

fr_md5_funcs_t const* fr_md5_funcs = &md5_local_funcs

Swap a single pointer, so all functions get swapped as an atomic operation.

Definition at line 53 of file md5.c.

◆ md5_array

_Thread_local fr_md5_free_list_t* md5_array
static

Definition at line 28 of file md5.c.

◆ md5_local_funcs

fr_md5_funcs_t md5_local_funcs
static
Initial value:
= {
}
static void fr_md5_local_ctx_copy(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src)
Copy the contents of a ctx.
Definition md5.c:327
static void fr_md5_local_update(fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen)
Ingest plaintext into the digest.
Definition md5.c:390
static void fr_md5_local_ctx_reset(fr_md5_ctx_t *ctx)
Reset the ctx to allow reuse.
Definition md5.c:311
static fr_md5_ctx_t * fr_md5_local_ctx_alloc(void)
Allocation function for MD5 digest context.
Definition md5.c:338
static void fr_md5_local_final(uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx)
Finalise the ctx, producing the digest.
Definition md5.c:443
static void fr_md5_local_ctx_free(fr_md5_ctx_t **ctx)
Free function for MD5 digest ctx.
Definition md5.c:379

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

◆ zero

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

Definition at line 385 of file md5.c.