The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
md5.h
Go to the documentation of this file.
1#pragma once
2/** Structures and prototypes for our local MD5 implementation
3 *
4 * @note license is LGPL, but largely derived from a public domain source.
5 *
6 * @file src/lib/util/md5.h
7 * @brief Structures and declarations for md5.
8 */
9RCSIDH(md5_h, "$Id: 9337b7afabfe542007d5b7ad40ae21cb8dbc7342 $")
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <freeradius-devel/build.h>
16#include <freeradius-devel/missing.h>
17
18#include <inttypes.h>
19#include <sys/types.h>
20#include <stdint.h>
21#include <stdbool.h>
22#include <string.h>
23
24#ifndef MD5_DIGEST_LENGTH
25# define MD5_DIGEST_LENGTH 16
26#endif
27
28typedef void fr_md5_ctx_t;
29
30/* md5.c */
31
32typedef void (*fr_md5_ctx_reset_t)(fr_md5_ctx_t *ctx);
33typedef void (*fr_md5_ctx_copy_t)(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src);
34typedef fr_md5_ctx_t *(*fr_md5_ctx_alloc_t)(void);
35typedef void (*fr_md5_ctx_free_t)(fr_md5_ctx_t **ctx);
36typedef void (*fr_md5_update_t)(fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen);
38
47
48/** Swap a single pointer, so all functions get swapped as an atomic operation
49 */
50extern fr_md5_funcs_t const *fr_md5_funcs;
51
52/** Reset the ctx to allow reuse
53 *
54 * @param[in] ctx To reuse.
55 */
56#define fr_md5_ctx_reset(_ctx) fr_md5_funcs->reset(_ctx)
57
58/** Copy the contents of a ctx
59 *
60 * @param[in] dst Where to copy the context to.
61 * @param[in] src Where to copy the context from.
62 */
63#define fr_md5_ctx_copy(_dst, _src) fr_md5_funcs->copy(_dst, _src)
64
65/** Allocation function for MD5 digest context
66 *
67 * @return
68 * - An MD5 ctx.
69 * - NULL if out of memory.
70 */
71#define fr_md5_ctx_alloc() fr_md5_funcs->alloc()
72
73/** Free function for MD5 digest ctx
74 *
75 * @param[in] ctx MD5 ctx to free. If the shared ctx is passed in
76 * then the ctx is reset but not freed.
77 */
78#define fr_md5_ctx_free(_ctx) fr_md5_funcs->free(_ctx)
79
80/** Ingest plaintext into the digest
81 *
82 * @param[in] ctx To ingest data into.
83 * @param[in] in Data to ingest.
84 * @param[in] inlen Length of data to ingest.
85 */
86#define fr_md5_update(_ctx, _in, _inlen) fr_md5_funcs->update(_ctx, _in, _inlen)
87
88/** Finalise the ctx, producing the digest
89 *
90 * @param[out] out The MD5 digest.
91 * @param[in] ctx To finalise.
92 */
93#define fr_md5_final(_out, _ctx) fr_md5_funcs->final(_out, _ctx)
94
95/** Perform a single digest operation on a single input buffer
96 *
97 */
98void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen);
99
100/** Allocate an MD5 context from a free list
101 *
102 */
104
105/** Release an MD5 context back to a free list
106 *
107 */
109
110/* hmac.c */
111int fr_hmac_md5(uint8_t digest[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
112 uint8_t const *key, size_t key_len);
113#ifdef __cplusplus
114}
115#endif
#define RCSIDH(h, id)
Definition build.h:486
static fr_slen_t in
Definition dict.h:849
fr_md5_ctx_copy_t copy
Definition md5.h:41
#define MD5_DIGEST_LENGTH
Definition md5.h:25
fr_md5_ctx_reset_t reset
Definition md5.h:40
int fr_hmac_md5(uint8_t digest[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen, uint8_t const *key, size_t key_len)
void(* fr_md5_update_t)(fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen)
Definition md5.h:36
void(* fr_md5_final_t)(uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx)
Definition md5.h:37
void fr_md5_ctx_t
Definition md5.h:28
fr_md5_ctx_t *(* fr_md5_ctx_alloc_t)(void)
Definition md5.h:34
void(* fr_md5_ctx_free_t)(fr_md5_ctx_t **ctx)
Definition md5.h:35
fr_md5_ctx_free_t free
Definition md5.h:43
fr_md5_ctx_alloc_t alloc
Definition md5.h:42
void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Perform a single digest operation on a single input buffer.
void(* fr_md5_ctx_reset_t)(fr_md5_ctx_t *ctx)
Definition md5.h:32
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
Release an MD5 context back to a free list.
Definition md5.c:544
fr_md5_funcs_t const * fr_md5_funcs
Swap a single pointer, so all functions get swapped as an atomic operation.
Definition md5.c:53
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
Allocate an MD5 context from a free list.
Definition md5.c:499
void(* fr_md5_ctx_copy_t)(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src)
Definition md5.h:33
fr_md5_update_t update
Definition md5.h:44
unsigned char uint8_t
static size_t char fr_sbuff_t size_t inlen
Definition value.h:1023
static size_t char ** out
Definition value.h:1023