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