blob: 08e75b247bd93107766a23b4e1ff00919fc3722a [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)
Paul Bakker90995b52013-06-24 19:20:35 +020033#include "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
Rich Evans00ab4702015-02-06 13:43:58 +000038#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000039
Gilles Peskinea381fe82018-01-23 18:16:11 +010040#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
41
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 */
58typedef struct
59{
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
171#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 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100180 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100181 *
182 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100183 *
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 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100188 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000189MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100190
191/**
192 * \brief MD2 process buffer
193 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100194 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100195 *
196 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100197 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100198 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100199 *
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 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100204 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000205MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
206 const unsigned char *input,
207 size_t ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100208
209/**
210 * \brief MD2 final digest
211 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100212 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100213 *
214 * \param ctx MD2 context
215 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100216 *
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 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100221 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000222MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
223 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100224
225/**
226 * \brief MD2 process data block (internal use only)
227 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100228 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100229 *
230 * \param ctx MD2 context
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100231 *
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 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100236 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000237MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100238
239#undef MBEDTLS_DEPRECATED
240#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000241
242/**
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
258#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 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100267 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100268 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100269 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100270 * \param ilen length of the input data
271 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100272 *
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 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100277 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000278MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
279 size_t ilen,
280 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100281
282#undef MBEDTLS_DEPRECATED
283#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000284
285/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000286 * \brief Checkup routine
287 *
288 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100289 *
290 * \warning MD2 is considered a weak message digest and its use
291 * constitutes a security risk. We recommend considering
292 * stronger message digests instead.
293 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000294 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000296
Paul Bakker5121ce52009-01-03 21:22:43 +0000297#ifdef __cplusplus
298}
299#endif
300
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301#endif /* mbedtls_md2.h */