blob: 58c5396cf051d8009caee5be6731c71281c3f833 [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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020085
86/**
87 * \brief Clear MD2 context
88 *
89 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010090 *
91 * \warning MD2 is considered a weak message digest and its use
92 * constitutes a security risk. We recommend considering
93 * stronger message digests instead.
94 *
Paul Bakker5b4af392014-06-26 12:09:34 +020095 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020097
98/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020099 * \brief Clone (the state of) an MD2 context
100 *
101 * \param dst The destination context
102 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100103 *
104 * \warning MD2 is considered a weak message digest and its use
105 * constitutes a security risk. We recommend considering
106 * stronger message digests instead.
107 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200108 */
109void mbedtls_md2_clone( mbedtls_md2_context *dst,
110 const mbedtls_md2_context *src );
111
112/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000113 * \brief MD2 context setup
114 *
115 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100116 *
117 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100118 *
119 * \warning MD2 is considered a weak message digest and its use
120 * constitutes a security risk. We recommend considering
121 * stronger message digests instead.
122 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100124int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
126/**
127 * \brief MD2 process buffer
128 *
129 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100130 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100132 *
133 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100134 *
135 * \warning MD2 is considered a weak message digest and its use
136 * constitutes a security risk. We recommend considering
137 * stronger message digests instead.
138 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000139 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100140int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100141 const unsigned char *input,
142 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000143
144/**
145 * \brief MD2 final digest
146 *
147 * \param ctx MD2 context
148 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100149 *
150 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100151 *
152 * \warning MD2 is considered a weak message digest and its use
153 * constitutes a security risk. We recommend considering
154 * stronger message digests instead.
155 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100157int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100158 unsigned char output[16] );
159
160/**
161 * \brief MD2 process data block (internal use only)
162 *
163 * \param ctx MD2 context
164 *
165 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100166 *
167 * \warning MD2 is considered a weak message digest and its use
168 * constitutes a security risk. We recommend considering
169 * stronger message digests instead.
170 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100171 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100172int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100173
174#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100175/**
176 * \brief MD2 context setup
177 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100178 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100179 *
180 * \param ctx context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100181 *
182 * \warning MD2 is considered a weak message digest and its use
183 * constitutes a security risk. We recommend considering
184 * stronger message digests instead.
185 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100186 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000187MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100188
189/**
190 * \brief MD2 process buffer
191 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100192 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100193 *
194 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100195 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100196 * \param ilen length of the input data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100197 *
198 * \warning MD2 is considered a weak message digest and its use
199 * constitutes a security risk. We recommend considering
200 * stronger message digests instead.
201 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100202 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000203MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
204 const unsigned char *input,
205 size_t ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100206
207/**
208 * \brief MD2 final digest
209 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100210 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100211 *
212 * \param ctx MD2 context
213 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100214 *
215 * \warning MD2 is considered a weak message digest and its use
216 * constitutes a security risk. We recommend considering
217 * stronger message digests instead.
218 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100219 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000220MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
221 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100222
223/**
224 * \brief MD2 process data block (internal use only)
225 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100226 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100227 *
228 * \param ctx MD2 context
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100229 *
230 * \warning MD2 is considered a weak message digest and its use
231 * constitutes a security risk. We recommend considering
232 * stronger message digests instead.
233 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100234 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000235MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100236#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)
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100255/**
256 * \brief Output = MD2( input buffer )
257 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100258 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100259 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100260 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100261 * \param ilen length of the input data
262 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100263 *
264 * \warning MD2 is considered a weak message digest and its use
265 * constitutes a security risk. We recommend considering
266 * stronger message digests instead.
267 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100268 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000269MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
270 size_t ilen,
271 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100272#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000273
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500274#if defined(MBEDTLS_SELF_TEST)
275
Paul Bakker5121ce52009-01-03 21:22:43 +0000276/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000277 * \brief Checkup routine
278 *
279 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100280 *
281 * \warning MD2 is considered a weak message digest and its use
282 * constitutes a security risk. We recommend considering
283 * stronger message digests instead.
284 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000285 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000287
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500288#endif /* MBEDTLS_SELF_TEST */
289
Paul Bakker5121ce52009-01-03 21:22:43 +0000290#ifdef __cplusplus
291}
292#endif
293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294#endif /* mbedtls_md2.h */