blob: 8d245810060e6f1babbf58caa955ddbf6cdc0595 [file] [log] [blame]
Jaeden Ameroe54e6932018-08-06 16:19:58 +01001/**
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
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 * This file is part of Mbed Crypto (https://tls.mbed.org)
27 */
28#ifndef MBEDCRYPTO_MD5_H
29#define MBEDCRYPTO_MD5_H
30
31#if !defined(MBEDCRYPTO_CONFIG_FILE)
32#include "config.h"
33#else
34#include MBEDCRYPTO_CONFIG_FILE
35#endif
36
37#include <stddef.h>
38#include <stdint.h>
39
40#define MBEDCRYPTO_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#if !defined(MBEDCRYPTO_MD5_ALT)
47// Regular implementation
48//
49
50/**
51 * \brief MD5 context structure
52 *
53 * \warning MD5 is considered a weak message digest and its use
54 * constitutes a security risk. We recommend considering
55 * stronger message digests instead.
56 *
57 */
58typedef struct
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}
64mbedcrypto_md5_context;
65
66#else /* MBEDCRYPTO_MD5_ALT */
67#include "md5_alt.h"
68#endif /* MBEDCRYPTO_MD5_ALT */
69
70/**
71 * \brief Initialize MD5 context
72 *
73 * \param ctx MD5 context to be initialized
74 *
75 * \warning MD5 is considered a weak message digest and its use
76 * constitutes a security risk. We recommend considering
77 * stronger message digests instead.
78 *
79 */
80void mbedcrypto_md5_init( mbedcrypto_md5_context *ctx );
81
82/**
83 * \brief Clear MD5 context
84 *
85 * \param ctx MD5 context to be cleared
86 *
87 * \warning MD5 is considered a weak message digest and its use
88 * constitutes a security risk. We recommend considering
89 * stronger message digests instead.
90 *
91 */
92void mbedcrypto_md5_free( mbedcrypto_md5_context *ctx );
93
94/**
95 * \brief Clone (the state of) an MD5 context
96 *
97 * \param dst The destination context
98 * \param src The context to be cloned
99 *
100 * \warning MD5 is considered a weak message digest and its use
101 * constitutes a security risk. We recommend considering
102 * stronger message digests instead.
103 *
104 */
105void mbedcrypto_md5_clone( mbedcrypto_md5_context *dst,
106 const mbedcrypto_md5_context *src );
107
108/**
109 * \brief MD5 context setup
110 *
111 * \param ctx context to be initialized
112 *
113 * \return 0 if successful
114 *
115 * \warning MD5 is considered a weak message digest and its use
116 * constitutes a security risk. We recommend considering
117 * stronger message digests instead.
118 *
119 */
120int mbedcrypto_md5_starts_ret( mbedcrypto_md5_context *ctx );
121
122/**
123 * \brief MD5 process buffer
124 *
125 * \param ctx MD5 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 MD5 is considered a weak message digest and its use
132 * constitutes a security risk. We recommend considering
133 * stronger message digests instead.
134 *
135 */
136int mbedcrypto_md5_update_ret( mbedcrypto_md5_context *ctx,
137 const unsigned char *input,
138 size_t ilen );
139
140/**
141 * \brief MD5 final digest
142 *
143 * \param ctx MD5 context
144 * \param output MD5 checksum result
145 *
146 * \return 0 if successful
147 *
148 * \warning MD5 is considered a weak message digest and its use
149 * constitutes a security risk. We recommend considering
150 * stronger message digests instead.
151 *
152 */
153int mbedcrypto_md5_finish_ret( mbedcrypto_md5_context *ctx,
154 unsigned char output[16] );
155
156/**
157 * \brief MD5 process data block (internal use only)
158 *
159 * \param ctx MD5 context
160 * \param data buffer holding one block of data
161 *
162 * \return 0 if successful
163 *
164 * \warning MD5 is considered a weak message digest and its use
165 * constitutes a security risk. We recommend considering
166 * stronger message digests instead.
167 *
168 */
169int mbedcrypto_internal_md5_process( mbedcrypto_md5_context *ctx,
170 const unsigned char data[64] );
171
172#if !defined(MBEDCRYPTO_DEPRECATED_REMOVED)
173#if defined(MBEDCRYPTO_DEPRECATED_WARNING)
174#define MBEDCRYPTO_DEPRECATED __attribute__((deprecated))
175#else
176#define MBEDCRYPTO_DEPRECATED
177#endif
178/**
179 * \brief MD5 context setup
180 *
181 * \deprecated Superseded by mbedcrypto_md5_starts_ret() in 2.7.0
182 *
183 * \param ctx context to be initialized
184 *
185 * \warning MD5 is considered a weak message digest and its use
186 * constitutes a security risk. We recommend considering
187 * stronger message digests instead.
188 *
189 */
190MBEDCRYPTO_DEPRECATED void mbedcrypto_md5_starts( mbedcrypto_md5_context *ctx );
191
192/**
193 * \brief MD5 process buffer
194 *
195 * \deprecated Superseded by mbedcrypto_md5_update_ret() in 2.7.0
196 *
197 * \param ctx MD5 context
198 * \param input buffer holding the data
199 * \param ilen length of the input data
200 *
201 * \warning MD5 is considered a weak message digest and its use
202 * constitutes a security risk. We recommend considering
203 * stronger message digests instead.
204 *
205 */
206MBEDCRYPTO_DEPRECATED void mbedcrypto_md5_update( mbedcrypto_md5_context *ctx,
207 const unsigned char *input,
208 size_t ilen );
209
210/**
211 * \brief MD5 final digest
212 *
213 * \deprecated Superseded by mbedcrypto_md5_finish_ret() in 2.7.0
214 *
215 * \param ctx MD5 context
216 * \param output MD5 checksum result
217 *
218 * \warning MD5 is considered a weak message digest and its use
219 * constitutes a security risk. We recommend considering
220 * stronger message digests instead.
221 *
222 */
223MBEDCRYPTO_DEPRECATED void mbedcrypto_md5_finish( mbedcrypto_md5_context *ctx,
224 unsigned char output[16] );
225
226/**
227 * \brief MD5 process data block (internal use only)
228 *
229 * \deprecated Superseded by mbedcrypto_internal_md5_process() in 2.7.0
230 *
231 * \param ctx MD5 context
232 * \param data buffer holding one block of data
233 *
234 * \warning MD5 is considered a weak message digest and its use
235 * constitutes a security risk. We recommend considering
236 * stronger message digests instead.
237 *
238 */
239MBEDCRYPTO_DEPRECATED void mbedcrypto_md5_process( mbedcrypto_md5_context *ctx,
240 const unsigned char data[64] );
241
242#undef MBEDCRYPTO_DEPRECATED
243#endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */
244
245/**
246 * \brief Output = MD5( input buffer )
247 *
248 * \param input buffer holding the data
249 * \param ilen length of the input data
250 * \param output MD5 checksum result
251 *
252 * \return 0 if successful
253 *
254 * \warning MD5 is considered a weak message digest and its use
255 * constitutes a security risk. We recommend considering
256 * stronger message digests instead.
257 *
258 */
259int mbedcrypto_md5_ret( const unsigned char *input,
260 size_t ilen,
261 unsigned char output[16] );
262
263#if !defined(MBEDCRYPTO_DEPRECATED_REMOVED)
264#if defined(MBEDCRYPTO_DEPRECATED_WARNING)
265#define MBEDCRYPTO_DEPRECATED __attribute__((deprecated))
266#else
267#define MBEDCRYPTO_DEPRECATED
268#endif
269/**
270 * \brief Output = MD5( input buffer )
271 *
272 * \deprecated Superseded by mbedcrypto_md5_ret() in 2.7.0
273 *
274 * \param input buffer holding the data
275 * \param ilen length of the input data
276 * \param output MD5 checksum result
277 *
278 * \warning MD5 is considered a weak message digest and its use
279 * constitutes a security risk. We recommend considering
280 * stronger message digests instead.
281 *
282 */
283MBEDCRYPTO_DEPRECATED void mbedcrypto_md5( const unsigned char *input,
284 size_t ilen,
285 unsigned char output[16] );
286
287#undef MBEDCRYPTO_DEPRECATED
288#endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */
289
290/**
291 * \brief Checkup routine
292 *
293 * \return 0 if successful, or 1 if the test failed
294 *
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.
298 *
299 */
300int mbedcrypto_md5_self_test( int verbose );
301
302#ifdef __cplusplus
303}
304#endif
305
306#endif /* mbedcrypto_md5.h */