blob: 9607df66baffd4f87836cc0bc5db6fca91096b38 [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útia2947ac2020-08-19 16:37:36 +020011 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-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útif744bd72020-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 *
Paul Bakker5121ce52009-01-03 21:22:43 +000053 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#ifndef MBEDTLS_MD2_H
55#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020058#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020059#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020061#endif
Paul Bakker90995b52013-06-24 19:20:35 +020062
Rich Evans00ab4702015-02-06 13:43:58 +000063#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000064
Ron Eldor9924bdc2018-10-04 10:59:13 +030065/* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea381fe82018-01-23 18:16:11 +010066#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
67
Paul Bakker407a0da2013-06-27 14:29:21 +020068#ifdef __cplusplus
69extern "C" {
70#endif
71
Ron Eldorb2aacec2017-05-18 16:53:08 +030072#if !defined(MBEDTLS_MD2_ALT)
73// Regular implementation
74//
75
Paul Bakker5121ce52009-01-03 21:22:43 +000076/**
77 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010078 *
79 * \warning MD2 is considered a weak message digest and its use
80 * constitutes a security risk. We recommend considering
81 * stronger message digests instead.
82 *
Paul Bakker5121ce52009-01-03 21:22:43 +000083 */
Dawid Drozd428cc522018-07-24 10:02:47 +020084typedef struct mbedtls_md2_context
Paul Bakker5121ce52009-01-03 21:22:43 +000085{
86 unsigned char cksum[16]; /*!< checksum of the data block */
87 unsigned char state[48]; /*!< intermediate digest state */
88 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000089 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000090}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000092
Ron Eldorb2aacec2017-05-18 16:53:08 +030093#else /* MBEDTLS_MD2_ALT */
94#include "md2_alt.h"
95#endif /* MBEDTLS_MD2_ALT */
96
Paul Bakker5121ce52009-01-03 21:22:43 +000097/**
Paul Bakker5b4af392014-06-26 12:09:34 +020098 * \brief Initialize MD2 context
99 *
100 * \param ctx MD2 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100101 *
102 * \warning MD2 is considered a weak message digest and its use
103 * constitutes a security risk. We recommend considering
104 * stronger message digests instead.
105 *
Paul Bakker5b4af392014-06-26 12:09:34 +0200106 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200108
109/**
110 * \brief Clear MD2 context
111 *
112 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100113 *
114 * \warning MD2 is considered a weak message digest and its use
115 * constitutes a security risk. We recommend considering
116 * stronger message digests instead.
117 *
Paul Bakker5b4af392014-06-26 12:09:34 +0200118 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200120
121/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200122 * \brief Clone (the state of) an MD2 context
123 *
124 * \param dst The destination context
125 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100126 *
127 * \warning MD2 is considered a weak message digest and its use
128 * constitutes a security risk. We recommend considering
129 * stronger message digests instead.
130 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200131 */
132void mbedtls_md2_clone( mbedtls_md2_context *dst,
133 const mbedtls_md2_context *src );
134
135/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 * \brief MD2 context setup
137 *
138 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100139 *
140 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100141 *
142 * \warning MD2 is considered a weak message digest and its use
143 * constitutes a security risk. We recommend considering
144 * stronger message digests instead.
145 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000146 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100147int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000148
149/**
150 * \brief MD2 process buffer
151 *
152 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100153 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000154 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100155 *
156 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100157 *
158 * \warning MD2 is considered a weak message digest and its use
159 * constitutes a security risk. We recommend considering
160 * stronger message digests instead.
161 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000162 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100163int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100164 const unsigned char *input,
165 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000166
167/**
168 * \brief MD2 final digest
169 *
170 * \param ctx MD2 context
171 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100172 *
173 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100174 *
175 * \warning MD2 is considered a weak message digest and its use
176 * constitutes a security risk. We recommend considering
177 * stronger message digests instead.
178 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000179 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100180int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100181 unsigned char output[16] );
182
183/**
184 * \brief MD2 process data block (internal use only)
185 *
186 * \param ctx MD2 context
187 *
188 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100189 *
190 * \warning MD2 is considered a weak message digest and its use
191 * constitutes a security risk. We recommend considering
192 * stronger message digests instead.
193 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100194 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100195int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100196
197#if !defined(MBEDTLS_DEPRECATED_REMOVED)
198#if defined(MBEDTLS_DEPRECATED_WARNING)
199#define MBEDTLS_DEPRECATED __attribute__((deprecated))
200#else
201#define MBEDTLS_DEPRECATED
202#endif
203/**
204 * \brief MD2 context setup
205 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100206 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100207 *
208 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100209 *
210 * \warning MD2 is considered a weak message digest and its use
211 * constitutes a security risk. We recommend considering
212 * stronger message digests instead.
213 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100214 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000215MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100216
217/**
218 * \brief MD2 process buffer
219 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100220 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100221 *
222 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100223 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100224 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100225 *
226 * \warning MD2 is considered a weak message digest and its use
227 * constitutes a security risk. We recommend considering
228 * stronger message digests instead.
229 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100230 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000231MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
232 const unsigned char *input,
233 size_t ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100234
235/**
236 * \brief MD2 final digest
237 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100238 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100239 *
240 * \param ctx MD2 context
241 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100242 *
243 * \warning MD2 is considered a weak message digest and its use
244 * constitutes a security risk. We recommend considering
245 * stronger message digests instead.
246 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100247 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000248MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
249 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100250
251/**
252 * \brief MD2 process data block (internal use only)
253 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100254 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100255 *
256 * \param ctx MD2 context
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100257 *
258 * \warning MD2 is considered a weak message digest and its use
259 * constitutes a security risk. We recommend considering
260 * stronger message digests instead.
261 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100262 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000263MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100264
265#undef MBEDTLS_DEPRECATED
266#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000267
268/**
269 * \brief Output = MD2( input buffer )
270 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100271 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000272 * \param ilen length of the input data
273 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100274 *
275 * \warning MD2 is considered a weak message digest and its use
276 * constitutes a security risk. We recommend considering
277 * stronger message digests instead.
278 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000279 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100280int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100281 size_t ilen,
282 unsigned char output[16] );
283
284#if !defined(MBEDTLS_DEPRECATED_REMOVED)
285#if defined(MBEDTLS_DEPRECATED_WARNING)
286#define MBEDTLS_DEPRECATED __attribute__((deprecated))
287#else
288#define MBEDTLS_DEPRECATED
289#endif
290/**
291 * \brief Output = MD2( input buffer )
292 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100293 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100294 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100295 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100296 * \param ilen length of the input data
297 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100298 *
299 * \warning MD2 is considered a weak message digest and its use
300 * constitutes a security risk. We recommend considering
301 * stronger message digests instead.
302 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100303 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000304MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
305 size_t ilen,
306 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100307
308#undef MBEDTLS_DEPRECATED
309#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000310
Ron Eldorfa8f6352017-06-20 15:48:46 +0300311#if defined(MBEDTLS_SELF_TEST)
312
Paul Bakker5121ce52009-01-03 21:22:43 +0000313/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000314 * \brief Checkup routine
315 *
316 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100317 *
318 * \warning MD2 is considered a weak message digest and its use
319 * constitutes a security risk. We recommend considering
320 * stronger message digests instead.
321 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000322 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000324
Ron Eldorfa8f6352017-06-20 15:48:46 +0300325#endif /* MBEDTLS_SELF_TEST */
326
Paul Bakker5121ce52009-01-03 21:22:43 +0000327#ifdef __cplusplus
328}
329#endif
330
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331#endif /* mbedtls_md2.h */