blob: 6ef359154a45a5e5e9250dfd3860dd055932c995 [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/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020011 * Copyright The Mbed TLS Contributors
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 Bakker5121ce52009-01-03 21:22:43 +000025 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#ifndef MBEDTLS_MD5_H
27#define MBEDTLS_MD5_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020028#include "mbedtls/private_access.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010031#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#endif
Paul Bakker90995b52013-06-24 19:20:35 +020035
Rich Evans00ab4702015-02-06 13:43:58 +000036#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020037#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000038
Paul Bakker407a0da2013-06-27 14:29:21 +020039#ifdef __cplusplus
40extern "C" {
41#endif
42
Ron Eldorb2aacec2017-05-18 16:53:08 +030043#if !defined(MBEDTLS_MD5_ALT)
44// Regular implementation
45//
46
Paul Bakker5121ce52009-01-03 21:22:43 +000047/**
48 * \brief MD5 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010049 *
50 * \warning MD5 is considered a weak message digest and its use
51 * constitutes a security risk. We recommend considering
52 * stronger message digests instead.
53 *
Paul Bakker5121ce52009-01-03 21:22:43 +000054 */
Dawid Drozd428cc522018-07-24 10:02:47 +020055typedef struct mbedtls_md5_context
Paul Bakker5121ce52009-01-03 21:22:43 +000056{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020057 uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
58 uint32_t MBEDTLS_PRIVATE(state)[4]; /*!< intermediate digest state */
59 unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000060}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061mbedtls_md5_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000062
Ron Eldorb2aacec2017-05-18 16:53:08 +030063#else /* MBEDTLS_MD5_ALT */
64#include "md5_alt.h"
65#endif /* MBEDTLS_MD5_ALT */
66
Paul Bakker5121ce52009-01-03 21:22:43 +000067/**
Paul Bakker5b4af392014-06-26 12:09:34 +020068 * \brief Initialize MD5 context
69 *
70 * \param ctx MD5 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010071 *
72 * \warning MD5 is considered a weak message digest and its use
73 * constitutes a security risk. We recommend considering
74 * stronger message digests instead.
75 *
Paul Bakker5b4af392014-06-26 12:09:34 +020076 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077void mbedtls_md5_init( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020078
79/**
80 * \brief Clear MD5 context
81 *
82 * \param ctx MD5 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010083 *
84 * \warning MD5 is considered a weak message digest and its use
85 * constitutes a security risk. We recommend considering
86 * stronger message digests instead.
87 *
Paul Bakker5b4af392014-06-26 12:09:34 +020088 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089void mbedtls_md5_free( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020090
91/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020092 * \brief Clone (the state of) an MD5 context
93 *
94 * \param dst The destination context
95 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010096 *
97 * \warning MD5 is considered a weak message digest and its use
98 * constitutes a security risk. We recommend considering
99 * stronger message digests instead.
100 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200101 */
102void mbedtls_md5_clone( mbedtls_md5_context *dst,
103 const mbedtls_md5_context *src );
104
105/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 * \brief MD5 context setup
107 *
108 * \param ctx context to be initialized
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100109 *
110 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100111 *
112 * \warning MD5 is considered a weak message digest and its use
113 * constitutes a security risk. We recommend considering
114 * stronger message digests instead.
115 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000116 */
TRodziewicz26371e42021-06-08 16:45:41 +0200117int mbedtls_md5_starts( mbedtls_md5_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000118
119/**
120 * \brief MD5 process buffer
121 *
122 * \param ctx MD5 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100123 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 * \param ilen length of the input data
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100125 *
126 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100127 *
128 * \warning MD5 is considered a weak message digest and its use
129 * constitutes a security risk. We recommend considering
130 * stronger message digests instead.
131 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 */
TRodziewicz26371e42021-06-08 16:45:41 +0200133int mbedtls_md5_update( mbedtls_md5_context *ctx,
134 const unsigned char *input,
135 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000136
137/**
138 * \brief MD5 final digest
139 *
140 * \param ctx MD5 context
141 * \param output MD5 checksum result
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100142 *
143 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100144 *
145 * \warning MD5 is considered a weak message digest and its use
146 * constitutes a security risk. We recommend considering
147 * stronger message digests instead.
148 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000149 */
TRodziewicz26371e42021-06-08 16:45:41 +0200150int mbedtls_md5_finish( mbedtls_md5_context *ctx,
151 unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000152
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100153/**
154 * \brief MD5 process data block (internal use only)
155 *
156 * \param ctx MD5 context
157 * \param data buffer holding one block of data
158 *
159 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100160 *
161 * \warning MD5 is considered a weak message digest and its use
162 * constitutes a security risk. We recommend considering
163 * stronger message digests instead.
164 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100165 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100166int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
167 const unsigned char data[64] );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100168
Paul Bakker5121ce52009-01-03 21:22:43 +0000169/**
170 * \brief Output = MD5( input buffer )
171 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100172 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000173 * \param ilen length of the input data
174 * \param output MD5 checksum result
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100175 *
176 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100177 *
178 * \warning MD5 is considered a weak message digest and its use
179 * constitutes a security risk. We recommend considering
180 * stronger message digests instead.
181 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000182 */
TRodziewicz26371e42021-06-08 16:45:41 +0200183int mbedtls_md5( const unsigned char *input,
184 size_t ilen,
185 unsigned char output[16] );
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100186
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500187#if defined(MBEDTLS_SELF_TEST)
188
Paul Bakker5121ce52009-01-03 21:22:43 +0000189/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000190 * \brief Checkup routine
191 *
192 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100193 *
194 * \warning MD5 is considered a weak message digest and its use
195 * constitutes a security risk. We recommend considering
196 * stronger message digests instead.
197 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000198 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199int mbedtls_md5_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000200
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500201#endif /* MBEDTLS_SELF_TEST */
202
Paul Bakker5121ce52009-01-03 21:22:43 +0000203#ifdef __cplusplus
204}
205#endif
206
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207#endif /* mbedtls_md5.h */