Mbed OS Reference
Loading...
Searching...
No Matches
mbedtls/include/mbedtls/md5.h
Go to the documentation of this file.
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 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#ifndef MBEDTLS_MD5_H
27#define MBEDTLS_MD5_H
28
29#if !defined(MBEDTLS_CONFIG_FILE)
30#include "mbedtls/config.h"
31#else
32#include MBEDTLS_CONFIG_FILE
33#endif
34
35#include <stddef.h>
36#include <stdint.h>
37
38/**
39 * \ingroup mbedtls_md_module
40 * \{
41 */
42
43/* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */
44#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50#if !defined(MBEDTLS_MD5_ALT)
51// Regular implementation
52//
53
54/**
55 * \brief MD5 context structure
56 *
57 * \warning MD5 is considered a weak message digest and its use
58 * constitutes a security risk. We recommend considering
59 * stronger message digests instead.
60 *
61 */
62typedef struct mbedtls_md5_context
63{
64 uint32_t total[2]; /*!< number of bytes processed */
65 uint32_t state[4]; /*!< intermediate digest state */
66 unsigned char buffer[64]; /*!< data block being processed */
67}
69
70#else /* MBEDTLS_MD5_ALT */
71#include "md5_alt.h"
72#endif /* MBEDTLS_MD5_ALT */
73
74/**
75 * \brief Initialize MD5 context
76 *
77 * \param ctx MD5 context to be initialized
78 *
79 * \warning MD5 is considered a weak message digest and its use
80 * constitutes a security risk. We recommend considering
81 * stronger message digests instead.
82 *
83 */
85
86/**
87 * \brief Clear MD5 context
88 *
89 * \param ctx MD5 context to be cleared
90 *
91 * \warning MD5 is considered a weak message digest and its use
92 * constitutes a security risk. We recommend considering
93 * stronger message digests instead.
94 *
95 */
97
98/**
99 * \brief Clone (the state of) an MD5 context
100 *
101 * \param dst The destination context
102 * \param src The context to be cloned
103 *
104 * \warning MD5 is considered a weak message digest and its use
105 * constitutes a security risk. We recommend considering
106 * stronger message digests instead.
107 *
108 */
110 const mbedtls_md5_context *src );
111
112/**
113 * \brief MD5 context setup
114 *
115 * \param ctx context to be initialized
116 *
117 * \return 0 if successful
118 *
119 * \warning MD5 is considered a weak message digest and its use
120 * constitutes a security risk. We recommend considering
121 * stronger message digests instead.
122 *
123 */
125
126/**
127 * \brief MD5 process buffer
128 *
129 * \param ctx MD5 context
130 * \param input buffer holding the data
131 * \param ilen length of the input data
132 *
133 * \return 0 if successful
134 *
135 * \warning MD5 is considered a weak message digest and its use
136 * constitutes a security risk. We recommend considering
137 * stronger message digests instead.
138 *
139 */
141 const unsigned char *input,
142 size_t ilen );
143
144/**
145 * \brief MD5 final digest
146 *
147 * \param ctx MD5 context
148 * \param output MD5 checksum result
149 *
150 * \return 0 if successful
151 *
152 * \warning MD5 is considered a weak message digest and its use
153 * constitutes a security risk. We recommend considering
154 * stronger message digests instead.
155 *
156 */
158 unsigned char output[16] );
159
160/**
161 * \brief MD5 process data block (internal use only)
162 *
163 * \param ctx MD5 context
164 * \param data buffer holding one block of data
165 *
166 * \return 0 if successful
167 *
168 * \warning MD5 is considered a weak message digest and its use
169 * constitutes a security risk. We recommend considering
170 * stronger message digests instead.
171 *
172 */
174 const unsigned char data[64] );
175
176#if !defined(MBEDTLS_DEPRECATED_REMOVED)
177#if defined(MBEDTLS_DEPRECATED_WARNING)
178#define MBEDTLS_DEPRECATED __attribute__((deprecated))
179#else
180#define MBEDTLS_DEPRECATED
181#endif
182/**
183 * \brief MD5 context setup
184 *
185 * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
186 *
187 * \param ctx context to be initialized
188 *
189 * \warning MD5 is considered a weak message digest and its use
190 * constitutes a security risk. We recommend considering
191 * stronger message digests instead.
192 *
193 */
194MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
195
196/**
197 * \brief MD5 process buffer
198 *
199 * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
200 *
201 * \param ctx MD5 context
202 * \param input buffer holding the data
203 * \param ilen length of the input data
204 *
205 * \warning MD5 is considered a weak message digest and its use
206 * constitutes a security risk. We recommend considering
207 * stronger message digests instead.
208 *
209 */
210MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
211 const unsigned char *input,
212 size_t ilen );
213
214/**
215 * \brief MD5 final digest
216 *
217 * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
218 *
219 * \param ctx MD5 context
220 * \param output MD5 checksum result
221 *
222 * \warning MD5 is considered a weak message digest and its use
223 * constitutes a security risk. We recommend considering
224 * stronger message digests instead.
225 *
226 */
227MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
228 unsigned char output[16] );
229
230/**
231 * \brief MD5 process data block (internal use only)
232 *
233 * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
234 *
235 * \param ctx MD5 context
236 * \param data buffer holding one block of data
237 *
238 * \warning MD5 is considered a weak message digest and its use
239 * constitutes a security risk. We recommend considering
240 * stronger message digests instead.
241 *
242 */
243MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
244 const unsigned char data[64] );
245
246#undef MBEDTLS_DEPRECATED
247#endif /* !MBEDTLS_DEPRECATED_REMOVED */
248
249/**
250 * \brief Output = MD5( input buffer )
251 *
252 * \param input buffer holding the data
253 * \param ilen length of the input data
254 * \param output MD5 checksum result
255 *
256 * \return 0 if successful
257 *
258 * \warning MD5 is considered a weak message digest and its use
259 * constitutes a security risk. We recommend considering
260 * stronger message digests instead.
261 *
262 */
263int mbedtls_md5_ret( const unsigned char *input,
264 size_t ilen,
265 unsigned char output[16] );
266
267#if !defined(MBEDTLS_DEPRECATED_REMOVED)
268#if defined(MBEDTLS_DEPRECATED_WARNING)
269#define MBEDTLS_DEPRECATED __attribute__((deprecated))
270#else
271#define MBEDTLS_DEPRECATED
272#endif
273/**
274 * \brief Output = MD5( input buffer )
275 *
276 * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
277 *
278 * \param input buffer holding the data
279 * \param ilen length of the input data
280 * \param output MD5 checksum result
281 *
282 * \warning MD5 is considered a weak message digest and its use
283 * constitutes a security risk. We recommend considering
284 * stronger message digests instead.
285 *
286 */
287MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
288 size_t ilen,
289 unsigned char output[16] );
290
291#undef MBEDTLS_DEPRECATED
292#endif /* !MBEDTLS_DEPRECATED_REMOVED */
293
294#if defined(MBEDTLS_SELF_TEST)
295
296/**
297 * \brief Checkup routine
298 *
299 * \return 0 if successful, or 1 if the test failed
300 *
301 * \warning MD5 is considered a weak message digest and its use
302 * constitutes a security risk. We recommend considering
303 * stronger message digests instead.
304 *
305 */
306int mbedtls_md5_self_test( int verbose );
307
308#endif /* MBEDTLS_SELF_TEST */
309
310#ifdef __cplusplus
311}
312#endif
313
314/// \}
315
316#endif /* mbedtls_md5.h */
Configuration options (set of defines)
void mbedtls_md5_starts(mbedtls_md5_context *ctx)
MD5 context setup.
void mbedtls_md5(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD5( input buffer )
void mbedtls_md5_clone(mbedtls_md5_context *dst, const mbedtls_md5_context *src)
Clone (the state of) an MD5 context.
int mbedtls_internal_md5_process(mbedtls_md5_context *ctx, const unsigned char data[64])
MD5 process data block (internal use only)
void mbedtls_md5_process(mbedtls_md5_context *ctx, const unsigned char data[64])
MD5 process data block (internal use only)
void mbedtls_md5_free(mbedtls_md5_context *ctx)
Clear MD5 context.
int mbedtls_md5_ret(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD5( input buffer )
int mbedtls_md5_starts_ret(mbedtls_md5_context *ctx)
MD5 context setup.
void mbedtls_md5_finish(mbedtls_md5_context *ctx, unsigned char output[16])
MD5 final digest.
void mbedtls_md5_init(mbedtls_md5_context *ctx)
Initialize MD5 context.
int mbedtls_md5_update_ret(mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 process buffer.
void mbedtls_md5_update(mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 process buffer.
int mbedtls_md5_finish_ret(mbedtls_md5_context *ctx, unsigned char output[16])
MD5 final digest.
MD5 message digest algorithm (hash function)
MD5 context structure.