blob: eeb1670903b4a61e7b1184e6da22650eb4d890a3 [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
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000025 *
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#ifndef MBEDTLS_MD4_H
28#define MBEDTLS_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010031#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#endif
Paul Bakker90995b52013-06-24 19:20:35 +020035
Rich Evans00ab4702015-02-06 13:43:58 +000036#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020037#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000038
Ron Eldor9924bdc2018-10-04 10:59:13 +030039/* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea381fe82018-01-23 18:16:11 +010040#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
41
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Ron Eldorb2aacec2017-05-18 16:53:08 +030046#if !defined(MBEDTLS_MD4_ALT)
47// Regular implementation
48//
49
Paul Bakker5121ce52009-01-03 21:22:43 +000050/**
51 * \brief MD4 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010052 *
53 * \warning MD4 is considered a weak message digest and its use
54 * constitutes a security risk. We recommend considering
55 * stronger message digests instead.
56 *
Paul Bakker5121ce52009-01-03 21:22:43 +000057 */
Dawid Drozd428cc522018-07-24 10:02:47 +020058typedef struct mbedtls_md4_context
Paul Bakker5121ce52009-01-03 21:22:43 +000059{
Paul Bakker5c2364c2012-10-01 14:41:15 +000060 uint32_t total[2]; /*!< number of bytes processed */
61 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000062 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000063}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064mbedtls_md4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000065
Ron Eldorb2aacec2017-05-18 16:53:08 +030066#else /* MBEDTLS_MD4_ALT */
67#include "md4_alt.h"
68#endif /* MBEDTLS_MD4_ALT */
69
Paul Bakker5121ce52009-01-03 21:22:43 +000070/**
Paul Bakker5b4af392014-06-26 12:09:34 +020071 * \brief Initialize MD4 context
72 *
73 * \param ctx MD4 context to be initialized
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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080void mbedtls_md4_init( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020081
82/**
83 * \brief Clear MD4 context
84 *
85 * \param ctx MD4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010086 *
87 * \warning MD4 is considered a weak message digest and its use
88 * constitutes a security risk. We recommend considering
89 * stronger message digests instead.
90 *
Paul Bakker5b4af392014-06-26 12:09:34 +020091 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092void mbedtls_md4_free( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020093
94/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020095 * \brief Clone (the state of) an MD4 context
96 *
97 * \param dst The destination context
98 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010099 *
100 * \warning MD4 is considered a weak message digest and its use
101 * constitutes a security risk. We recommend considering
102 * stronger message digests instead.
103 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200104 */
105void mbedtls_md4_clone( mbedtls_md4_context *dst,
106 const mbedtls_md4_context *src );
107
108/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000109 * \brief MD4 context setup
110 *
111 * \param ctx context to be initialized
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100112 *
113 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100114 *
115 * \warning MD4 is considered a weak message digest and its use
116 * constitutes a security risk. We recommend considering
117 * stronger message digests instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000118 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100119int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000120
121/**
122 * \brief MD4 process buffer
123 *
124 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100125 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 * \param ilen length of the input data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100127 *
128 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100129 *
130 * \warning MD4 is considered a weak message digest and its use
131 * constitutes a security risk. We recommend considering
132 * stronger message digests instead.
133 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100135int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100136 const unsigned char *input,
137 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000138
139/**
140 * \brief MD4 final digest
141 *
142 * \param ctx MD4 context
143 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100144 *
145 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100146 *
147 * \warning MD4 is considered a weak message digest and its use
148 * constitutes a security risk. We recommend considering
149 * stronger message digests instead.
150 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100152int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100153 unsigned char output[16] );
154
155/**
156 * \brief MD4 process data block (internal use only)
157 *
158 * \param ctx MD4 context
159 * \param data buffer holding one block of data
160 *
161 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100162 *
163 * \warning MD4 is considered a weak message digest and its use
164 * constitutes a security risk. We recommend considering
165 * stronger message digests instead.
166 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100167 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100168int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
169 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100170
171#if !defined(MBEDTLS_DEPRECATED_REMOVED)
172#if defined(MBEDTLS_DEPRECATED_WARNING)
173#define MBEDTLS_DEPRECATED __attribute__((deprecated))
174#else
175#define MBEDTLS_DEPRECATED
176#endif
177/**
178 * \brief MD4 context setup
179 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100180 * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100181 *
182 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100183 *
184 * \warning MD4 is considered a weak message digest and its use
185 * constitutes a security risk. We recommend considering
186 * stronger message digests instead.
187 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100188 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000189MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100190
191/**
192 * \brief MD4 process buffer
193 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100194 * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100195 *
196 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100197 * \param input buffer holding the data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100198 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100199 *
200 * \warning MD4 is considered a weak message digest and its use
201 * constitutes a security risk. We recommend considering
202 * stronger message digests instead.
203 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100204 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000205MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
206 const unsigned char *input,
207 size_t ilen );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100208
209/**
210 * \brief MD4 final digest
211 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100212 * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100213 *
214 * \param ctx MD4 context
215 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100216 *
217 * \warning MD4 is considered a weak message digest and its use
218 * constitutes a security risk. We recommend considering
219 * stronger message digests instead.
220 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100221 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000222MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
223 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100224
225/**
226 * \brief MD4 process data block (internal use only)
227 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100228 * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100229 *
230 * \param ctx MD4 context
231 * \param data buffer holding one block of data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100232 *
233 * \warning MD4 is considered a weak message digest and its use
234 * constitutes a security risk. We recommend considering
235 * stronger message digests instead.
236 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100237 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000238MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
239 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100240
241#undef MBEDTLS_DEPRECATED
242#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000243
244/**
245 * \brief Output = MD4( input buffer )
246 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100247 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 * \param ilen length of the input data
249 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100250 *
251 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100252 *
253 * \warning MD4 is considered a weak message digest and its use
254 * constitutes a security risk. We recommend considering
255 * stronger message digests instead.
256 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000257 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100258int mbedtls_md4_ret( const unsigned char *input,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100259 size_t ilen,
260 unsigned char output[16] );
261
262#if !defined(MBEDTLS_DEPRECATED_REMOVED)
263#if defined(MBEDTLS_DEPRECATED_WARNING)
264#define MBEDTLS_DEPRECATED __attribute__((deprecated))
265#else
266#define MBEDTLS_DEPRECATED
267#endif
268/**
269 * \brief Output = MD4( input buffer )
270 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100271 * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100272 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100273 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000274 * \param ilen length of the input data
275 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100276 *
277 * \warning MD4 is considered a weak message digest and its use
278 * constitutes a security risk. We recommend considering
279 * stronger message digests instead.
280 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000281 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000282MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
283 size_t ilen,
284 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100285
286#undef MBEDTLS_DEPRECATED
287#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000288
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500289#if defined(MBEDTLS_SELF_TEST)
290
Paul Bakker5121ce52009-01-03 21:22:43 +0000291/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000292 * \brief Checkup routine
293 *
294 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100295 *
296 * \warning MD4 is considered a weak message digest and its use
297 * constitutes a security risk. We recommend considering
298 * stronger message digests instead.
299 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000300 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301int mbedtls_md4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000302
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500303#endif /* MBEDTLS_SELF_TEST */
304
Paul Bakker5121ce52009-01-03 21:22:43 +0000305#ifdef __cplusplus
306}
307#endif
308
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309#endif /* mbedtls_md4.h */