blob: 5c2253c49f88397f3a20ef327a39f0c5936774d5 [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
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)
Hanno Beckerbbca8c52017-09-25 14:53:51 +010027 *
Paul Bakker5121ce52009-01-03 21:22:43 +000028 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#ifndef MBEDTLS_MD2_H
30#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero203fdf72019-07-04 20:01:14 +010033#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020036#endif
Paul Bakker90995b52013-06-24 19:20:35 +020037
Jaeden Amero59ebddf2019-07-10 11:03:03 +010038#include "mbedtls/platform_util.h"
39
Rich Evans00ab4702015-02-06 13:43:58 +000040#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000041
Ron Eldor9924bdc2018-10-04 10:59:13 +030042/* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea381fe82018-01-23 18:16:11 +010043#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
44
Paul Bakker407a0da2013-06-27 14:29:21 +020045#ifdef __cplusplus
46extern "C" {
47#endif
48
Ron Eldorb2aacec2017-05-18 16:53:08 +030049#if !defined(MBEDTLS_MD2_ALT)
50// Regular implementation
51//
52
Paul Bakker5121ce52009-01-03 21:22:43 +000053/**
54 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010055 *
56 * \warning MD2 is considered a weak message digest and its use
57 * constitutes a security risk. We recommend considering
58 * stronger message digests instead.
59 *
Paul Bakker5121ce52009-01-03 21:22:43 +000060 */
Dawid Drozd428cc522018-07-24 10:02:47 +020061typedef struct mbedtls_md2_context
Paul Bakker5121ce52009-01-03 21:22:43 +000062{
63 unsigned char cksum[16]; /*!< checksum of the data block */
64 unsigned char state[48]; /*!< intermediate digest state */
65 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000066 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000067}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000069
Ron Eldorb2aacec2017-05-18 16:53:08 +030070#else /* MBEDTLS_MD2_ALT */
71#include "md2_alt.h"
72#endif /* MBEDTLS_MD2_ALT */
73
Paul Bakker5121ce52009-01-03 21:22:43 +000074/**
Paul Bakker5b4af392014-06-26 12:09:34 +020075 * \brief Initialize MD2 context
76 *
77 * \param ctx MD2 context to be initialized
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 Bakker5b4af392014-06-26 12:09:34 +020083 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +010084MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020086
87/**
88 * \brief Clear MD2 context
89 *
90 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010091 *
92 * \warning MD2 is considered a weak message digest and its use
93 * constitutes a security risk. We recommend considering
94 * stronger message digests instead.
95 *
Paul Bakker5b4af392014-06-26 12:09:34 +020096 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +010097MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020099
100/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200101 * \brief Clone (the state of) an MD2 context
102 *
103 * \param dst The destination context
104 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100105 *
106 * \warning MD2 is considered a weak message digest and its use
107 * constitutes a security risk. We recommend considering
108 * stronger message digests instead.
109 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200110 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +0100111MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200112void mbedtls_md2_clone( mbedtls_md2_context *dst,
113 const mbedtls_md2_context *src );
114
115/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000116 * \brief MD2 context setup
117 *
118 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100119 *
120 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100121 *
122 * \warning MD2 is considered a weak message digest and its use
123 * constitutes a security risk. We recommend considering
124 * stronger message digests instead.
125 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +0100127MBEDTLS_DEPRECATED
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100128int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000129
130/**
131 * \brief MD2 process buffer
132 *
133 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100134 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000135 * \param ilen length of the input data
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 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +0100144MBEDTLS_DEPRECATED
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100145int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100146 const unsigned char *input,
147 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000148
149/**
150 * \brief MD2 final digest
151 *
152 * \param ctx MD2 context
153 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100154 *
155 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100156 *
157 * \warning MD2 is considered a weak message digest and its use
158 * constitutes a security risk. We recommend considering
159 * stronger message digests instead.
160 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000161 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +0100162MBEDTLS_DEPRECATED
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100163int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100164 unsigned char output[16] );
165
166/**
167 * \brief MD2 process data block (internal use only)
168 *
169 * \param ctx MD2 context
170 *
171 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100172 *
173 * \warning MD2 is considered a weak message digest and its use
174 * constitutes a security risk. We recommend considering
175 * stronger message digests instead.
176 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100177 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100178int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100179
180#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100181/**
182 * \brief MD2 context setup
183 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100184 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100185 *
186 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100187 *
188 * \warning MD2 is considered a weak message digest and its use
189 * constitutes a security risk. We recommend considering
190 * stronger message digests instead.
191 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100192 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000193MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100194
195/**
196 * \brief MD2 process buffer
197 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100198 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100199 *
200 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100201 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100202 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100203 *
204 * \warning MD2 is considered a weak message digest and its use
205 * constitutes a security risk. We recommend considering
206 * stronger message digests instead.
207 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100208 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000209MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
210 const unsigned char *input,
211 size_t ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100212
213/**
214 * \brief MD2 final digest
215 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100216 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100217 *
218 * \param ctx MD2 context
219 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100220 *
221 * \warning MD2 is considered a weak message digest and its use
222 * constitutes a security risk. We recommend considering
223 * stronger message digests instead.
224 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100225 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000226MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
227 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100228
229/**
230 * \brief MD2 process data block (internal use only)
231 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100232 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100233 *
234 * \param ctx MD2 context
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100235 *
236 * \warning MD2 is considered a weak message digest and its use
237 * constitutes a security risk. We recommend considering
238 * stronger message digests instead.
239 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100240 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000241MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100242#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000243
244/**
245 * \brief Output = MD2( input buffer )
246 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100247 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 * \param ilen length of the input data
249 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100250 *
251 * \warning MD2 is considered a weak message digest and its use
252 * constitutes a security risk. We recommend considering
253 * stronger message digests instead.
254 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000255 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +0100256MBEDTLS_DEPRECATED
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100257int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100258 size_t ilen,
259 unsigned char output[16] );
260
261#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100262/**
263 * \brief Output = MD2( input buffer )
264 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100265 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100266 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100267 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100268 * \param ilen length of the input data
269 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100270 *
271 * \warning MD2 is considered a weak message digest and its use
272 * constitutes a security risk. We recommend considering
273 * stronger message digests instead.
274 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100275 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000276MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
277 size_t ilen,
278 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100279#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000280
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500281#if defined(MBEDTLS_SELF_TEST)
282
Paul Bakker5121ce52009-01-03 21:22:43 +0000283/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000284 * \brief Checkup routine
285 *
286 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100287 *
288 * \warning MD2 is considered a weak message digest and its use
289 * constitutes a security risk. We recommend considering
290 * stronger message digests instead.
291 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000292 */
Jaeden Amerodfc7f4a2019-07-10 11:33:37 +0100293MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000295
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500296#endif /* MBEDTLS_SELF_TEST */
297
Paul Bakker5121ce52009-01-03 21:22:43 +0000298#ifdef __cplusplus
299}
300#endif
301
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302#endif /* mbedtls_md2.h */