blob: 1e4f2553bbe696a1ae6c10d625d48294d5024b54 [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +020011 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13 *
14 * This file is provided under the Apache License 2.0, or the
15 * GNU General Public License v2.0 or later.
16 *
17 * **********
18 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020019 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000031 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020032 * **********
33 *
34 * **********
35 * GNU General Public License v2.0 or later:
36 *
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License along
48 * with this program; if not, write to the Free Software Foundation, Inc.,
49 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50 *
51 * **********
52 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000053 * This file is part of mbed TLS (https://tls.mbed.org)
Hanno Beckerbbca8c52017-09-25 14:53:51 +010054 *
Paul Bakker5121ce52009-01-03 21:22:43 +000055 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#ifndef MBEDTLS_MD2_H
57#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020060#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020061#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020063#endif
Paul Bakker90995b52013-06-24 19:20:35 +020064
Rich Evans00ab4702015-02-06 13:43:58 +000065#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000066
Gilles Peskinea381fe82018-01-23 18:16:11 +010067#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
68
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if !defined(MBEDTLS_MD2_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020070// Regular implementation
71//
72
Paul Bakker407a0da2013-06-27 14:29:21 +020073#ifdef __cplusplus
74extern "C" {
75#endif
76
Paul Bakker5121ce52009-01-03 21:22:43 +000077/**
78 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010079 *
80 * \warning MD2 is considered a weak message digest and its use
81 * constitutes a security risk. We recommend considering
82 * stronger message digests instead.
83 *
Paul Bakker5121ce52009-01-03 21:22:43 +000084 */
85typedef struct
86{
87 unsigned char cksum[16]; /*!< checksum of the data block */
88 unsigned char state[48]; /*!< intermediate digest state */
89 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000090 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000091}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000093
Paul Bakker5121ce52009-01-03 21:22:43 +000094/**
Paul Bakker5b4af392014-06-26 12:09:34 +020095 * \brief Initialize MD2 context
96 *
97 * \param ctx MD2 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010098 *
99 * \warning MD2 is considered a weak message digest and its use
100 * constitutes a security risk. We recommend considering
101 * stronger message digests instead.
102 *
Paul Bakker5b4af392014-06-26 12:09:34 +0200103 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200105
106/**
107 * \brief Clear MD2 context
108 *
109 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100110 *
111 * \warning MD2 is considered a weak message digest and its use
112 * constitutes a security risk. We recommend considering
113 * stronger message digests instead.
114 *
Paul Bakker5b4af392014-06-26 12:09:34 +0200115 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200117
118/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200119 * \brief Clone (the state of) an MD2 context
120 *
121 * \param dst The destination context
122 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100123 *
124 * \warning MD2 is considered a weak message digest and its use
125 * constitutes a security risk. We recommend considering
126 * stronger message digests instead.
127 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200128 */
129void mbedtls_md2_clone( mbedtls_md2_context *dst,
130 const mbedtls_md2_context *src );
131
132/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 * \brief MD2 context setup
134 *
135 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100136 *
137 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100138 *
139 * \warning MD2 is considered a weak message digest and its use
140 * constitutes a security risk. We recommend considering
141 * stronger message digests instead.
142 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000143 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100144int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000145
146/**
147 * \brief MD2 process buffer
148 *
149 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100150 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100152 *
153 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100154 *
155 * \warning MD2 is considered a weak message digest and its use
156 * constitutes a security risk. We recommend considering
157 * stronger message digests instead.
158 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000159 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100160int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100161 const unsigned char *input,
162 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000163
164/**
165 * \brief MD2 final digest
166 *
167 * \param ctx MD2 context
168 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100169 *
170 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100171 *
172 * \warning MD2 is considered a weak message digest and its use
173 * constitutes a security risk. We recommend considering
174 * stronger message digests instead.
175 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000176 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100177int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100178 unsigned char output[16] );
179
180/**
181 * \brief MD2 process data block (internal use only)
182 *
183 * \param ctx MD2 context
184 *
185 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100186 *
187 * \warning MD2 is considered a weak message digest and its use
188 * constitutes a security risk. We recommend considering
189 * stronger message digests instead.
190 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100191 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100192int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100193
194#if !defined(MBEDTLS_DEPRECATED_REMOVED)
195#if defined(MBEDTLS_DEPRECATED_WARNING)
196#define MBEDTLS_DEPRECATED __attribute__((deprecated))
197#else
198#define MBEDTLS_DEPRECATED
199#endif
200/**
201 * \brief MD2 context setup
202 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100203 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100204 *
205 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100206 *
207 * \warning MD2 is considered a weak message digest and its use
208 * constitutes a security risk. We recommend considering
209 * stronger message digests instead.
210 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100211 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000212MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100213
214/**
215 * \brief MD2 process buffer
216 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100217 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100218 *
219 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100220 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100221 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100222 *
223 * \warning MD2 is considered a weak message digest and its use
224 * constitutes a security risk. We recommend considering
225 * stronger message digests instead.
226 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100227 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000228MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
229 const unsigned char *input,
230 size_t ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100231
232/**
233 * \brief MD2 final digest
234 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100235 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100236 *
237 * \param ctx MD2 context
238 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100239 *
240 * \warning MD2 is considered a weak message digest and its use
241 * constitutes a security risk. We recommend considering
242 * stronger message digests instead.
243 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100244 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000245MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
246 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100247
248/**
249 * \brief MD2 process data block (internal use only)
250 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100251 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100252 *
253 * \param ctx MD2 context
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100254 *
255 * \warning MD2 is considered a weak message digest and its use
256 * constitutes a security risk. We recommend considering
257 * stronger message digests instead.
258 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100259 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000260MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100261
262#undef MBEDTLS_DEPRECATED
263#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000264
Paul Bakker90995b52013-06-24 19:20:35 +0200265#ifdef __cplusplus
266}
267#endif
268
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269#else /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200270#include "md2_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271#endif /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200272
273#ifdef __cplusplus
274extern "C" {
275#endif
276
Paul Bakker5121ce52009-01-03 21:22:43 +0000277/**
278 * \brief Output = MD2( input buffer )
279 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100280 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000281 * \param ilen length of the input data
282 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100283 *
284 * \warning MD2 is considered a weak message digest and its use
285 * constitutes a security risk. We recommend considering
286 * stronger message digests instead.
287 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000288 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100289int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100290 size_t ilen,
291 unsigned char output[16] );
292
293#if !defined(MBEDTLS_DEPRECATED_REMOVED)
294#if defined(MBEDTLS_DEPRECATED_WARNING)
295#define MBEDTLS_DEPRECATED __attribute__((deprecated))
296#else
297#define MBEDTLS_DEPRECATED
298#endif
299/**
300 * \brief Output = MD2( input buffer )
301 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100302 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100303 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100304 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100305 * \param ilen length of the input data
306 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100307 *
308 * \warning MD2 is considered a weak message digest and its use
309 * constitutes a security risk. We recommend considering
310 * stronger message digests instead.
311 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100312 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000313MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
314 size_t ilen,
315 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100316
317#undef MBEDTLS_DEPRECATED
318#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000319
320/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000321 * \brief Checkup routine
322 *
323 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100324 *
325 * \warning MD2 is considered a weak message digest and its use
326 * constitutes a security risk. We recommend considering
327 * stronger message digests instead.
328 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000329 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200330int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000331
Paul Bakker5121ce52009-01-03 21:22:43 +0000332#ifdef __cplusplus
333}
334#endif
335
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336#endif /* mbedtls_md2.h */