The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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  */
9 RCSIDH(md5_h, "$Id: de408dca67b56eaf79804a9efe2080ebd36d163e $")
10 
11 #ifdef __cplusplus
12 extern "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 
28 typedef void fr_md5_ctx_t;
29 
30 /* md5.c */
31 
32 /** Reset the ctx to allow reuse
33  *
34  * @param[in] ctx To reuse.
35  */
36 typedef void (*fr_md5_ctx_reset_t)(fr_md5_ctx_t *ctx);
38 
39 /** Copy the contents of a ctx
40  *
41  * @param[in] dst Where to copy the context to.
42  * @param[in] src Where to copy the context from.
43  */
44 typedef void (*fr_md5_ctx_copy_t)(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src);
46 
47 /** Allocation function for MD5 digest context
48  *
49  * @return
50  * - An MD5 ctx.
51  * - NULL if out of memory.
52  */
53 typedef fr_md5_ctx_t *(*fr_md5_ctx_alloc_t)(void);
55 
56 /** Free function for MD5 digest ctx
57  *
58  * @param[in] ctx MD5 ctx to free. If the shared ctx is passed in
59  * then the ctx is reset but not freed.
60  */
61 typedef void (*fr_md5_ctx_free_t)(fr_md5_ctx_t **ctx);
63 
64 /** Ingest plaintext into the digest
65  *
66  * @param[in] ctx To ingest data into.
67  * @param[in] in Data to ingest.
68  * @param[in] inlen Length of data to ingest.
69  */
70 typedef void (*fr_md5_update_t)(fr_md5_ctx_t *ctx, uint8_t const *in, size_t inlen);
72 
73 /** Finalise the ctx, producing the digest
74  *
75  * @param[out] out The MD5 digest.
76  * @param[in] ctx To finalise.
77  */
78 typedef void (*fr_md5_final_t)(uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx);
80 
81 /** Perform a single digest operation on a single input buffer
82  *
83  */
84 void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen);
85 
86 /** Allocate an MD5 context from a free list
87  *
88  */
90 
91 /** Release an MD5 context back to a free list
92  *
93  */
95 
96 /* hmac.c */
97 int fr_hmac_md5(uint8_t digest[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen,
98  uint8_t const *key, size_t key_len);
99 #ifdef __cplusplus
100 }
101 #endif
#define RCSIDH(h, id)
Definition: build.h:482
static fr_slen_t in
Definition: dict.h:821
#define MD5_DIGEST_LENGTH
Definition: md5.h:25
fr_md5_ctx_alloc_t fr_md5_ctx_alloc
Definition: md5.c:440
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)
Ingest plaintext into the digest.
Definition: md5.h:70
fr_md5_ctx_free_t fr_md5_ctx_free
Definition: md5.c:441
fr_md5_ctx_t *(* fr_md5_ctx_alloc_t)(void)
Allocation function for MD5 digest context.
Definition: md5.h:53
fr_md5_update_t fr_md5_update
Definition: md5.c:442
fr_md5_final_t fr_md5_final
Definition: md5.c:443
void(* fr_md5_final_t)(uint8_t out[static MD5_DIGEST_LENGTH], fr_md5_ctx_t *ctx)
Finalise the ctx, producing the digest.
Definition: md5.h:78
void fr_md5_ctx_t
Definition: md5.h:28
void(* fr_md5_ctx_free_t)(fr_md5_ctx_t **ctx)
Free function for MD5 digest ctx.
Definition: md5.h:61
fr_md5_ctx_reset_t fr_md5_ctx_reset
Definition: md5.c:438
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.
Definition: merged_model.c:251
void(* fr_md5_ctx_reset_t)(fr_md5_ctx_t *ctx)
Reset the ctx to allow reuse.
Definition: md5.h:36
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
Release an MD5 context back to a free list.
Definition: md5.c:522
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
Allocate an MD5 context from a free list.
Definition: md5.c:477
fr_md5_ctx_copy_t fr_md5_ctx_copy
Definition: md5.c:439
void(* fr_md5_ctx_copy_t)(fr_md5_ctx_t *dst, fr_md5_ctx_t const *src)
Copy the contents of a ctx.
Definition: md5.h:44
unsigned char uint8_t
Definition: merged_model.c:30
static size_t char fr_sbuff_t size_t inlen
Definition: value.h:997
static size_t char ** out
Definition: value.h:997