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: 99d9d01b5de8cc677cfbd022715a6a389f3f94ae $")
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
21#ifndef MD5_DIGEST_LENGTH
22# define MD5_DIGEST_LENGTH 16
23#endif
24
25typedef void fr_md5_ctx_t;
26
27/* md5.c */
28
29typedef void (*fr_md5_ctx_reset_t)(fr_md5_ctx_t *ctx);
30typedef void (*fr_md5_ctx_copy_t)(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src);
31typedef fr_md5_ctx_t *(*fr_md5_ctx_alloc_t)(void);
32typedef void (*fr_md5_ctx_free_t)(fr_md5_ctx_t **ctx);
33typedef void (*fr_md5_update_t)(fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen);
35
44
45/** Swap a single pointer, so all functions get swapped as an atomic operation
46 */
47extern fr_md5_funcs_t const *fr_md5_funcs;
48
49/** Reset the ctx to allow reuse
50 *
51 * @param[in] ctx To reuse.
52 */
53#define fr_md5_ctx_reset(_ctx) fr_md5_funcs->reset(_ctx)
54
55/** Copy the contents of a ctx
56 *
57 * @param[in] dst Where to copy the context to.
58 * @param[in] src Where to copy the context from.
59 */
60#define fr_md5_ctx_copy(_dst, _src) fr_md5_funcs->copy(_dst, _src)
61
62/** Allocation function for MD5 digest context
63 *
64 * @return
65 * - An MD5 ctx.
66 * - NULL if out of memory.
67 */
68#define fr_md5_ctx_alloc() fr_md5_funcs->alloc()
69
70/** Free function for MD5 digest ctx
71 *
72 * @param[in] ctx MD5 ctx to free. If the shared ctx is passed in
73 * then the ctx is reset but not freed.
74 */
75#define fr_md5_ctx_free(_ctx) fr_md5_funcs->free(_ctx)
76
77/** Ingest plaintext into the digest
78 *
79 * @param[in] ctx To ingest data into.
80 * @param[in] in Data to ingest.
81 * @param[in] inlen Length of data to ingest.
82 */
83#define fr_md5_update(_ctx, _in, _inlen) fr_md5_funcs->update(_ctx, _in, _inlen)
84
85/** Finalise the ctx, producing the digest
86 *
87 * @param[out] out The MD5 digest.
88 * @param[in] ctx To finalise.
89 */
90#define fr_md5_final(_out, _ctx) fr_md5_funcs->final(_out, _ctx)
91
92/** Perform a single digest operation on a single input buffer
93 *
94 */
95void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen);
96
97/** Allocate an MD5 context from a free list
98 *
99 */
101
102/** Release an MD5 context back to a free list
103 *
104 */
106
107/* hmac.c */
108int fr_hmac_md5(uint8_t digest[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
109 uint8_t const *key, size_t key_len);
110
111#ifdef HAVE_OPENSSL_EVP_H
112void fr_md5_openssl_init(void);
113void fr_md5_openssl_free(void);
114#endif
115
116#ifdef __cplusplus
117}
118#endif
#define RCSIDH(h, id)
Definition build.h:507
static fr_slen_t in
Definition dict.h:882
fr_md5_ctx_copy_t copy
Definition md5.h:38
#define MD5_DIGEST_LENGTH
Definition md5.h:22
fr_md5_ctx_reset_t reset
Definition md5.h:37
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:33
void(* fr_md5_final_t)(uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx)
Definition md5.h:34
void fr_md5_ctx_t
Definition md5.h:25
fr_md5_ctx_t *(* fr_md5_ctx_alloc_t)(void)
Definition md5.h:31
void(* fr_md5_ctx_free_t)(fr_md5_ctx_t **ctx)
Definition md5.h:32
fr_md5_ctx_free_t free
Definition md5.h:40
fr_md5_ctx_alloc_t alloc
Definition md5.h:39
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:29
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
Release an MD5 context back to a free list.
Definition md5.c:515
fr_md5_funcs_t const * fr_md5_funcs
Swap a single pointer, so all functions get swapped as an atomic operation.
Definition md5.c:45
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
Allocate an MD5 context from a free list.
Definition md5.c:470
void(* fr_md5_ctx_copy_t)(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src)
Definition md5.h:30
fr_md5_update_t update
Definition md5.h:41
unsigned char uint8_t
static size_t char fr_sbuff_t size_t inlen
Definition value.h:1030
static size_t char ** out
Definition value.h:1030