blob: e101014cbffc1765e9dc40e94460a61f6a0141be [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +020011 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000026 * This file is part of mbed TLS (https://tls.mbed.org)
Hanno Beckerbbca8c52017-09-25 14:53:51 +010027 *
Paul Bakker5121ce52009-01-03 21:22:43 +000028 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#ifndef MBEDTLS_MD4_H
30#define MBEDTLS_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero203fdf72019-07-04 20:01:14 +010033#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020036#endif
Paul Bakker90995b52013-06-24 19:20:35 +020037
Jaeden Amero59ebddf2019-07-10 11:03:03 +010038#include "mbedtls/platform_util.h"
39
Rich Evans00ab4702015-02-06 13:43:58 +000040#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020041#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000042
Ron Eldor9924bdc2018-10-04 10:59:13 +030043/* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea381fe82018-01-23 18:16:11 +010044#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
45
Paul Bakker407a0da2013-06-27 14:29:21 +020046#ifdef __cplusplus
47extern "C" {
48#endif
49
Ron Eldorb2aacec2017-05-18 16:53:08 +030050#if !defined(MBEDTLS_MD4_ALT)
51// Regular implementation
52//
53
Paul Bakker5121ce52009-01-03 21:22:43 +000054/**
55 * \brief MD4 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010056 *
57 * \warning MD4 is considered a weak message digest and its use
58 * constitutes a security risk. We recommend considering
59 * stronger message digests instead.
60 *
Paul Bakker5121ce52009-01-03 21:22:43 +000061 */
Dawid Drozd428cc522018-07-24 10:02:47 +020062typedef struct mbedtls_md4_context
Paul Bakker5121ce52009-01-03 21:22:43 +000063{
Paul Bakker5c2364c2012-10-01 14:41:15 +000064 uint32_t total[2]; /*!< number of bytes processed */
65 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000066 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000067}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068mbedtls_md4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000069
Ron Eldorb2aacec2017-05-18 16:53:08 +030070#else /* MBEDTLS_MD4_ALT */
71#include "md4_alt.h"
72#endif /* MBEDTLS_MD4_ALT */
73
Paul Bakker5121ce52009-01-03 21:22:43 +000074/**
Paul Bakker5b4af392014-06-26 12:09:34 +020075 * \brief Initialize MD4 context
76 *
77 * \param ctx MD4 context to be initialized
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 Bakker5b4af392014-06-26 12:09:34 +020083 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084void mbedtls_md4_init( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020085
86/**
87 * \brief Clear MD4 context
88 *
89 * \param ctx MD4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010090 *
91 * \warning MD4 is considered a weak message digest and its use
92 * constitutes a security risk. We recommend considering
93 * stronger message digests instead.
94 *
Paul Bakker5b4af392014-06-26 12:09:34 +020095 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096void mbedtls_md4_free( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020097
98/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020099 * \brief Clone (the state of) an MD4 context
100 *
101 * \param dst The destination context
102 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100103 *
104 * \warning MD4 is considered a weak message digest and its use
105 * constitutes a security risk. We recommend considering
106 * stronger message digests instead.
107 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200108 */
109void mbedtls_md4_clone( mbedtls_md4_context *dst,
110 const mbedtls_md4_context *src );
111
112/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000113 * \brief MD4 context setup
114 *
115 * \param ctx context to be initialized
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100116 *
117 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100118 *
119 * \warning MD4 is considered a weak message digest and its use
120 * constitutes a security risk. We recommend considering
121 * stronger message digests instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000122 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100123int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000124
125/**
126 * \brief MD4 process buffer
127 *
128 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100129 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 * \param ilen length of the input data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100131 *
132 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100133 *
134 * \warning MD4 is considered a weak message digest and its use
135 * constitutes a security risk. We recommend considering
136 * stronger message digests instead.
137 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100139int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100140 const unsigned char *input,
141 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000142
143/**
144 * \brief MD4 final digest
145 *
146 * \param ctx MD4 context
147 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100148 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000155 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100156int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100157 unsigned char output[16] );
158
159/**
160 * \brief MD4 process data block (internal use only)
161 *
162 * \param ctx MD4 context
163 * \param data buffer holding one block of data
164 *
165 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100166 *
167 * \warning MD4 is considered a weak message digest and its use
168 * constitutes a security risk. We recommend considering
169 * stronger message digests instead.
170 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100171 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100172int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
173 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100174
175#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100176/**
177 * \brief MD4 context setup
178 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100179 * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100180 *
181 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100182 *
183 * \warning MD4 is considered a weak message digest and its use
184 * constitutes a security risk. We recommend considering
185 * stronger message digests instead.
186 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100187 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000188MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100189
190/**
191 * \brief MD4 process buffer
192 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100193 * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100194 *
195 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100196 * \param input buffer holding the data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100197 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100198 *
199 * \warning MD4 is considered a weak message digest and its use
200 * constitutes a security risk. We recommend considering
201 * stronger message digests instead.
202 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100203 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000204MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
205 const unsigned char *input,
206 size_t ilen );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100207
208/**
209 * \brief MD4 final digest
210 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100211 * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100212 *
213 * \param ctx MD4 context
214 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100215 *
216 * \warning MD4 is considered a weak message digest and its use
217 * constitutes a security risk. We recommend considering
218 * stronger message digests instead.
219 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100220 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000221MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
222 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100223
224/**
225 * \brief MD4 process data block (internal use only)
226 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100227 * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100228 *
229 * \param ctx MD4 context
230 * \param data buffer holding one block of data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100231 *
232 * \warning MD4 is considered a weak message digest and its use
233 * constitutes a security risk. We recommend considering
234 * stronger message digests instead.
235 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100236 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000237MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
238 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100239
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100240#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000241
242/**
243 * \brief Output = MD4( input buffer )
244 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100245 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000246 * \param ilen length of the input data
247 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100248 *
249 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100250 *
251 * \warning MD4 is considered a weak message digest and its use
252 * constitutes a security risk. We recommend considering
253 * stronger message digests instead.
254 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000255 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100256int mbedtls_md4_ret( const unsigned char *input,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100257 size_t ilen,
258 unsigned char output[16] );
259
260#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100261/**
262 * \brief Output = MD4( input buffer )
263 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100264 * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100265 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100266 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 * \param ilen length of the input data
268 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100269 *
270 * \warning MD4 is considered a weak message digest and its use
271 * constitutes a security risk. We recommend considering
272 * stronger message digests instead.
273 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000274 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000275MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
276 size_t ilen,
277 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100278
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100279#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000280
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500281#if defined(MBEDTLS_SELF_TEST)
282
Paul Bakker5121ce52009-01-03 21:22:43 +0000283/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000284 * \brief Checkup routine
285 *
286 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100287 *
288 * \warning MD4 is considered a weak message digest and its use
289 * constitutes a security risk. We recommend considering
290 * stronger message digests instead.
291 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000292 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293int mbedtls_md4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000294
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500295#endif /* MBEDTLS_SELF_TEST */
296
Paul Bakker5121ce52009-01-03 21:22:43 +0000297#ifdef __cplusplus
298}
299#endif
300
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301#endif /* mbedtls_md4.h */