blob: e091fd91b1dcbef357ebab921b917bda588f4e55 [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úti44bfbe32020-08-19 16:54:51 +020011 * Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13 *
14 * This file is provided under the Apache License 2.0, or the
15 * GNU General Public License v2.0 or later.
16 *
17 * **********
18 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020019 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000031 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020032 * **********
33 *
34 * **********
35 * GNU General Public License v2.0 or later:
36 *
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License along
48 * with this program; if not, write to the Free Software Foundation, Inc.,
49 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50 *
51 * **********
52 *
Paul Bakker5121ce52009-01-03 21:22:43 +000053 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#ifndef MBEDTLS_MD4_H
55#define MBEDTLS_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020058#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020059#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020061#endif
Paul Bakker90995b52013-06-24 19:20:35 +020062
Rich Evans00ab4702015-02-06 13:43:58 +000063#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020064#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000065
Gilles Peskinea381fe82018-01-23 18:16:11 +010066#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if !defined(MBEDTLS_MD4_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020069// Regular implementation
70//
71
Paul Bakker407a0da2013-06-27 14:29:21 +020072#ifdef __cplusplus
73extern "C" {
74#endif
75
Paul Bakker5121ce52009-01-03 21:22:43 +000076/**
77 * \brief MD4 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010078 *
79 * \warning MD4 is considered a weak message digest and its use
80 * constitutes a security risk. We recommend considering
81 * stronger message digests instead.
82 *
Paul Bakker5121ce52009-01-03 21:22:43 +000083 */
84typedef struct
85{
Paul Bakker5c2364c2012-10-01 14:41:15 +000086 uint32_t total[2]; /*!< number of bytes processed */
87 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000088 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000089}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090mbedtls_md4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000091
Paul Bakker5121ce52009-01-03 21:22:43 +000092/**
Paul Bakker5b4af392014-06-26 12:09:34 +020093 * \brief Initialize MD4 context
94 *
95 * \param ctx MD4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010096 *
97 * \warning MD4 is considered a weak message digest and its use
98 * constitutes a security risk. We recommend considering
99 * stronger message digests instead.
100 *
Paul Bakker5b4af392014-06-26 12:09:34 +0200101 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102void mbedtls_md4_init( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200103
104/**
105 * \brief Clear MD4 context
106 *
107 * \param ctx MD4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100108 *
109 * \warning MD4 is considered a weak message digest and its use
110 * constitutes a security risk. We recommend considering
111 * stronger message digests instead.
112 *
Paul Bakker5b4af392014-06-26 12:09:34 +0200113 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114void mbedtls_md4_free( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200115
116/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200117 * \brief Clone (the state of) an MD4 context
118 *
119 * \param dst The destination context
120 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100121 *
122 * \warning MD4 is considered a weak message digest and its use
123 * constitutes a security risk. We recommend considering
124 * stronger message digests instead.
125 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200126 */
127void mbedtls_md4_clone( mbedtls_md4_context *dst,
128 const mbedtls_md4_context *src );
129
130/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 * \brief MD4 context setup
132 *
133 * \param ctx context to be initialized
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100134 *
135 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100136 *
137 * \warning MD4 is considered a weak message digest and its use
138 * constitutes a security risk. We recommend considering
139 * stronger message digests instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000140 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100141int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000142
143/**
144 * \brief MD4 process buffer
145 *
146 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100147 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000148 * \param ilen length of the input data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100149 *
150 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100151 *
152 * \warning MD4 is considered a weak message digest and its use
153 * constitutes a security risk. We recommend considering
154 * stronger message digests instead.
155 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100157int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100158 const unsigned char *input,
159 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000160
161/**
162 * \brief MD4 final digest
163 *
164 * \param ctx MD4 context
165 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100166 *
167 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100168 *
169 * \warning MD4 is considered a weak message digest and its use
170 * constitutes a security risk. We recommend considering
171 * stronger message digests instead.
172 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000173 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100174int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100175 unsigned char output[16] );
176
177/**
178 * \brief MD4 process data block (internal use only)
179 *
180 * \param ctx MD4 context
181 * \param data buffer holding one block of data
182 *
183 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100184 *
185 * \warning MD4 is considered a weak message digest and its use
186 * constitutes a security risk. We recommend considering
187 * stronger message digests instead.
188 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100189 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100190int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
191 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100192
193#if !defined(MBEDTLS_DEPRECATED_REMOVED)
194#if defined(MBEDTLS_DEPRECATED_WARNING)
195#define MBEDTLS_DEPRECATED __attribute__((deprecated))
196#else
197#define MBEDTLS_DEPRECATED
198#endif
199/**
200 * \brief MD4 context setup
201 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100202 * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100203 *
204 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100205 *
206 * \warning MD4 is considered a weak message digest and its use
207 * constitutes a security risk. We recommend considering
208 * stronger message digests instead.
209 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100210 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000211MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100212
213/**
214 * \brief MD4 process buffer
215 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100216 * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100217 *
218 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100219 * \param input buffer holding the data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100220 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100221 *
222 * \warning MD4 is considered a weak message digest and its use
223 * constitutes a security risk. We recommend considering
224 * stronger message digests instead.
225 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100226 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000227MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
228 const unsigned char *input,
229 size_t ilen );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100230
231/**
232 * \brief MD4 final digest
233 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100234 * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100235 *
236 * \param ctx MD4 context
237 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100238 *
239 * \warning MD4 is considered a weak message digest and its use
240 * constitutes a security risk. We recommend considering
241 * stronger message digests instead.
242 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100243 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000244MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
245 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100246
247/**
248 * \brief MD4 process data block (internal use only)
249 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100250 * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100251 *
252 * \param ctx MD4 context
253 * \param data buffer holding one block of data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100254 *
255 * \warning MD4 is considered a weak message digest and its use
256 * constitutes a security risk. We recommend considering
257 * stronger message digests instead.
258 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100259 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000260MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
261 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100262
263#undef MBEDTLS_DEPRECATED
264#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000265
Paul Bakker90995b52013-06-24 19:20:35 +0200266#ifdef __cplusplus
267}
268#endif
269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270#else /* MBEDTLS_MD4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200271#include "md4_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272#endif /* MBEDTLS_MD4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200273
274#ifdef __cplusplus
275extern "C" {
276#endif
277
Paul Bakker5121ce52009-01-03 21:22:43 +0000278/**
279 * \brief Output = MD4( input buffer )
280 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100281 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000282 * \param ilen length of the input data
283 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100284 *
285 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100286 *
287 * \warning MD4 is considered a weak message digest and its use
288 * constitutes a security risk. We recommend considering
289 * stronger message digests instead.
290 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000291 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100292int mbedtls_md4_ret( const unsigned char *input,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100293 size_t ilen,
294 unsigned char output[16] );
295
296#if !defined(MBEDTLS_DEPRECATED_REMOVED)
297#if defined(MBEDTLS_DEPRECATED_WARNING)
298#define MBEDTLS_DEPRECATED __attribute__((deprecated))
299#else
300#define MBEDTLS_DEPRECATED
301#endif
302/**
303 * \brief Output = MD4( input buffer )
304 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100305 * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100306 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100307 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000308 * \param ilen length of the input data
309 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100310 *
311 * \warning MD4 is considered a weak message digest and its use
312 * constitutes a security risk. We recommend considering
313 * stronger message digests instead.
314 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000315 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000316MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
317 size_t ilen,
318 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100319
320#undef MBEDTLS_DEPRECATED
321#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000322
323/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000324 * \brief Checkup routine
325 *
326 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100327 *
328 * \warning MD4 is considered a weak message digest and its use
329 * constitutes a security risk. We recommend considering
330 * stronger message digests instead.
331 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000332 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333int mbedtls_md4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000334
Paul Bakker5121ce52009-01-03 21:22:43 +0000335#ifdef __cplusplus
336}
337#endif
338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339#endif /* mbedtls_md4.h */