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 /** MD4 hardware accelerator failed */
41 #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED                   -0x002D
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #if !defined(MBEDTLS_MD4_ALT)
48 // Regular implementation
49 //
50 
51 /**
52  * \brief          MD4 context structure
53  *
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  *
58  */
59 typedef struct mbedtls_md4_context
60 {
61     uint32_t total[2];          /*!< number of bytes processed  */
62     uint32_t state[4];          /*!< intermediate digest state  */
63     unsigned char buffer[64];   /*!< data block being processed */
64 }
65 mbedtls_md4_context;
66 
67 #else  /* MBEDTLS_MD4_ALT */
68 #include "md4_alt.h"
69 #endif /* MBEDTLS_MD4_ALT */
70 
71 /**
72  * \brief          Initialize MD4 context
73  *
74  * \param ctx      MD4 context to be initialized
75  *
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  *
80  */
81 void mbedtls_md4_init( mbedtls_md4_context *ctx );
82 
83 /**
84  * \brief          Clear MD4 context
85  *
86  * \param ctx      MD4 context to be cleared
87  *
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  *
92  */
93 void mbedtls_md4_free( mbedtls_md4_context *ctx );
94 
95 /**
96  * \brief          Clone (the state of) an MD4 context
97  *
98  * \param dst      The destination context
99  * \param src      The context to be cloned
100  *
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  *
105  */
106 void mbedtls_md4_clone( mbedtls_md4_context *dst,
107                         const mbedtls_md4_context *src );
108 
109 /**
110  * \brief          MD4 context setup
111  *
112  * \param ctx      context to be initialized
113  *
114  * \return         0 if successful
115  *
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.
119  */
120 int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
121 
122 /**
123  * \brief          MD4 process buffer
124  *
125  * \param ctx      MD4 context
126  * \param input    buffer holding the data
127  * \param ilen     length of the input data
128  *
129  * \return         0 if successful
130  *
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  *
135  */
136 int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
137                             const unsigned char *input,
138                             size_t ilen );
139 
140 /**
141  * \brief          MD4 final digest
142  *
143  * \param ctx      MD4 context
144  * \param output   MD4 checksum result
145  *
146  * \return         0 if successful
147  *
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  *
152  */
153 int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
154                             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
163  *
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  *
168  */
169 int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
170                                   const unsigned char data[64] );
171 
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  *
181  * \deprecated     Superseded by mbedtls_md4_starts_ret() in 2.7.0
182  *
183  * \param ctx      context to be initialized
184  *
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  *
189  */
190 MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
191 
192 /**
193  * \brief          MD4 process buffer
194  *
195  * \deprecated     Superseded by mbedtls_md4_update_ret() in 2.7.0
196  *
197  * \param ctx      MD4 context
198  * \param input    buffer holding the data
199  * \param ilen     length of the input data
200  *
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  *
205  */
206 MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
207                                             const unsigned char *input,
208                                             size_t ilen );
209 
210 /**
211  * \brief          MD4 final digest
212  *
213  * \deprecated     Superseded by mbedtls_md4_finish_ret() in 2.7.0
214  *
215  * \param ctx      MD4 context
216  * \param output   MD4 checksum result
217  *
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  *
222  */
223 MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
224                                             unsigned char output[16] );
225 
226 /**
227  * \brief          MD4 process data block (internal use only)
228  *
229  * \deprecated     Superseded by mbedtls_internal_md4_process() in 2.7.0
230  *
231  * \param ctx      MD4 context
232  * \param data     buffer holding one block of data
233  *
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  *
238  */
239 MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
240                                              const unsigned char data[64] );
241 
242 #undef MBEDTLS_DEPRECATED
243 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
244 
245 /**
246  * \brief          Output = MD4( input buffer )
247  *
248  * \param input    buffer holding the data
249  * \param ilen     length of the input data
250  * \param output   MD4 checksum result
251  *
252  * \return         0 if successful
253  *
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  *
258  */
259 int mbedtls_md4_ret( const unsigned char *input,
260                      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  *
272  * \deprecated     Superseded by mbedtls_md4_ret() in 2.7.0
273  *
274  * \param input    buffer holding the data
275  * \param ilen     length of the input data
276  * \param output   MD4 checksum result
277  *
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  *
282  */
283 MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
284                                      size_t ilen,
285                                      unsigned char output[16] );
286 
287 #undef MBEDTLS_DEPRECATED
288 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
289 
290 #if defined(MBEDTLS_SELF_TEST)
291 
292 /**
293  * \brief          Checkup routine
294  *
295  * \return         0 if successful, or 1 if the test failed
296  *
297  * \warning        MD4 is considered a weak message digest and its use
298  *                 constitutes a security risk. We recommend considering
299  *                 stronger message digests instead.
300  *
301  */
302 int mbedtls_md4_self_test( int verbose );
303 
304 #endif /* MBEDTLS_SELF_TEST */
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 
310 #endif /* mbedtls_md4.h */
311