blob: 8ee4e5cabfe894d28acf324756d1454ee0103bfd [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)
Paul Bakker90995b52013-06-24 19:20:35 +020033#include "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
Rich Evans00ab4702015-02-06 13:43:58 +000038#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020039#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000040
Gilles Peskinea381fe82018-01-23 18:16:11 +010041#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
42
Paul Bakker407a0da2013-06-27 14:29:21 +020043#ifdef __cplusplus
44extern "C" {
45#endif
46
Ron Eldorb2aacec2017-05-18 16:53:08 +030047#if !defined(MBEDTLS_MD4_ALT)
48// Regular implementation
49//
50
Paul Bakker5121ce52009-01-03 21:22:43 +000051/**
52 * \brief MD4 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010053 *
54 * \warning MD4 is considered a weak message digest and its use
55 * constitutes a security risk. We recommend considering
56 * stronger message digests instead.
57 *
Paul Bakker5121ce52009-01-03 21:22:43 +000058 */
59typedef struct
60{
Paul Bakker5c2364c2012-10-01 14:41:15 +000061 uint32_t total[2]; /*!< number of bytes processed */
62 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000063 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000064}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065mbedtls_md4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000066
Ron Eldorb2aacec2017-05-18 16:53:08 +030067#else /* MBEDTLS_MD4_ALT */
68#include "md4_alt.h"
69#endif /* MBEDTLS_MD4_ALT */
70
Paul Bakker5121ce52009-01-03 21:22:43 +000071/**
Paul Bakker5b4af392014-06-26 12:09:34 +020072 * \brief Initialize MD4 context
73 *
74 * \param ctx MD4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010075 *
76 * \warning MD4 is considered a weak message digest and its use
77 * constitutes a security risk. We recommend considering
78 * stronger message digests instead.
79 *
Paul Bakker5b4af392014-06-26 12:09:34 +020080 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081void mbedtls_md4_init( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020082
83/**
84 * \brief Clear MD4 context
85 *
86 * \param ctx MD4 context to be cleared
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 *
Paul Bakker5b4af392014-06-26 12:09:34 +020092 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093void mbedtls_md4_free( mbedtls_md4_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020094
95/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020096 * \brief Clone (the state of) an MD4 context
97 *
98 * \param dst The destination context
99 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100100 *
101 * \warning MD4 is considered a weak message digest and its use
102 * constitutes a security risk. We recommend considering
103 * stronger message digests instead.
104 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200105 */
106void mbedtls_md4_clone( mbedtls_md4_context *dst,
107 const mbedtls_md4_context *src );
108
109/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 * \brief MD4 context setup
111 *
112 * \param ctx context to be initialized
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100113 *
114 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100115 *
116 * \warning MD4 is considered a weak message digest and its use
117 * constitutes a security risk. We recommend considering
118 * stronger message digests instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000119 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100120int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
122/**
123 * \brief MD4 process buffer
124 *
125 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100126 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 * \param ilen length of the input data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100128 *
129 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100130 *
131 * \warning MD4 is considered a weak message digest and its use
132 * constitutes a security risk. We recommend considering
133 * stronger message digests instead.
134 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000135 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100136int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100137 const unsigned char *input,
138 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000139
140/**
141 * \brief MD4 final digest
142 *
143 * \param ctx MD4 context
144 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100145 *
146 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100147 *
148 * \warning MD4 is considered a weak message digest and its use
149 * constitutes a security risk. We recommend considering
150 * stronger message digests instead.
151 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000152 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100153int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100154 unsigned char output[16] );
155
156/**
157 * \brief MD4 process data block (internal use only)
158 *
159 * \param ctx MD4 context
160 * \param data buffer holding one block of data
161 *
162 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100163 *
164 * \warning MD4 is considered a weak message digest and its use
165 * constitutes a security risk. We recommend considering
166 * stronger message digests instead.
167 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100168 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100169int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
170 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100171
172#if !defined(MBEDTLS_DEPRECATED_REMOVED)
173#if defined(MBEDTLS_DEPRECATED_WARNING)
174#define MBEDTLS_DEPRECATED __attribute__((deprecated))
175#else
176#define MBEDTLS_DEPRECATED
177#endif
178/**
179 * \brief MD4 context setup
180 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100181 * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100182 *
183 * \param ctx context to be initialized
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 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000190MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100191
192/**
193 * \brief MD4 process buffer
194 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100195 * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100196 *
197 * \param ctx MD4 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100198 * \param input buffer holding the data
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100199 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100200 *
201 * \warning MD4 is considered a weak message digest and its use
202 * constitutes a security risk. We recommend considering
203 * stronger message digests instead.
204 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100205 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000206MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
207 const unsigned char *input,
208 size_t ilen );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100209
210/**
211 * \brief MD4 final digest
212 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100213 * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100214 *
215 * \param ctx MD4 context
216 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100217 *
218 * \warning MD4 is considered a weak message digest and its use
219 * constitutes a security risk. We recommend considering
220 * stronger message digests instead.
221 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100222 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000223MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
224 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100225
226/**
227 * \brief MD4 process data block (internal use only)
228 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100229 * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100230 *
231 * \param ctx MD4 context
232 * \param data buffer holding one block of data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100233 *
234 * \warning MD4 is considered a weak message digest and its use
235 * constitutes a security risk. We recommend considering
236 * stronger message digests instead.
237 *
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100238 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000239MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
240 const unsigned char data[64] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100241
242#undef MBEDTLS_DEPRECATED
243#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000244
245/**
246 * \brief Output = MD4( input buffer )
247 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100248 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000249 * \param ilen length of the input data
250 * \param output MD4 checksum result
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100251 *
252 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100253 *
254 * \warning MD4 is considered a weak message digest and its use
255 * constitutes a security risk. We recommend considering
256 * stronger message digests instead.
257 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000258 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100259int mbedtls_md4_ret( const unsigned char *input,
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100260 size_t ilen,
261 unsigned char output[16] );
262
263#if !defined(MBEDTLS_DEPRECATED_REMOVED)
264#if defined(MBEDTLS_DEPRECATED_WARNING)
265#define MBEDTLS_DEPRECATED __attribute__((deprecated))
266#else
267#define MBEDTLS_DEPRECATED
268#endif
269/**
270 * \brief Output = MD4( input buffer )
271 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100272 * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100273 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100274 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000275 * \param ilen length of the input data
276 * \param output MD4 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100277 *
278 * \warning MD4 is considered a weak message digest and its use
279 * constitutes a security risk. We recommend considering
280 * stronger message digests instead.
281 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000282 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000283MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
284 size_t ilen,
285 unsigned char output[16] );
Andres Amaya Garciabee06352017-04-28 17:00:30 +0100286
287#undef MBEDTLS_DEPRECATED
288#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000289
290/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000291 * \brief Checkup routine
292 *
293 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100294 *
295 * \warning MD4 is considered a weak message digest and its use
296 * constitutes a security risk. We recommend considering
297 * stronger message digests instead.
298 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000299 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300int mbedtls_md4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000301
Paul Bakker5121ce52009-01-03 21:22:43 +0000302#ifdef __cplusplus
303}
304#endif
305
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306#endif /* mbedtls_md4.h */