4 * \brief MD5 message digest algorithm (hash function)
6 * \warning MD5 is considered a weak message digest and its use constitutes a
7 * security risk. We recommend considering stronger message
11 * Copyright The Mbed TLS Contributors
12 * SPDX-License-Identifier: Apache-2.0
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
18 * http://www.apache.org/licenses/LICENSE-2.0
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.
29 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include "mbedtls/config.h"
32 #include MBEDTLS_CONFIG_FILE
38 /* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */
39 #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
45 #if !defined(MBEDTLS_MD5_ALT)
46 // Regular implementation
50 * \brief MD5 context structure
52 * \warning MD5 is considered a weak message digest and its use
53 * constitutes a security risk. We recommend considering
54 * stronger message digests instead.
57 typedef struct mbedtls_md5_context
{
58 uint32_t total
[2]; /*!< number of bytes processed */
59 uint32_t state
[4]; /*!< intermediate digest state */
60 unsigned char buffer
[64]; /*!< data block being processed */
64 #else /* MBEDTLS_MD5_ALT */
66 #endif /* MBEDTLS_MD5_ALT */
69 * \brief Initialize MD5 context
71 * \param ctx MD5 context to be initialized
73 * \warning MD5 is considered a weak message digest and its use
74 * constitutes a security risk. We recommend considering
75 * stronger message digests instead.
78 void mbedtls_md5_init(mbedtls_md5_context
*ctx
);
81 * \brief Clear MD5 context
83 * \param ctx MD5 context to be cleared
85 * \warning MD5 is considered a weak message digest and its use
86 * constitutes a security risk. We recommend considering
87 * stronger message digests instead.
90 void mbedtls_md5_free(mbedtls_md5_context
*ctx
);
93 * \brief Clone (the state of) an MD5 context
95 * \param dst The destination context
96 * \param src The context to be cloned
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.
103 void mbedtls_md5_clone(mbedtls_md5_context
*dst
,
104 const mbedtls_md5_context
*src
);
107 * \brief MD5 context setup
109 * \param ctx context to be initialized
111 * \return 0 if successful
113 * \warning MD5 is considered a weak message digest and its use
114 * constitutes a security risk. We recommend considering
115 * stronger message digests instead.
118 int mbedtls_md5_starts_ret(mbedtls_md5_context
*ctx
);
121 * \brief MD5 process buffer
123 * \param ctx MD5 context
124 * \param input buffer holding the data
125 * \param ilen length of the input data
127 * \return 0 if successful
129 * \warning MD5 is considered a weak message digest and its use
130 * constitutes a security risk. We recommend considering
131 * stronger message digests instead.
134 int mbedtls_md5_update_ret(mbedtls_md5_context
*ctx
,
135 const unsigned char *input
,
139 * \brief MD5 final digest
141 * \param ctx MD5 context
142 * \param output MD5 checksum result
144 * \return 0 if successful
146 * \warning MD5 is considered a weak message digest and its use
147 * constitutes a security risk. We recommend considering
148 * stronger message digests instead.
151 int mbedtls_md5_finish_ret(mbedtls_md5_context
*ctx
,
152 unsigned char output
[16]);
155 * \brief MD5 process data block (internal use only)
157 * \param ctx MD5 context
158 * \param data buffer holding one block of data
160 * \return 0 if successful
162 * \warning MD5 is considered a weak message digest and its use
163 * constitutes a security risk. We recommend considering
164 * stronger message digests instead.
167 int mbedtls_internal_md5_process(mbedtls_md5_context
*ctx
,
168 const unsigned char data
[64]);
170 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
171 #if defined(MBEDTLS_DEPRECATED_WARNING)
172 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
174 #define MBEDTLS_DEPRECATED
177 * \brief MD5 context setup
179 * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
181 * \param ctx context to be initialized
183 * \warning MD5 is considered a weak message digest and its use
184 * constitutes a security risk. We recommend considering
185 * stronger message digests instead.
188 MBEDTLS_DEPRECATED
void mbedtls_md5_starts(mbedtls_md5_context
*ctx
);
191 * \brief MD5 process buffer
193 * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
195 * \param ctx MD5 context
196 * \param input buffer holding the data
197 * \param ilen length of the input data
199 * \warning MD5 is considered a weak message digest and its use
200 * constitutes a security risk. We recommend considering
201 * stronger message digests instead.
204 MBEDTLS_DEPRECATED
void mbedtls_md5_update(mbedtls_md5_context
*ctx
,
205 const unsigned char *input
,
209 * \brief MD5 final digest
211 * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
213 * \param ctx MD5 context
214 * \param output MD5 checksum result
216 * \warning MD5 is considered a weak message digest and its use
217 * constitutes a security risk. We recommend considering
218 * stronger message digests instead.
221 MBEDTLS_DEPRECATED
void mbedtls_md5_finish(mbedtls_md5_context
*ctx
,
222 unsigned char output
[16]);
225 * \brief MD5 process data block (internal use only)
227 * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
229 * \param ctx MD5 context
230 * \param data buffer holding one block of data
232 * \warning MD5 is considered a weak message digest and its use
233 * constitutes a security risk. We recommend considering
234 * stronger message digests instead.
237 MBEDTLS_DEPRECATED
void mbedtls_md5_process(mbedtls_md5_context
*ctx
,
238 const unsigned char data
[64]);
240 #undef MBEDTLS_DEPRECATED
241 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
244 * \brief Output = MD5( input buffer )
246 * \param input buffer holding the data
247 * \param ilen length of the input data
248 * \param output MD5 checksum result
250 * \return 0 if successful
252 * \warning MD5 is considered a weak message digest and its use
253 * constitutes a security risk. We recommend considering
254 * stronger message digests instead.
257 int mbedtls_md5_ret(const unsigned char *input
,
259 unsigned char output
[16]);
261 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
262 #if defined(MBEDTLS_DEPRECATED_WARNING)
263 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
265 #define MBEDTLS_DEPRECATED
268 * \brief Output = MD5( input buffer )
270 * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
272 * \param input buffer holding the data
273 * \param ilen length of the input data
274 * \param output MD5 checksum result
276 * \warning MD5 is considered a weak message digest and its use
277 * constitutes a security risk. We recommend considering
278 * stronger message digests instead.
281 MBEDTLS_DEPRECATED
void mbedtls_md5(const unsigned char *input
,
283 unsigned char output
[16]);
285 #undef MBEDTLS_DEPRECATED
286 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
288 #if defined(MBEDTLS_SELF_TEST)
291 * \brief Checkup routine
293 * \return 0 if successful, or 1 if the test failed
295 * \warning MD5 is considered a weak message digest and its use
296 * constitutes a security risk. We recommend considering
297 * stronger message digests instead.
300 int mbedtls_md5_self_test(int verbose
);
302 #endif /* MBEDTLS_SELF_TEST */
308 #endif /* mbedtls_md5.h */