blob: b827ffecb15dc4438085bc78f54dba2674c91f71 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file md4.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD4 message digest algorithm (hash function)
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
6 * \warning MD4 is considered a weak message digest and its use constitutes a
7 * security risk. We recommend considering stronger message digests
8 * instead.
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020011 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakkerb96f1542010-07-18 20:36:00 +000013 *
Paul Bakker5121ce52009-01-03 21:22:43 +000014 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020015#ifndef MBEDTLS_MD4_H
16#define MBEDTLS_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000017
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020018#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010019#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020020#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020021#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020022#endif
Paul Bakker90995b52013-06-24 19:20:35 +020023
Rich Evans00ab4702015-02-06 13:43:58 +000024#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020025#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000026
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020027/* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020028/** MD4 hardware accelerator failed */
29#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020030
Paul Bakker407a0da2013-06-27 14:29:21 +020031#ifdef __cplusplus
32extern "C" {
33#endif
34
Ron Eldorb2aacec2017-05-18 16:53:08 +030035#if !defined(MBEDTLS_MD4_ALT)
36// Regular implementation
37//
38
Paul Bakker5121ce52009-01-03 21:22:43 +000039/**
40 * \brief MD4 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010041 *
42 * \warning MD4 is considered a weak message digest and its use
43 * constitutes a security risk. We recommend considering
44 * stronger message digests instead.
45 *
Paul Bakker5121ce52009-01-03 21:22:43 +000046 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010047typedef struct mbedtls_md4_context {
Paul Bakker5c2364c2012-10-01 14:41:15 +000048 uint32_t total[2]; /*!< number of bytes processed */
49 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000050 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000051}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052mbedtls_md4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000053
Ron Eldorb2aacec2017-05-18 16:53:08 +030054#else /* MBEDTLS_MD4_ALT */
55#include "md4_alt.h"
56#endif /* MBEDTLS_MD4_ALT */
57
Paul Bakker5121ce52009-01-03 21:22:43 +000058/**
Paul Bakker5b4af392014-06-26 12:09:34 +020059 * \brief Initialize MD4 context
60 *
61 * \param ctx MD4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010062 *
63 * \warning MD4 is considered a weak message digest and its use
64 * constitutes a security risk. We recommend considering
65 * stronger message digests instead.
66 *
Paul Bakker5b4af392014-06-26 12:09:34 +020067 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010068void mbedtls_md4_init(mbedtls_md4_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020069
70/**
71 * \brief Clear MD4 context
72 *
73 * \param ctx MD4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010074 *
75 * \warning MD4 is considered a weak message digest and its use
76 * constitutes a security risk. We recommend considering
77 * stronger message digests instead.
78 *
Paul Bakker5b4af392014-06-26 12:09:34 +020079 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010080void mbedtls_md4_free(mbedtls_md4_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020081
82/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020083 * \brief Clone (the state of) an MD4 context
84 *
85 * \param dst The destination context
86 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010087 *
88 * \warning MD4 is considered a weak message digest and its use
89 * constitutes a security risk. We recommend considering
90 * stronger message digests instead.
91 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020092 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010093void mbedtls_md4_clone(mbedtls_md4_context *dst,
94 const mbedtls_md4_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020095
96/**
Paul Bakker5121ce52009-01-03 21:22:43 +000097 * \brief MD4 context setup
98 *
99 * \param ctx context to be initialized
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100100 *
101 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100102 *
103 * \warning MD4 is considered a weak message digest and its use
104 * constitutes a security risk. We recommend considering
105 * stronger message digests instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100107int mbedtls_md4_starts_ret(mbedtls_md4_context *ctx);
Paul Bakker5121ce52009-01-03 21:22:43 +0000108
109/**
110 * \brief MD4 process buffer
111 *
112 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100113 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 * \param ilen length of the input data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100115 *
116 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100117 *
118 * \warning MD4 is considered a weak message digest and its use
119 * constitutes a security risk. We recommend considering
120 * stronger message digests instead.
121 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000122 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100123int mbedtls_md4_update_ret(mbedtls_md4_context *ctx,
124 const unsigned char *input,
125 size_t ilen);
Paul Bakker5121ce52009-01-03 21:22:43 +0000126
127/**
128 * \brief MD4 final digest
129 *
130 * \param ctx MD4 context
131 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100132 *
133 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100134 *
135 * \warning MD4 is considered a weak message digest and its use
136 * constitutes a security risk. We recommend considering
137 * stronger message digests instead.
138 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000139 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100140int mbedtls_md4_finish_ret(mbedtls_md4_context *ctx,
141 unsigned char output[16]);
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100142
143/**
144 * \brief MD4 process data block (internal use only)
145 *
146 * \param ctx MD4 context
147 * \param data buffer holding one block of data
148 *
149 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100150 *
151 * \warning MD4 is considered a weak message digest and its use
152 * constitutes a security risk. We recommend considering
153 * stronger message digests instead.
154 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100155 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100156int mbedtls_internal_md4_process(mbedtls_md4_context *ctx,
157 const unsigned char data[64]);
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100158
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200159#if !defined(MBEDTLS_DEPRECATED_REMOVED)
160#if defined(MBEDTLS_DEPRECATED_WARNING)
161#define MBEDTLS_DEPRECATED __attribute__((deprecated))
162#else
163#define MBEDTLS_DEPRECATED
164#endif
165/**
166 * \brief MD4 context setup
167 *
168 * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
169 *
170 * \param ctx context to be initialized
171 *
172 * \warning MD4 is considered a weak message digest and its use
173 * constitutes a security risk. We recommend considering
174 * stronger message digests instead.
175 *
176 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100177MBEDTLS_DEPRECATED void mbedtls_md4_starts(mbedtls_md4_context *ctx);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200178
179/**
180 * \brief MD4 process buffer
181 *
182 * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
183 *
184 * \param ctx MD4 context
185 * \param input buffer holding the data
186 * \param ilen length of the input data
187 *
188 * \warning MD4 is considered a weak message digest and its use
189 * constitutes a security risk. We recommend considering
190 * stronger message digests instead.
191 *
192 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100193MBEDTLS_DEPRECATED void mbedtls_md4_update(mbedtls_md4_context *ctx,
194 const unsigned char *input,
195 size_t ilen);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200196
197/**
198 * \brief MD4 final digest
199 *
200 * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
201 *
202 * \param ctx MD4 context
203 * \param output MD4 checksum result
204 *
205 * \warning MD4 is considered a weak message digest and its use
206 * constitutes a security risk. We recommend considering
207 * stronger message digests instead.
208 *
209 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100210MBEDTLS_DEPRECATED void mbedtls_md4_finish(mbedtls_md4_context *ctx,
211 unsigned char output[16]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200212
213/**
214 * \brief MD4 process data block (internal use only)
215 *
216 * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
217 *
218 * \param ctx MD4 context
219 * \param data buffer holding one block of data
220 *
221 * \warning MD4 is considered a weak message digest and its use
222 * constitutes a security risk. We recommend considering
223 * stronger message digests instead.
224 *
225 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100226MBEDTLS_DEPRECATED void mbedtls_md4_process(mbedtls_md4_context *ctx,
227 const unsigned char data[64]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200228
229#undef MBEDTLS_DEPRECATED
230#endif /* !MBEDTLS_DEPRECATED_REMOVED */
231
Paul Bakker5121ce52009-01-03 21:22:43 +0000232/**
233 * \brief Output = MD4( input buffer )
234 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100235 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000236 * \param ilen length of the input data
237 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100238 *
239 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100240 *
241 * \warning MD4 is considered a weak message digest and its use
242 * constitutes a security risk. We recommend considering
243 * stronger message digests instead.
244 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100246int mbedtls_md4_ret(const unsigned char *input,
247 size_t ilen,
248 unsigned char output[16]);
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100249
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200250#if !defined(MBEDTLS_DEPRECATED_REMOVED)
251#if defined(MBEDTLS_DEPRECATED_WARNING)
252#define MBEDTLS_DEPRECATED __attribute__((deprecated))
253#else
254#define MBEDTLS_DEPRECATED
255#endif
256/**
257 * \brief Output = MD4( input buffer )
258 *
259 * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
260 *
261 * \param input buffer holding the data
262 * \param ilen length of the input data
263 * \param output MD4 checksum result
264 *
265 * \warning MD4 is considered a weak message digest and its use
266 * constitutes a security risk. We recommend considering
267 * stronger message digests instead.
268 *
269 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100270MBEDTLS_DEPRECATED void mbedtls_md4(const unsigned char *input,
271 size_t ilen,
272 unsigned char output[16]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200273
274#undef MBEDTLS_DEPRECATED
275#endif /* !MBEDTLS_DEPRECATED_REMOVED */
276
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500277#if defined(MBEDTLS_SELF_TEST)
278
Paul Bakker5121ce52009-01-03 21:22:43 +0000279/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000280 * \brief Checkup routine
281 *
282 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100283 *
284 * \warning MD4 is considered a weak message digest and its use
285 * constitutes a security risk. We recommend considering
286 * stronger message digests instead.
287 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000288 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100289int mbedtls_md4_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000290
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500291#endif /* MBEDTLS_SELF_TEST */
292
Paul Bakker5121ce52009-01-03 21:22:43 +0000293#ifdef __cplusplus
294}
295#endif
296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297#endif /* mbedtls_md4.h */