1 /**
2  * \file md4.h
3  *
4  * \brief MD4 message digest algorithm (hash function)
5  *
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.
9  */
10 /*
11  *  Copyright The Mbed TLS Contributors
12  *  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.
25  *
26  */
27 #ifndef MBEDTLS_MD4_H
28 #define MBEDTLS_MD4_H
29 
30 #if !defined(MBEDTLS_CONFIG_FILE)
31 #include "mbedtls/config.h"
32 #else
33 #include MBEDTLS_CONFIG_FILE
34 #endif
35 
36 #include <stddef.h>
37 #include <stdint.h>
38 
39 /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
40 #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED                   -0x002D  /**< MD4 hardware accelerator failed */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #if !defined(MBEDTLS_MD4_ALT)
47 // Regular implementation
48 //
49 
50 /**
51  * \brief          MD4 context structure
52  *
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  *
57  */
58 typedef struct mbedtls_md4_context
59 {
60     uint32_t total[2];          /*!< number of bytes processed  */
61     uint32_t state[4];          /*!< intermediate digest state  */
62     unsigned char buffer[64];   /*!< data block being processed */
63 }
64 mbedtls_md4_context;
65 
66 #else  /* MBEDTLS_MD4_ALT */
67 #include "md4_alt.h"
68 #endif /* MBEDTLS_MD4_ALT */
69 
70 /**
71  * \brief          Initialize MD4 context
72  *
73  * \param ctx      MD4 context to be initialized
74  *
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  *
79  */
80 void mbedtls_md4_init( mbedtls_md4_context *ctx );
81 
82 /**
83  * \brief          Clear MD4 context
84  *
85  * \param ctx      MD4 context to be cleared
86  *
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  *
91  */
92 void mbedtls_md4_free( mbedtls_md4_context *ctx );
93 
94 /**
95  * \brief          Clone (the state of) an MD4 context
96  *
97  * \param dst      The destination context
98  * \param src      The context to be cloned
99  *
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  *
104  */
105 void mbedtls_md4_clone( mbedtls_md4_context *dst,
106                         const mbedtls_md4_context *src );
107 
108 /**
109  * \brief          MD4 context setup
110  *
111  * \param ctx      context to be initialized
112  *
113  * \return         0 if successful
114  *
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.
118  */
119 int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
120 
121 /**
122  * \brief          MD4 process buffer
123  *
124  * \param ctx      MD4 context
125  * \param input    buffer holding the data
126  * \param ilen     length of the input data
127  *
128  * \return         0 if successful
129  *
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  *
134  */
135 int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
136                             const unsigned char *input,
137                             size_t ilen );
138 
139 /**
140  * \brief          MD4 final digest
141  *
142  * \param ctx      MD4 context
143  * \param output   MD4 checksum result
144  *
145  * \return         0 if successful
146  *
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  *
151  */
152 int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
153                             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
162  *
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  *
167  */
168 int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
169                                   const unsigned char data[64] );
170 
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  *
180  * \deprecated     Superseded by mbedtls_md4_starts_ret() in 2.7.0
181  *
182  * \param ctx      context to be initialized
183  *
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  *
188  */
189 MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
190 
191 /**
192  * \brief          MD4 process buffer
193  *
194  * \deprecated     Superseded by mbedtls_md4_update_ret() in 2.7.0
195  *
196  * \param ctx      MD4 context
197  * \param input    buffer holding the data
198  * \param ilen     length of the input data
199  *
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  *
204  */
205 MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
206                                             const unsigned char *input,
207                                             size_t ilen );
208 
209 /**
210  * \brief          MD4 final digest
211  *
212  * \deprecated     Superseded by mbedtls_md4_finish_ret() in 2.7.0
213  *
214  * \param ctx      MD4 context
215  * \param output   MD4 checksum result
216  *
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  *
221  */
222 MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
223                                             unsigned char output[16] );
224 
225 /**
226  * \brief          MD4 process data block (internal use only)
227  *
228  * \deprecated     Superseded by mbedtls_internal_md4_process() in 2.7.0
229  *
230  * \param ctx      MD4 context
231  * \param data     buffer holding one block of data
232  *
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  *
237  */
238 MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
239                                              const unsigned char data[64] );
240 
241 #undef MBEDTLS_DEPRECATED
242 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
243 
244 /**
245  * \brief          Output = MD4( input buffer )
246  *
247  * \param input    buffer holding the data
248  * \param ilen     length of the input data
249  * \param output   MD4 checksum result
250  *
251  * \return         0 if successful
252  *
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  *
257  */
258 int mbedtls_md4_ret( const unsigned char *input,
259                      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  *
271  * \deprecated     Superseded by mbedtls_md4_ret() in 2.7.0
272  *
273  * \param input    buffer holding the data
274  * \param ilen     length of the input data
275  * \param output   MD4 checksum result
276  *
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  *
281  */
282 MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
283                                      size_t ilen,
284                                      unsigned char output[16] );
285 
286 #undef MBEDTLS_DEPRECATED
287 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
288 
289 #if defined(MBEDTLS_SELF_TEST)
290 
291 /**
292  * \brief          Checkup routine
293  *
294  * \return         0 if successful, or 1 if the test failed
295  *
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  *
300  */
301 int mbedtls_md4_self_test( int verbose );
302 
303 #endif /* MBEDTLS_SELF_TEST */
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 
309 #endif /* mbedtls_md4.h */
310