blob: 7f3d5cf446c9c33752e1472c78aee968b1021402 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file md2.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD2 message digest algorithm (hash function)
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
6 * \warning MD2 is considered a weak message digest and its use constitutes a
7 * security risk. We recommend considering stronger message digests
8 * 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 Bakkerb96f1542010-07-18 20:36:00 +000025 *
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#ifndef MBEDTLS_MD2_H
28#define MBEDTLS_MD2_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>
Paul Bakker23986e52011-04-24 08:57:21 +000037
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020038/* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020039/** MD2 hardware accelerator failed */
40#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020041
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_MD2_ALT)
47// Regular implementation
48//
49
Paul Bakker5121ce52009-01-03 21:22:43 +000050/**
51 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010052 *
53 * \warning MD2 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 */
Dawid Drozd428cc522018-07-24 10:02:47 +020058typedef struct mbedtls_md2_context
Paul Bakker5121ce52009-01-03 21:22:43 +000059{
60 unsigned char cksum[16]; /*!< checksum of the data block */
61 unsigned char state[48]; /*!< intermediate digest state */
62 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000063 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000064}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000066
Ron Eldorb2aacec2017-05-18 16:53:08 +030067#else /* MBEDTLS_MD2_ALT */
68#include "md2_alt.h"
69#endif /* MBEDTLS_MD2_ALT */
70
Paul Bakker5121ce52009-01-03 21:22:43 +000071/**
Paul Bakker5b4af392014-06-26 12:09:34 +020072 * \brief Initialize MD2 context
73 *
74 * \param ctx MD2 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010075 *
76 * \warning MD2 is considered a weak message digest and its use
77 * constitutes a security risk. We recommend considering
78 * stronger message digests instead.
79 *
Paul Bakker5b4af392014-06-26 12:09:34 +020080 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020082
83/**
84 * \brief Clear MD2 context
85 *
86 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010087 *
88 * \warning MD2 is considered a weak message digest and its use
89 * constitutes a security risk. We recommend considering
90 * stronger message digests instead.
91 *
Paul Bakker5b4af392014-06-26 12:09:34 +020092 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020094
95/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020096 * \brief Clone (the state of) an MD2 context
97 *
98 * \param dst The destination context
99 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100100 *
101 * \warning MD2 is considered a weak message digest and its use
102 * constitutes a security risk. We recommend considering
103 * stronger message digests instead.
104 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200105 */
106void mbedtls_md2_clone( mbedtls_md2_context *dst,
107 const mbedtls_md2_context *src );
108
109/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 * \brief MD2 context setup
111 *
112 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100113 *
114 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100115 *
116 * \warning MD2 is considered a weak message digest and its use
117 * constitutes a security risk. We recommend considering
118 * stronger message digests instead.
119 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000120 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100121int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000122
123/**
124 * \brief MD2 process buffer
125 *
126 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100127 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000128 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100129 *
130 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100131 *
132 * \warning MD2 is considered a weak message digest and its use
133 * constitutes a security risk. We recommend considering
134 * stronger message digests instead.
135 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100137int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100138 const unsigned char *input,
139 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000140
141/**
142 * \brief MD2 final digest
143 *
144 * \param ctx MD2 context
145 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100146 *
147 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100148 *
149 * \warning MD2 is considered a weak message digest and its use
150 * constitutes a security risk. We recommend considering
151 * stronger message digests instead.
152 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000153 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100154int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100155 unsigned char output[16] );
156
157/**
158 * \brief MD2 process data block (internal use only)
159 *
160 * \param ctx MD2 context
161 *
162 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100163 *
164 * \warning MD2 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 Garcia1d852132017-04-28 16:21:40 +0100168 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100169int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100170
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200171#if !defined(MBEDTLS_DEPRECATED_REMOVED)
172#if defined(MBEDTLS_DEPRECATED_WARNING)
173#define MBEDTLS_DEPRECATED __attribute__((deprecated))
174#else
175#define MBEDTLS_DEPRECATED
176#endif
177/**
178 * \brief MD2 context setup
179 *
180 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
181 *
182 * \param ctx context to be initialized
183 *
184 * \warning MD2 is considered a weak message digest and its use
185 * constitutes a security risk. We recommend considering
186 * stronger message digests instead.
187 *
188 */
189MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
190
191/**
192 * \brief MD2 process buffer
193 *
194 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
195 *
196 * \param ctx MD2 context
197 * \param input buffer holding the data
198 * \param ilen length of the input data
199 *
200 * \warning MD2 is considered a weak message digest and its use
201 * constitutes a security risk. We recommend considering
202 * stronger message digests instead.
203 *
204 */
205MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
206 const unsigned char *input,
207 size_t ilen );
208
209/**
210 * \brief MD2 final digest
211 *
212 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
213 *
214 * \param ctx MD2 context
215 * \param output MD2 checksum result
216 *
217 * \warning MD2 is considered a weak message digest and its use
218 * constitutes a security risk. We recommend considering
219 * stronger message digests instead.
220 *
221 */
222MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
223 unsigned char output[16] );
224
225/**
226 * \brief MD2 process data block (internal use only)
227 *
228 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
229 *
230 * \param ctx MD2 context
231 *
232 * \warning MD2 is considered a weak message digest and its use
233 * constitutes a security risk. We recommend considering
234 * stronger message digests instead.
235 *
236 */
237MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
238
239#undef MBEDTLS_DEPRECATED
240#endif /* !MBEDTLS_DEPRECATED_REMOVED */
241
Paul Bakker5121ce52009-01-03 21:22:43 +0000242/**
243 * \brief Output = MD2( input buffer )
244 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100245 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000246 * \param ilen length of the input data
247 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100248 *
249 * \warning MD2 is considered a weak message digest and its use
250 * constitutes a security risk. We recommend considering
251 * stronger message digests instead.
252 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000253 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100254int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100255 size_t ilen,
256 unsigned char output[16] );
257
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200258#if !defined(MBEDTLS_DEPRECATED_REMOVED)
259#if defined(MBEDTLS_DEPRECATED_WARNING)
260#define MBEDTLS_DEPRECATED __attribute__((deprecated))
261#else
262#define MBEDTLS_DEPRECATED
263#endif
264/**
265 * \brief Output = MD2( input buffer )
266 *
267 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
268 *
269 * \param input buffer holding the data
270 * \param ilen length of the input data
271 * \param output MD2 checksum result
272 *
273 * \warning MD2 is considered a weak message digest and its use
274 * constitutes a security risk. We recommend considering
275 * stronger message digests instead.
276 *
277 */
278MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
279 size_t ilen,
280 unsigned char output[16] );
281
282#undef MBEDTLS_DEPRECATED
283#endif /* !MBEDTLS_DEPRECATED_REMOVED */
284
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500285#if defined(MBEDTLS_SELF_TEST)
286
Paul Bakker5121ce52009-01-03 21:22:43 +0000287/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000288 * \brief Checkup routine
289 *
290 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100291 *
292 * \warning MD2 is considered a weak message digest and its use
293 * constitutes a security risk. We recommend considering
294 * stronger message digests instead.
295 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000296 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000298
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500299#endif /* MBEDTLS_SELF_TEST */
300
Paul Bakker5121ce52009-01-03 21:22:43 +0000301#ifdef __cplusplus
302}
303#endif
304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305#endif /* mbedtls_md2.h */