blob: 1adde5c1638341041f621bc975f3fa25431b43a5 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file md5.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD5 message digest algorithm (hash function)
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
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.
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +020011 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 * 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.
Paul Bakkerb96f1542010-07-18 20:36:00 +000025 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000026 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000027 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#ifndef MBEDTLS_MD5_H
29#define MBEDTLS_MD5_H
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020032#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#endif
Paul Bakker90995b52013-06-24 19:20:35 +020036
Rich Evans00ab4702015-02-06 13:43:58 +000037#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020038#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000039
Gilles Peskinea381fe82018-01-23 18:16:11 +010040#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
41
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Ron Eldorb2aacec2017-05-18 16:53:08 +030046#if !defined(MBEDTLS_MD5_ALT)
47// Regular implementation
48//
49
Paul Bakker5121ce52009-01-03 21:22:43 +000050/**
51 * \brief MD5 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010052 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +000057 */
58typedef struct
59{
Paul Bakker5c2364c2012-10-01 14:41:15 +000060 uint32_t total[2]; /*!< number of bytes processed */
61 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000062 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000063}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064mbedtls_md5_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000065
Ron Eldorb2aacec2017-05-18 16:53:08 +030066#else /* MBEDTLS_MD5_ALT */
67#include "md5_alt.h"
68#endif /* MBEDTLS_MD5_ALT */
69
Paul Bakker5121ce52009-01-03 21:22:43 +000070/**
Paul Bakker5b4af392014-06-26 12:09:34 +020071 * \brief Initialize MD5 context
72 *
73 * \param ctx MD5 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010074 *
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 *
Paul Bakker5b4af392014-06-26 12:09:34 +020079 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080void mbedtls_md5_init( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020081
82/**
83 * \brief Clear MD5 context
84 *
85 * \param ctx MD5 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010086 *
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 *
Paul Bakker5b4af392014-06-26 12:09:34 +020091 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092void mbedtls_md5_free( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020093
94/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020095 * \brief Clone (the state of) an MD5 context
96 *
97 * \param dst The destination context
98 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010099 *
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 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200104 */
105void mbedtls_md5_clone( mbedtls_md5_context *dst,
106 const mbedtls_md5_context *src );
107
108/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000109 * \brief MD5 context setup
110 *
111 * \param ctx context to be initialized
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100112 *
113 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100114 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000119 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100120int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
122/**
123 * \brief MD5 process buffer
124 *
125 * \param ctx MD5 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100126 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 * \param ilen length of the input data
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100128 *
129 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100130 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000135 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100136int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100137 const unsigned char *input,
138 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000139
140/**
141 * \brief MD5 final digest
142 *
143 * \param ctx MD5 context
144 * \param output MD5 checksum result
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100145 *
146 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100147 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000152 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100153int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100154 unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000155
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100156/**
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
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100163 *
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 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100168 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100169int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
170 const unsigned char data[64] );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100171
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 MD5 context setup
180 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100181 * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100182 *
183 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100184 *
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 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100189 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000190MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100191
192/**
193 * \brief MD5 process buffer
194 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100195 * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100196 *
197 * \param ctx MD5 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100198 * \param input buffer holding the data
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100199 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100200 *
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 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100205 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000206MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
207 const unsigned char *input,
208 size_t ilen );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100209
210/**
211 * \brief MD5 final digest
212 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100213 * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100214 *
215 * \param ctx MD5 context
216 * \param output MD5 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100217 *
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 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100222 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000223MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
224 unsigned char output[16] );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100225
226/**
227 * \brief MD5 process data block (internal use only)
228 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100229 * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100230 *
231 * \param ctx MD5 context
232 * \param data buffer holding one block of data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100233 *
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 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100238 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000239MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
240 const unsigned char data[64] );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100241
242#undef MBEDTLS_DEPRECATED
243#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker90995b52013-06-24 19:20:35 +0200244
Paul Bakker5121ce52009-01-03 21:22:43 +0000245/**
246 * \brief Output = MD5( input buffer )
247 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100248 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000249 * \param ilen length of the input data
250 * \param output MD5 checksum result
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100251 *
252 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100253 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000258 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100259int mbedtls_md5_ret( const unsigned char *input,
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100260 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 = MD5( input buffer )
271 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100272 * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100273 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100274 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000275 * \param ilen length of the input data
276 * \param output MD5 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100277 *
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000282 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000283MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
284 size_t ilen,
285 unsigned char output[16] );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100286
287#undef MBEDTLS_DEPRECATED
288#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000289
Ron Eldorfa8f6352017-06-20 15:48:46 +0300290#if defined(MBEDTLS_SELF_TEST)
291
Paul Bakker5121ce52009-01-03 21:22:43 +0000292/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000293 * \brief Checkup routine
294 *
295 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100296 *
297 * \warning MD5 is considered a weak message digest and its use
298 * constitutes a security risk. We recommend considering
299 * stronger message digests instead.
300 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000301 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302int mbedtls_md5_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000303
Ron Eldorfa8f6352017-06-20 15:48:46 +0300304#endif /* MBEDTLS_SELF_TEST */
305
Paul Bakker5121ce52009-01-03 21:22:43 +0000306#ifdef __cplusplus
307}
308#endif
309
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200310#endif /* mbedtls_md5.h */