The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
md4.c
Go to the documentation of this file.
1/** A local MD4 implementation
2 *
3 * @note license is LGPL, but largely derived from a public domain source.
4 *
5 * @file src/lib/util/md4.c
6 */
7RCSID("$Id: 774f74e3d49871113aa756137cf339b959d75be2 $")
8
9#include <freeradius-devel/util/debug.h>
10#include <freeradius-devel/util/strerror.h>
11#include <freeradius-devel/util/atexit.h>
12
13/*
14 * FORCE MD4 TO USE OUR MD4 HEADER FILE!
15 * If we don't do this, it might pick up the systems broken MD4.
16 */
17#include <freeradius-devel/util/md4.h>
18
19/** The thread local free list
20 *
21 * Any entries remaining in the list will be freed when the thread is joined
22 */
23#define ARRAY_SIZE (8)
24typedef struct {
25 bool used;
28static _Thread_local fr_md4_free_list_t *md4_array;
29
30static void fr_md4_local_ctx_reset(fr_md4_ctx_t *ctx);
31static void fr_md4_local_ctx_copy(fr_md4_ctx_t *dst, fr_md4_ctx_t const *src);
32#ifdef HAVE_OPENSSL_EVP_H
33static fr_md4_ctx_t *fr_md4_local_ctx_init(void);
34#else
36#endif
37static void fr_md4_local_ctx_free(fr_md4_ctx_t **ctx);
38static void fr_md4_local_update(fr_md4_ctx_t *ctx, uint8_t const *in, size_t inlen);
40
44#ifdef HAVE_OPENSSL_EVP_H
45 .alloc = fr_md4_local_ctx_init,
46#else
48#endif
50 .update = fr_md4_local_update,
51 .final = fr_md4_local_final
52};
54
55/*
56 * If we have OpenSSL's EVP API available, then build wrapper functions.
57 *
58 * We always need to build the local MD4 functions as OpenSSL could
59 * be operating in FIPS mode where MD4 digest functions are unavailable.
60 */
61#ifdef HAVE_OPENSSL_EVP_H
62# include <freeradius-devel/tls/openssl_user_macros.h>
63# include <openssl/evp.h>
64# include <openssl/crypto.h>
65# include <openssl/err.h>
66# include <openssl/provider.h>
67
68/** @copydoc fr_md4_ctx_reset
69 *
70 */
71static void fr_md4_openssl_ctx_reset(fr_md4_ctx_t *ctx)
72{
73 EVP_MD_CTX *md_ctx = ctx;
74
75 EVP_MD_CTX_reset(md_ctx);
76 EVP_DigestInit_ex(md_ctx, EVP_md4(), NULL);
77}
78
79/** @copydoc fr_md4_ctx_copy
80 *
81 */
82static void fr_md4_openssl_ctx_copy(fr_md4_ctx_t *dst, fr_md4_ctx_t const *src)
83{
84 EVP_MD_CTX_copy_ex(dst, src);
85}
86
87/** @copydoc fr_md4_ctx_alloc
88 *
89 */
90static fr_md4_ctx_t *fr_md4_openssl_ctx_alloc(void)
91{
92 EVP_MD_CTX *md_ctx;
93
94 md_ctx = EVP_MD_CTX_new();
95 if (unlikely(!md_ctx)) return NULL;
96
97 if (EVP_DigestInit_ex(md_ctx, EVP_md4(), NULL) != 1) {
98 char buffer[256];
99
100 ERR_error_string_n(ERR_get_error(), buffer, sizeof(buffer));
101 fr_strerror_printf("Failed initialising md4 ctx: %s", buffer);
102 EVP_MD_CTX_free(md_ctx);
103
104 return NULL;
105 }
106
107 return md_ctx;
108}
109
110/** @copydoc fr_md4_ctx_free
111 *
112 */
113static void fr_md4_openssl_ctx_free(fr_md4_ctx_t **ctx)
114{
115 EVP_MD_CTX_free(*ctx);
116 *ctx = NULL;
117}
118
119/** @copydoc fr_md4_update
120 *
121 */
122static void fr_md4_openssl_update(fr_md4_ctx_t *ctx, uint8_t const *in, size_t inlen)
123{
124 EVP_DigestUpdate(ctx, in, inlen);
125}
126
127/** @copydoc fr_md4_final
128 *
129 */
130static void fr_md4_openssl_final(uint8_t out[static MD4_DIGEST_LENGTH], fr_md4_ctx_t *ctx)
131{
132 unsigned int len;
133
134 EVP_DigestFinal(ctx, out, &len);
135
136 if (!fr_cond_assert(len == MD4_DIGEST_LENGTH)) return;
137}
138
139static fr_md4_funcs_t md4_openssl_funcs = {
140 .reset = fr_md4_openssl_ctx_reset,
141 .copy = fr_md4_openssl_ctx_copy,
142 .alloc = fr_md4_openssl_ctx_alloc,
143 .free = fr_md4_openssl_ctx_free,
144 .update = fr_md4_openssl_update,
145 .final = fr_md4_openssl_final
146};
147#endif
148
149/*
150 * This code implements the MD4 message-digest algorithm.
151 * The algorithm is due to Ron Rivest. This code was
152 * written by Colin Plumb in 1993, no copyright is claimed.
153 * This code is in the public domain; do with it what you wish.
154 * Todd C. Miller modified the md4 code to do MD4 based on RFC 1186.
155 *
156 * Equivalent code is available from RSA Data Security, Inc.
157 * This code has been tested against that, and is equivalent,
158 * except that you don't need to include two pages of legalese
159 * with every copy.
160 *
161 * To compute the message digest of a chunk of bytes, declare an
162 * MD4Context structure, pass it to fr_md4_init, call fr_md4_update as
163 * needed on buffers full of bytes, and then call fr_md4_final, which
164 * will fill a supplied 16-byte array with the digest.
165 */
166#ifndef WORDS_BIGENDIAN
167# define htole32_4(buf) /* Nothing */
168# define htole32_14(buf) /* Nothing */
169# define htole32_16(buf) /* Nothing */
170#else
171/* Sometimes defined by endian.h */
172# ifndef htole32
173# define htole32(x)\
174 (((((uint32_t)x) & 0xff000000) >> 24) |\
175 ((((uint32_t)x) & 0x00ff0000) >> 8) |\
176 ((((uint32_t)x) & 0x0000ff00) << 8) |\
177 ((((uint32_t)x) & 0x000000ff) << 24))
178# endif
179# define htole32_4(buf) do {\
180 (buf)[0] = htole32((buf)[0]);\
181 (buf)[1] = htole32((buf)[1]);\
182 (buf)[2] = htole32((buf)[2]);\
183 (buf)[3] = htole32((buf)[3]);\
184} while (0)
185
186# define htole32_14(buf) do {\
187 (buf)[0] = htole32((buf)[0]);\
188 (buf)[1] = htole32((buf)[1]);\
189 (buf)[2] = htole32((buf)[2]);\
190 (buf)[3] = htole32((buf)[3]);\
191 (buf)[4] = htole32((buf)[4]);\
192 (buf)[5] = htole32((buf)[5]);\
193 (buf)[6] = htole32((buf)[6]);\
194 (buf)[7] = htole32((buf)[7]);\
195 (buf)[8] = htole32((buf)[8]);\
196 (buf)[9] = htole32((buf)[9]);\
197 (buf)[10] = htole32((buf)[10]);\
198 (buf)[11] = htole32((buf)[11]);\
199 (buf)[12] = htole32((buf)[12]);\
200 (buf)[13] = htole32((buf)[13]);\
201} while (0)
202
203# define htole32_16(buf) do {\
204 (buf)[0] = htole32((buf)[0]);\
205 (buf)[1] = htole32((buf)[1]);\
206 (buf)[2] = htole32((buf)[2]);\
207 (buf)[3] = htole32((buf)[3]);\
208 (buf)[4] = htole32((buf)[4]);\
209 (buf)[5] = htole32((buf)[5]);\
210 (buf)[6] = htole32((buf)[6]);\
211 (buf)[7] = htole32((buf)[7]);\
212 (buf)[8] = htole32((buf)[8]);\
213 (buf)[9] = htole32((buf)[9]);\
214 (buf)[10] = htole32((buf)[10]);\
215 (buf)[11] = htole32((buf)[11]);\
216 (buf)[12] = htole32((buf)[12]);\
217 (buf)[13] = htole32((buf)[13]);\
218 (buf)[14] = htole32((buf)[14]);\
219 (buf)[15] = htole32((buf)[15]);\
220} while (0)
221#endif
222
223#define MD4_BLOCK_LENGTH 64
224
225/* The three core functions - F1 is optimized somewhat */
226#define MD4_F1(x, y, z) (z ^ (x & (y ^ z)))
227#define MD4_F2(x, y, z) ((x & y) | (x & z) | (y & z))
228#define MD4_F3(x, y, z) (x ^ y ^ z)
229
230/* This is the central step in the MD4 algorithm. */
231#define MD4STEP(f, w, x, y, z, data, s) (w += f(x, y, z) + data, w = w << s | w >> (32 - s))
232
233/** The core of the MD4 algorithm
234 *
235 * This alters an existing MD4 hash to reflect the addition of 16
236 * longwords of new data. fr_md4_update blocks the data and converts bytes
237 * into longwords for this routine.
238 *
239 * @param[in] state 16 bytes of data to feed into the hashing function.
240 * @param[in,out] block MD4 digest block to update.
241 */
242static void fr_md4_local_transform(uint32_t state[static 4], uint8_t const block[static MD4_BLOCK_LENGTH])
243{
244 uint32_t a, b, c, d;
245 uint32_t const *in = (uint32_t const *)block;
246
247 a = state[0];
248 b = state[1];
249 c = state[2];
250 d = state[3];
251
252 MD4STEP(MD4_F1, a, b, c, d, in[ 0], 3);
253 MD4STEP(MD4_F1, d, a, b, c, in[ 1], 7);
254 MD4STEP(MD4_F1, c, d, a, b, in[ 2], 11);
255 MD4STEP(MD4_F1, b, c, d, a, in[ 3], 19);
256 MD4STEP(MD4_F1, a, b, c, d, in[ 4], 3);
257 MD4STEP(MD4_F1, d, a, b, c, in[ 5], 7);
258 MD4STEP(MD4_F1, c, d, a, b, in[ 6], 11);
259 MD4STEP(MD4_F1, b, c, d, a, in[ 7], 19);
260 MD4STEP(MD4_F1, a, b, c, d, in[ 8], 3);
261 MD4STEP(MD4_F1, d, a, b, c, in[ 9], 7);
262 MD4STEP(MD4_F1, c, d, a, b, in[10], 11);
263 MD4STEP(MD4_F1, b, c, d, a, in[11], 19);
264 MD4STEP(MD4_F1, a, b, c, d, in[12], 3);
265 MD4STEP(MD4_F1, d, a, b, c, in[13], 7);
266 MD4STEP(MD4_F1, c, d, a, b, in[14], 11);
267 MD4STEP(MD4_F1, b, c, d, a, in[15], 19);
268
269 MD4STEP(MD4_F2, a, b, c, d, in[ 0] + 0x5a827999, 3);
270 MD4STEP(MD4_F2, d, a, b, c, in[ 4] + 0x5a827999, 5);
271 MD4STEP(MD4_F2, c, d, a, b, in[ 8] + 0x5a827999, 9);
272 MD4STEP(MD4_F2, b, c, d, a, in[12] + 0x5a827999, 13);
273 MD4STEP(MD4_F2, a, b, c, d, in[ 1] + 0x5a827999, 3);
274 MD4STEP(MD4_F2, d, a, b, c, in[ 5] + 0x5a827999, 5);
275 MD4STEP(MD4_F2, c, d, a, b, in[ 9] + 0x5a827999, 9);
276 MD4STEP(MD4_F2, b, c, d, a, in[13] + 0x5a827999, 13);
277 MD4STEP(MD4_F2, a, b, c, d, in[ 2] + 0x5a827999, 3);
278 MD4STEP(MD4_F2, d, a, b, c, in[ 6] + 0x5a827999, 5);
279 MD4STEP(MD4_F2, c, d, a, b, in[10] + 0x5a827999, 9);
280 MD4STEP(MD4_F2, b, c, d, a, in[14] + 0x5a827999, 13);
281 MD4STEP(MD4_F2, a, b, c, d, in[ 3] + 0x5a827999, 3);
282 MD4STEP(MD4_F2, d, a, b, c, in[ 7] + 0x5a827999, 5);
283 MD4STEP(MD4_F2, c, d, a, b, in[11] + 0x5a827999, 9);
284 MD4STEP(MD4_F2, b, c, d, a, in[15] + 0x5a827999, 13);
285
286 MD4STEP(MD4_F3, a, b, c, d, in[ 0] + 0x6ed9eba1, 3);
287 MD4STEP(MD4_F3, d, a, b, c, in[ 8] + 0x6ed9eba1, 9);
288 MD4STEP(MD4_F3, c, d, a, b, in[ 4] + 0x6ed9eba1, 11);
289 MD4STEP(MD4_F3, b, c, d, a, in[12] + 0x6ed9eba1, 15);
290 MD4STEP(MD4_F3, a, b, c, d, in[ 2] + 0x6ed9eba1, 3);
291 MD4STEP(MD4_F3, d, a, b, c, in[10] + 0x6ed9eba1, 9);
292 MD4STEP(MD4_F3, c, d, a, b, in[ 6] + 0x6ed9eba1, 11);
293 MD4STEP(MD4_F3, b, c, d, a, in[14] + 0x6ed9eba1, 15);
294 MD4STEP(MD4_F3, a, b, c, d, in[ 1] + 0x6ed9eba1, 3);
295 MD4STEP(MD4_F3, d, a, b, c, in[ 9] + 0x6ed9eba1, 9);
296 MD4STEP(MD4_F3, c, d, a, b, in[ 5] + 0x6ed9eba1, 11);
297 MD4STEP(MD4_F3, b, c, d, a, in[13] + 0x6ed9eba1, 15);
298 MD4STEP(MD4_F3, a, b, c, d, in[ 3] + 0x6ed9eba1, 3);
299 MD4STEP(MD4_F3, d, a, b, c, in[11] + 0x6ed9eba1, 9);
300 MD4STEP(MD4_F3, c, d, a, b, in[ 7] + 0x6ed9eba1, 11);
301 MD4STEP(MD4_F3, b, c, d, a, in[15] + 0x6ed9eba1, 15);
302
303 state[0] += a;
304 state[1] += b;
305 state[2] += c;
306 state[3] += d;
307}
308
309typedef struct {
310 uint32_t state[4]; //!< State.
311 uint32_t count[2]; //!< Number of bits, mod 2^64.
312 uint8_t buffer[MD4_BLOCK_LENGTH]; //!< Input buffer.
314
315/** @copydoc fr_md4_ctx_reset
316 *
317 */
319{
320 fr_md4_ctx_local_t *ctx_local = talloc_get_type_abort(ctx, fr_md4_ctx_local_t);
321
322 ctx_local->count[0] = 0;
323 ctx_local->count[1] = 0;
324 ctx_local->state[0] = 0x67452301;
325 ctx_local->state[1] = 0xefcdab89;
326 ctx_local->state[2] = 0x98badcfe;
327 ctx_local->state[3] = 0x10325476;
328}
329
330/** @copydoc fr_md4_ctx_copy
331 *
332 */
334{
336 fr_md4_ctx_local_t *ctx_local_dst = talloc_get_type_abort(dst, fr_md4_ctx_local_t);
337
338 memcpy(ctx_local_dst, ctx_local_src, sizeof(*ctx_local_dst));
339}
340
341/** @copydoc fr_md4_ctx_alloc
342 *
343 */
345{
346 fr_md4_ctx_local_t *ctx_local;
347
348 ctx_local = talloc(NULL, fr_md4_ctx_local_t);
349 if (unlikely(!ctx_local)) return NULL;
350 fr_md4_local_ctx_reset(ctx_local);
351
352 return ctx_local;
353}
354
355#ifdef HAVE_OPENSSL_EVP_H
356/** Initialize whether or not we use the local allocator, or the OpenSSL one.
357 *
358 */
359static fr_md4_ctx_t *fr_md4_local_ctx_init(void)
360{
361 /*
362 * If we are in FIPS mode, then use the local allocator.
363 */
364 if (!EVP_default_properties_is_fips_enabled(NULL)) {
365 /*
366 * OpenSSL isn't in FIPS mode. Swap out the functions
367 * pointers for the OpenSSL versions.
368 *
369 * We do this by swapping out a pointer to a structure
370 * containing the functions, as this prevents possible
371 * skew where some threads see a mixture of functions.
372 */
373 fr_md4_funcs = &md4_openssl_funcs;
374 } else {
375 md4_local_funcs.alloc = fr_md4_local_ctx_alloc; /* Don't call this (init) function again */
376 }
377
378 return fr_md4_ctx_alloc();
379}
380#endif
381
382/** @copydoc fr_md4_ctx_free
383 *
384 */
386{
387 talloc_free(*ctx);
388 *ctx = NULL;
389}
390
391static const uint8_t *zero = (uint8_t[]){ 0x00 };
392
393/** @copydoc fr_md4_update
394 *
395 */
396static void fr_md4_local_update(fr_md4_ctx_t *ctx, uint8_t const *in, size_t inlen)
397{
399 fr_md4_ctx_local_t *ctx_local = talloc_get_type_abort(ctx, fr_md4_ctx_local_t);
400
401 /*
402 * Needed so we can calculate the zero
403 * length md4 hash correctly.
404 * ubsan doesn't like arithmetic on
405 * NULL pointers.
406 */
407 if (!in) {
408 in = zero;
409 inlen = 0;
410 }
411
412 /* Bytes already stored in ctx_local->buffer */
413 count = (uint32_t)((ctx_local->count[0] >> 3) & 0x3f);
414
415 /* Update bitcount */
416/* ctx_local->count += (uint64_t)inlen << 3;*/
417 if ((ctx_local->count[0] += ((uint32_t)inlen << 3)) < (uint32_t)inlen) {
418 /* Overflowed ctx_local->count[0] */
419 ctx_local->count[1]++;
420 }
421 ctx_local->count[1] += ((uint32_t)inlen >> 29);
422
423 /* Handle any leading odd-sized chunks */
424 if (count) {
425 unsigned char *p = (unsigned char *)ctx_local->buffer + count;
426
428 if (inlen < count) {
429 memcpy(p, in, inlen);
430 return;
431 }
432 memcpy(p, in, count);
433 htole32_16((uint32_t *)ctx_local->buffer);
434 fr_md4_local_transform(ctx_local->state, ctx_local->buffer);
435 in += count;
436 inlen -= count;
437 }
438
439 /* Process data in MD4_BLOCK_LENGTH-byte chunks */
440 while (inlen >= MD4_BLOCK_LENGTH) {
441 memcpy(ctx_local->buffer, in, MD4_BLOCK_LENGTH);
442 htole32_16((uint32_t *)ctx_local->buffer);
443 fr_md4_local_transform(ctx_local->state, ctx_local->buffer);
446 }
447
448 /* Handle any remaining bytes of data. */
449 memcpy(ctx_local->buffer, in, inlen);
450}
451
452/** @copydoc fr_md4_final
453 *
454 */
456{
458 unsigned char *p;
459 fr_md4_ctx_local_t *ctx_local = talloc_get_type_abort(ctx, fr_md4_ctx_local_t);
460
461 /* number of bytes mod 64 */
462 count = (uint32_t)(ctx_local->count[0] >> 3) & 0x3f;
463
464 /*
465 * Set the first char of padding to 0x80.
466 * This is safe since there is always at least one byte free.
467 */
468 p = ctx_local->buffer + count;
469 *p++ = 0x80;
470
471 /* Bytes of padding needed to make 64 bytes */
472 count = 64 - 1 - count;
473
474 /* Pad out to 56 mod 64 */
475 if (count < 8) {
476 /* Two lots of padding: Pad the first block to 64 bytes */
477 memset(p, 0, count);
478 htole32_16((uint32_t *)ctx_local->buffer);
479 fr_md4_local_transform(ctx_local->state, ctx_local->buffer);
480
481 /* Now fill the next block with 56 bytes */
482 memset(ctx_local->buffer, 0, 56);
483 } else {
484 /* Pad block to 56 bytes */
485 memset(p, 0, count - 8);
486 }
487 htole32_14((uint32_t *)ctx_local->buffer);
488
489 /* Append bit count and transform */
490 ((uint32_t *)ctx_local->buffer)[14] = ctx_local->count[0];
491 ((uint32_t *)ctx_local->buffer)[15] = ctx_local->count[1];
492
493 fr_md4_local_transform(ctx_local->state, ctx_local->buffer);
494 htole32_4(ctx_local->state);
495 memcpy(out, ctx_local->state, MD4_DIGEST_LENGTH);
496 memset(ctx_local, 0, sizeof(*ctx_local)); /* in case it's sensitive */
497}
498
499/*
500 * Digest function pointers
501 */
508
509/** Calculate the MD4 hash of the contents of a buffer
510 *
511 * @param[out] out Where to write the MD4 digest. Must be a minimum of MD4_DIGEST_LENGTH.
512 * @param[in] in Data to hash.
513 * @param[in] inlen Length of the data.
514 */
516{
517 fr_md4_ctx_t *ctx;
518
520 fr_md4_update(ctx, in, inlen);
521 fr_md4_final(out, ctx);
523}
524
525static int _md4_ctx_free_on_exit(void *arg)
526{
527 int i;
528 fr_md4_free_list_t *free_list = arg;
529
530 for (i = 0; i < ARRAY_SIZE; i++) {
531 if (free_list[i].used) continue;
532
533 fr_md4_ctx_free(&free_list[i].md_ctx);
534 }
535 return talloc_free(free_list);
536}
537
538/** @copydoc fr_md4_ctx_alloc
539 *
540 */
542{
543 int i;
544 fr_md4_ctx_t *md_ctx;
545 fr_md4_free_list_t *free_list;
546
547 if (unlikely(!md4_array)) {
548 free_list = talloc_zero_array(NULL, fr_md4_free_list_t, ARRAY_SIZE);
549 if (unlikely(!free_list)) {
550 oom:
551 fr_strerror_const("Out of Memory");
552 return NULL;
553 }
554
556
557 /*
558 * Initialize all md4 contexts
559 */
560 for (i = 0; i < ARRAY_SIZE; i++) {
561 md_ctx = fr_md4_ctx_alloc();
562 if (unlikely(md_ctx == NULL)) goto oom;
563
564 free_list[i].md_ctx = md_ctx;
565 }
566 } else {
567 free_list = md4_array;
568 }
569
570 for (i = 0; i < ARRAY_SIZE; i++) {
571 if (free_list[i].used) continue;
572
573 free_list[i].used = true;
574 return free_list[i].md_ctx;
575 }
576
577 /*
578 * No more free contexts, just allocate a new one.
579 */
580 return fr_md4_ctx_alloc();
581}
582
583/** @copydoc fr_md4_ctx_free
584 *
585 */
587{
588 int i;
589 fr_md4_free_list_t *free_list = md4_array;
590
591 if (free_list) {
592 for (i = 0; i < ARRAY_SIZE; i++) {
593 if (free_list[i].md_ctx == *ctx) {
594 free_list[i].used = false;
595 fr_md4_ctx_reset(*ctx);
596 *ctx = NULL;
597 return;
598 }
599 }
600 }
601
602 fr_md4_ctx_free(*ctx);
603 *ctx = NULL;
604}
static int const char char buffer[256]
Definition acutest.h:576
#define fr_atexit_thread_local(_name, _free, _uctx)
Definition atexit.h:221
#define RCSID(id)
Definition build.h:485
#define unlikely(_x)
Definition build.h:383
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
static fr_slen_t in
Definition dict.h:861
talloc_free(reap)
uint8_t buffer[MD4_BLOCK_LENGTH]
Input buffer.
Definition md4.c:312
static int _md4_ctx_free_on_exit(void *arg)
Definition md4.c:525
static void fr_md4_local_transform(uint32_t state[static 4], uint8_t const block[static MD4_BLOCK_LENGTH])
The core of the MD4 algorithm.
Definition md4.c:242
#define MD4_F1(x, y, z)
Definition md4.c:226
uint32_t state[4]
State.
Definition md4.c:310
fr_md4_ctx_alloc_t fr_md4_ctx_alloc
Definition md4.c:504
#define MD4STEP(f, w, x, y, z, data, s)
Definition md4.c:231
#define htole32_16(buf)
Definition md4.c:169
#define htole32_4(buf)
Definition md4.c:167
#define MD4_F3(x, y, z)
Definition md4.c:228
fr_md4_update_t fr_md4_update
Definition md4.c:506
static void fr_md4_local_ctx_free(fr_md4_ctx_t **ctx)
Free function for MD4 digest ctx.
Definition md4.c:385
#define ARRAY_SIZE
The thread local free list.
Definition md4.c:23
void fr_md4_calc(uint8_t out[static MD4_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Calculate the MD4 hash of the contents of a buffer.
Definition md4.c:515
static fr_md4_ctx_t * fr_md4_local_ctx_alloc(void)
Allocation function for MD4 digest context.
Definition md4.c:344
fr_md4_ctx_reset_t fr_md4_ctx_reset
Definition md4.c:502
fr_md4_ctx_copy_t fr_md4_ctx_copy
Definition md4.c:503
fr_md4_ctx_t * fr_md4_ctx_alloc_from_list(void)
Allocation function for MD4 digest context.
Definition md4.c:541
uint32_t count[2]
Number of bits, mod 2^64.
Definition md4.c:311
static void fr_md4_local_update(fr_md4_ctx_t *ctx, uint8_t const *in, size_t inlen)
Ingest plaintext into the digest.
Definition md4.c:396
fr_md4_final_t fr_md4_final
Definition md4.c:507
#define htole32_14(buf)
Definition md4.c:168
#define MD4_F2(x, y, z)
Definition md4.c:227
static _Thread_local fr_md4_free_list_t * md4_array
Definition md4.c:28
static void fr_md4_local_ctx_copy(fr_md4_ctx_t *dst, fr_md4_ctx_t const *src)
Copy the contents of a ctx.
Definition md4.c:333
static void fr_md4_local_final(uint8_t out[static MD4_DIGEST_LENGTH], fr_md4_ctx_t *ctx)
Finalise the ctx, producing the digest.
Definition md4.c:455
static fr_md4_funcs_t md4_local_funcs
Definition md4.c:41
fr_md4_ctx_t * md_ctx
Definition md4.c:26
void fr_md4_ctx_free_from_list(fr_md4_ctx_t **ctx)
Free function for MD4 digest ctx.
Definition md4.c:586
#define MD4_BLOCK_LENGTH
Definition md4.c:223
fr_md4_funcs_t const * fr_md4_funcs
Swap a single pointer, so all functions get swapped as an atomic operation.
Definition md4.c:53
fr_md4_ctx_free_t fr_md4_ctx_free
Definition md4.c:505
static void fr_md4_local_ctx_reset(fr_md4_ctx_t *ctx)
Reset the ctx to allow reuse.
Definition md4.c:318
static const uint8_t * zero
Definition md4.c:391
fr_md4_ctx_reset_t reset
Definition md4.h:40
void(* fr_md4_final_t)(uint8_t out[static MD4_DIGEST_LENGTH], fr_md4_ctx_t *ctx)
Definition md4.h:37
fr_md4_ctx_t *(* fr_md4_ctx_alloc_t)(void)
Definition md4.h:34
fr_md4_ctx_alloc_t alloc
Definition md4.h:42
void(* fr_md4_ctx_free_t)(fr_md4_ctx_t **ctx)
Definition md4.h:35
void(* fr_md4_ctx_copy_t)(fr_md4_ctx_t *dst, fr_md4_ctx_t const *src)
Definition md4.h:33
#define MD4_DIGEST_LENGTH
Definition md4.h:25
void(* fr_md4_ctx_reset_t)(fr_md4_ctx_t *ctx)
Definition md4.h:32
void fr_md4_ctx_t
Definition md4.h:28
void(* fr_md4_update_t)(fr_md4_ctx_t *ctx, uint8_t const *in, size_t inlen)
Definition md4.h:36
unsigned int uint32_t
unsigned char uint8_t
static size_t used
return count
Definition module.c:155
#define talloc_get_type_abort_const
Definition talloc.h:287
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
static size_t char fr_sbuff_t size_t inlen
Definition value.h:1023
static size_t char ** out
Definition value.h:1023