xref: /reactos/sdk/include/reactos/libs/mbedtls/md5.h (revision b5218987)
1 /**
2  * \file md5.h
3  *
4  * \brief MD5 message digest algorithm (hash function)
5  *
6  * \warning   MD5 is considered a weak message digest and its use constitutes a
7  *            security risk. We recommend considering stronger message
8  *            digests instead.
9  */
10 /*
11  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
12  *  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:
19  *
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.
31  *
32  *  **********
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  *
53  *  This file is part of mbed TLS (https://tls.mbed.org)
54  */
55 #ifndef MBEDTLS_MD5_H
56 #define MBEDTLS_MD5_H
57 
58 #if !defined(MBEDTLS_CONFIG_FILE)
59 #include "config.h"
60 #else
61 #include MBEDTLS_CONFIG_FILE
62 #endif
63 
64 #include <stddef.h>
65 #include <stdint.h>
66 
67 #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED                   -0x002F  /**< MD5 hardware accelerator failed */
68 
69 #if !defined(MBEDTLS_MD5_ALT)
70 // Regular implementation
71 //
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 /**
78  * \brief          MD5 context structure
79  *
80  * \warning        MD5 is considered a weak message digest and its use
81  *                 constitutes a security risk. We recommend considering
82  *                 stronger message digests instead.
83  *
84  */
85 typedef struct
86 {
87     uint32_t total[2];          /*!< number of bytes processed  */
88     uint32_t state[4];          /*!< intermediate digest state  */
89     unsigned char buffer[64];   /*!< data block being processed */
90 }
91 mbedtls_md5_context;
92 
93 /**
94  * \brief          Initialize MD5 context
95  *
96  * \param ctx      MD5 context to be initialized
97  *
98  * \warning        MD5 is considered a weak message digest and its use
99  *                 constitutes a security risk. We recommend considering
100  *                 stronger message digests instead.
101  *
102  */
103 void mbedtls_md5_init( mbedtls_md5_context *ctx );
104 
105 /**
106  * \brief          Clear MD5 context
107  *
108  * \param ctx      MD5 context to be cleared
109  *
110  * \warning        MD5 is considered a weak message digest and its use
111  *                 constitutes a security risk. We recommend considering
112  *                 stronger message digests instead.
113  *
114  */
115 void mbedtls_md5_free( mbedtls_md5_context *ctx );
116 
117 /**
118  * \brief          Clone (the state of) an MD5 context
119  *
120  * \param dst      The destination context
121  * \param src      The context to be cloned
122  *
123  * \warning        MD5 is considered a weak message digest and its use
124  *                 constitutes a security risk. We recommend considering
125  *                 stronger message digests instead.
126  *
127  */
128 void mbedtls_md5_clone( mbedtls_md5_context *dst,
129                         const mbedtls_md5_context *src );
130 
131 /**
132  * \brief          MD5 context setup
133  *
134  * \param ctx      context to be initialized
135  *
136  * \return         0 if successful
137  *
138  * \warning        MD5 is considered a weak message digest and its use
139  *                 constitutes a security risk. We recommend considering
140  *                 stronger message digests instead.
141  *
142  */
143 int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
144 
145 /**
146  * \brief          MD5 process buffer
147  *
148  * \param ctx      MD5 context
149  * \param input    buffer holding the data
150  * \param ilen     length of the input data
151  *
152  * \return         0 if successful
153  *
154  * \warning        MD5 is considered a weak message digest and its use
155  *                 constitutes a security risk. We recommend considering
156  *                 stronger message digests instead.
157  *
158  */
159 int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
160                             const unsigned char *input,
161                             size_t ilen );
162 
163 /**
164  * \brief          MD5 final digest
165  *
166  * \param ctx      MD5 context
167  * \param output   MD5 checksum result
168  *
169  * \return         0 if successful
170  *
171  * \warning        MD5 is considered a weak message digest and its use
172  *                 constitutes a security risk. We recommend considering
173  *                 stronger message digests instead.
174  *
175  */
176 int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
177                             unsigned char output[16] );
178 
179 /**
180  * \brief          MD5 process data block (internal use only)
181  *
182  * \param ctx      MD5 context
183  * \param data     buffer holding one block of data
184  *
185  * \return         0 if successful
186  *
187  * \warning        MD5 is considered a weak message digest and its use
188  *                 constitutes a security risk. We recommend considering
189  *                 stronger message digests instead.
190  *
191  */
192 int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
193                                   const unsigned char data[64] );
194 
195 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
196 #if defined(MBEDTLS_DEPRECATED_WARNING)
197 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
198 #else
199 #define MBEDTLS_DEPRECATED
200 #endif
201 /**
202  * \brief          MD5 context setup
203  *
204  * \deprecated     Superseded by mbedtls_md5_starts_ret() in 2.7.0
205  *
206  * \param ctx      context to be initialized
207  *
208  * \warning        MD5 is considered a weak message digest and its use
209  *                 constitutes a security risk. We recommend considering
210  *                 stronger message digests instead.
211  *
212  */
213 MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
214 
215 /**
216  * \brief          MD5 process buffer
217  *
218  * \deprecated     Superseded by mbedtls_md5_update_ret() in 2.7.0
219  *
220  * \param ctx      MD5 context
221  * \param input    buffer holding the data
222  * \param ilen     length of the input data
223  *
224  * \warning        MD5 is considered a weak message digest and its use
225  *                 constitutes a security risk. We recommend considering
226  *                 stronger message digests instead.
227  *
228  */
229 MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
230                                             const unsigned char *input,
231                                             size_t ilen );
232 
233 /**
234  * \brief          MD5 final digest
235  *
236  * \deprecated     Superseded by mbedtls_md5_finish_ret() in 2.7.0
237  *
238  * \param ctx      MD5 context
239  * \param output   MD5 checksum result
240  *
241  * \warning        MD5 is considered a weak message digest and its use
242  *                 constitutes a security risk. We recommend considering
243  *                 stronger message digests instead.
244  *
245  */
246 MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
247                                             unsigned char output[16] );
248 
249 /**
250  * \brief          MD5 process data block (internal use only)
251  *
252  * \deprecated     Superseded by mbedtls_internal_md5_process() in 2.7.0
253  *
254  * \param ctx      MD5 context
255  * \param data     buffer holding one block of data
256  *
257  * \warning        MD5 is considered a weak message digest and its use
258  *                 constitutes a security risk. We recommend considering
259  *                 stronger message digests instead.
260  *
261  */
262 MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
263                                              const unsigned char data[64] );
264 
265 #undef MBEDTLS_DEPRECATED
266 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 #else  /* MBEDTLS_MD5_ALT */
273 #include "md5_alt.h"
274 #endif /* MBEDTLS_MD5_ALT */
275 
276 #ifdef __cplusplus
277 extern "C" {
278 #endif
279 
280 /**
281  * \brief          Output = MD5( input buffer )
282  *
283  * \param input    buffer holding the data
284  * \param ilen     length of the input data
285  * \param output   MD5 checksum result
286  *
287  * \return         0 if successful
288  *
289  * \warning        MD5 is considered a weak message digest and its use
290  *                 constitutes a security risk. We recommend considering
291  *                 stronger message digests instead.
292  *
293  */
294 int mbedtls_md5_ret( const unsigned char *input,
295                      size_t ilen,
296                      unsigned char output[16] );
297 
298 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
299 #if defined(MBEDTLS_DEPRECATED_WARNING)
300 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
301 #else
302 #define MBEDTLS_DEPRECATED
303 #endif
304 /**
305  * \brief          Output = MD5( input buffer )
306  *
307  * \deprecated     Superseded by mbedtls_md5_ret() in 2.7.0
308  *
309  * \param input    buffer holding the data
310  * \param ilen     length of the input data
311  * \param output   MD5 checksum result
312  *
313  * \warning        MD5 is considered a weak message digest and its use
314  *                 constitutes a security risk. We recommend considering
315  *                 stronger message digests instead.
316  *
317  */
318 MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
319                                      size_t ilen,
320                                      unsigned char output[16] );
321 
322 #undef MBEDTLS_DEPRECATED
323 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
324 
325 /**
326  * \brief          Checkup routine
327  *
328  * \return         0 if successful, or 1 if the test failed
329  *
330  * \warning        MD5 is considered a weak message digest and its use
331  *                 constitutes a security risk. We recommend considering
332  *                 stronger message digests instead.
333  *
334  */
335 int mbedtls_md5_self_test( int verbose );
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 
341 #endif /* mbedtls_md5.h */
342