blob: f82f8f870682900756bd805da7976f016f98a86b [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
Paul Bakker407a0da2013-06-27 14:29:21 +020038#ifdef __cplusplus
39extern "C" {
40#endif
41
Ron Eldorb2aacec2017-05-18 16:53:08 +030042#if !defined(MBEDTLS_MD2_ALT)
43// Regular implementation
44//
45
Paul Bakker5121ce52009-01-03 21:22:43 +000046/**
47 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010048 *
49 * \warning MD2 is considered a weak message digest and its use
50 * constitutes a security risk. We recommend considering
51 * stronger message digests instead.
52 *
Paul Bakker5121ce52009-01-03 21:22:43 +000053 */
Dawid Drozd428cc522018-07-24 10:02:47 +020054typedef struct mbedtls_md2_context
Paul Bakker5121ce52009-01-03 21:22:43 +000055{
56 unsigned char cksum[16]; /*!< checksum of the data block */
57 unsigned char state[48]; /*!< intermediate digest state */
58 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000059 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000060}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000062
Ron Eldorb2aacec2017-05-18 16:53:08 +030063#else /* MBEDTLS_MD2_ALT */
64#include "md2_alt.h"
65#endif /* MBEDTLS_MD2_ALT */
66
Paul Bakker5121ce52009-01-03 21:22:43 +000067/**
Paul Bakker5b4af392014-06-26 12:09:34 +020068 * \brief Initialize MD2 context
69 *
70 * \param ctx MD2 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010071 *
72 * \warning MD2 is considered a weak message digest and its use
73 * constitutes a security risk. We recommend considering
74 * stronger message digests instead.
75 *
Paul Bakker5b4af392014-06-26 12:09:34 +020076 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020078
79/**
80 * \brief Clear MD2 context
81 *
82 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010083 *
84 * \warning MD2 is considered a weak message digest and its use
85 * constitutes a security risk. We recommend considering
86 * stronger message digests instead.
87 *
Paul Bakker5b4af392014-06-26 12:09:34 +020088 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020090
91/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020092 * \brief Clone (the state of) an MD2 context
93 *
94 * \param dst The destination context
95 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010096 *
97 * \warning MD2 is considered a weak message digest and its use
98 * constitutes a security risk. We recommend considering
99 * stronger message digests instead.
100 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200101 */
102void mbedtls_md2_clone( mbedtls_md2_context *dst,
103 const mbedtls_md2_context *src );
104
105/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 * \brief MD2 context setup
107 *
108 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100109 *
110 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100111 *
112 * \warning MD2 is considered a weak message digest and its use
113 * constitutes a security risk. We recommend considering
114 * stronger message digests instead.
115 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000116 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100117int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000118
119/**
120 * \brief MD2 process buffer
121 *
122 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100123 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100125 *
126 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100127 *
128 * \warning MD2 is considered a weak message digest and its use
129 * constitutes a security risk. We recommend considering
130 * stronger message digests instead.
131 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100133int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100134 const unsigned char *input,
135 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000136
137/**
138 * \brief MD2 final digest
139 *
140 * \param ctx MD2 context
141 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100142 *
143 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100144 *
145 * \warning MD2 is considered a weak message digest and its use
146 * constitutes a security risk. We recommend considering
147 * stronger message digests instead.
148 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000149 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100150int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100151 unsigned char output[16] );
152
153/**
154 * \brief MD2 process data block (internal use only)
155 *
156 * \param ctx MD2 context
157 *
158 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100159 *
160 * \warning MD2 is considered a weak message digest and its use
161 * constitutes a security risk. We recommend considering
162 * stronger message digests instead.
163 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100164 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100165int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100166
167#if !defined(MBEDTLS_DEPRECATED_REMOVED)
168#if defined(MBEDTLS_DEPRECATED_WARNING)
169#define MBEDTLS_DEPRECATED __attribute__((deprecated))
170#else
171#define MBEDTLS_DEPRECATED
172#endif
173/**
174 * \brief MD2 context setup
175 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100176 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100177 *
178 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100179 *
180 * \warning MD2 is considered a weak message digest and its use
181 * constitutes a security risk. We recommend considering
182 * stronger message digests instead.
183 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100184 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000185MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100186
187/**
188 * \brief MD2 process buffer
189 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100190 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100191 *
192 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100193 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100194 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100195 *
196 * \warning MD2 is considered a weak message digest and its use
197 * constitutes a security risk. We recommend considering
198 * stronger message digests instead.
199 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100200 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000201MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
202 const unsigned char *input,
203 size_t ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100204
205/**
206 * \brief MD2 final digest
207 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100208 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100209 *
210 * \param ctx MD2 context
211 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100212 *
213 * \warning MD2 is considered a weak message digest and its use
214 * constitutes a security risk. We recommend considering
215 * stronger message digests instead.
216 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100217 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000218MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
219 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100220
221/**
222 * \brief MD2 process data block (internal use only)
223 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100224 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100225 *
226 * \param ctx MD2 context
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100227 *
228 * \warning MD2 is considered a weak message digest and its use
229 * constitutes a security risk. We recommend considering
230 * stronger message digests instead.
231 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100232 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000233MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100234
235#undef MBEDTLS_DEPRECATED
236#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000237
238/**
239 * \brief Output = MD2( input buffer )
240 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100241 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000242 * \param ilen length of the input data
243 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100244 *
245 * \warning MD2 is considered a weak message digest and its use
246 * constitutes a security risk. We recommend considering
247 * stronger message digests instead.
248 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000249 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100250int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100251 size_t ilen,
252 unsigned char output[16] );
253
254#if !defined(MBEDTLS_DEPRECATED_REMOVED)
255#if defined(MBEDTLS_DEPRECATED_WARNING)
256#define MBEDTLS_DEPRECATED __attribute__((deprecated))
257#else
258#define MBEDTLS_DEPRECATED
259#endif
260/**
261 * \brief Output = MD2( input buffer )
262 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100263 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100264 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100265 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100266 * \param ilen length of the input data
267 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100268 *
269 * \warning MD2 is considered a weak message digest and its use
270 * constitutes a security risk. We recommend considering
271 * stronger message digests instead.
272 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100273 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000274MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
275 size_t ilen,
276 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100277
278#undef MBEDTLS_DEPRECATED
279#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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000294
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500295#endif /* MBEDTLS_SELF_TEST */
296
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 */