blob: afcf3a3ee2a6b43423127d431bd1c64a2283e759 [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
Dave Rodgman7ff79652023-11-03 12:04:52 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakkerb96f1542010-07-18 20:36:00 +000013 *
Paul Bakker5121ce52009-01-03 21:22:43 +000014 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020015#ifndef MBEDTLS_MD2_H
16#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000017
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020018#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010019#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020020#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020021#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020022#endif
Paul Bakker90995b52013-06-24 19:20:35 +020023
Rich Evans00ab4702015-02-06 13:43:58 +000024#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000025
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020026/* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020027/** MD2 hardware accelerator failed */
28#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020029
Paul Bakker407a0da2013-06-27 14:29:21 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Ron Eldorb2aacec2017-05-18 16:53:08 +030034#if !defined(MBEDTLS_MD2_ALT)
35// Regular implementation
36//
37
Paul Bakker5121ce52009-01-03 21:22:43 +000038/**
39 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010040 *
41 * \warning MD2 is considered a weak message digest and its use
42 * constitutes a security risk. We recommend considering
43 * stronger message digests instead.
44 *
Paul Bakker5121ce52009-01-03 21:22:43 +000045 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010046typedef struct mbedtls_md2_context {
Paul Bakker5121ce52009-01-03 21:22:43 +000047 unsigned char cksum[16]; /*!< checksum of the data block */
48 unsigned char state[48]; /*!< intermediate digest state */
49 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000050 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000051}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000053
Ron Eldorb2aacec2017-05-18 16:53:08 +030054#else /* MBEDTLS_MD2_ALT */
55#include "md2_alt.h"
56#endif /* MBEDTLS_MD2_ALT */
57
Paul Bakker5121ce52009-01-03 21:22:43 +000058/**
Paul Bakker5b4af392014-06-26 12:09:34 +020059 * \brief Initialize MD2 context
60 *
61 * \param ctx MD2 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010062 *
63 * \warning MD2 is considered a weak message digest and its use
64 * constitutes a security risk. We recommend considering
65 * stronger message digests instead.
66 *
Paul Bakker5b4af392014-06-26 12:09:34 +020067 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010068void mbedtls_md2_init(mbedtls_md2_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020069
70/**
71 * \brief Clear MD2 context
72 *
73 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010074 *
75 * \warning MD2 is considered a weak message digest and its use
76 * constitutes a security risk. We recommend considering
77 * stronger message digests instead.
78 *
Paul Bakker5b4af392014-06-26 12:09:34 +020079 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010080void mbedtls_md2_free(mbedtls_md2_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020081
82/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020083 * \brief Clone (the state of) an MD2 context
84 *
85 * \param dst The destination context
86 * \param src The context to be cloned
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 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020092 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010093void mbedtls_md2_clone(mbedtls_md2_context *dst,
94 const mbedtls_md2_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020095
96/**
Paul Bakker5121ce52009-01-03 21:22:43 +000097 * \brief MD2 context setup
98 *
99 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100100 *
101 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100102 *
103 * \warning MD2 is considered a weak message digest and its use
104 * constitutes a security risk. We recommend considering
105 * stronger message digests instead.
106 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100108int mbedtls_md2_starts_ret(mbedtls_md2_context *ctx);
Paul Bakker5121ce52009-01-03 21:22:43 +0000109
110/**
111 * \brief MD2 process buffer
112 *
113 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100114 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000115 * \param ilen length of the input data
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 Peskine1b6c09a2023-01-11 14:52:35 +0100124int mbedtls_md2_update_ret(mbedtls_md2_context *ctx,
125 const unsigned char *input,
126 size_t ilen);
Paul Bakker5121ce52009-01-03 21:22:43 +0000127
128/**
129 * \brief MD2 final digest
130 *
131 * \param ctx MD2 context
132 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100133 *
134 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100135 *
136 * \warning MD2 is considered a weak message digest and its use
137 * constitutes a security risk. We recommend considering
138 * stronger message digests instead.
139 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000140 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100141int mbedtls_md2_finish_ret(mbedtls_md2_context *ctx,
142 unsigned char output[16]);
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100143
144/**
145 * \brief MD2 process data block (internal use only)
146 *
147 * \param ctx MD2 context
148 *
149 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100150 *
151 * \warning MD2 is considered a weak message digest and its use
152 * constitutes a security risk. We recommend considering
153 * stronger message digests instead.
154 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100155 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100156int mbedtls_internal_md2_process(mbedtls_md2_context *ctx);
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100157
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200158#if !defined(MBEDTLS_DEPRECATED_REMOVED)
159#if defined(MBEDTLS_DEPRECATED_WARNING)
160#define MBEDTLS_DEPRECATED __attribute__((deprecated))
161#else
162#define MBEDTLS_DEPRECATED
163#endif
164/**
165 * \brief MD2 context setup
166 *
167 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
168 *
169 * \param ctx context to be initialized
170 *
171 * \warning MD2 is considered a weak message digest and its use
172 * constitutes a security risk. We recommend considering
173 * stronger message digests instead.
174 *
175 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100176MBEDTLS_DEPRECATED void mbedtls_md2_starts(mbedtls_md2_context *ctx);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200177
178/**
179 * \brief MD2 process buffer
180 *
181 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
182 *
183 * \param ctx MD2 context
184 * \param input buffer holding the data
185 * \param ilen length of the input data
186 *
187 * \warning MD2 is considered a weak message digest and its use
188 * constitutes a security risk. We recommend considering
189 * stronger message digests instead.
190 *
191 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100192MBEDTLS_DEPRECATED void mbedtls_md2_update(mbedtls_md2_context *ctx,
193 const unsigned char *input,
194 size_t ilen);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200195
196/**
197 * \brief MD2 final digest
198 *
199 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
200 *
201 * \param ctx MD2 context
202 * \param output MD2 checksum result
203 *
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 *
208 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100209MBEDTLS_DEPRECATED void mbedtls_md2_finish(mbedtls_md2_context *ctx,
210 unsigned char output[16]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200211
212/**
213 * \brief MD2 process data block (internal use only)
214 *
215 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
216 *
217 * \param ctx MD2 context
218 *
219 * \warning MD2 is considered a weak message digest and its use
220 * constitutes a security risk. We recommend considering
221 * stronger message digests instead.
222 *
223 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100224MBEDTLS_DEPRECATED void mbedtls_md2_process(mbedtls_md2_context *ctx);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200225
226#undef MBEDTLS_DEPRECATED
227#endif /* !MBEDTLS_DEPRECATED_REMOVED */
228
Paul Bakker5121ce52009-01-03 21:22:43 +0000229/**
230 * \brief Output = MD2( input buffer )
231 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100232 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000233 * \param ilen length of the input data
234 * \param output MD2 checksum result
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 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000240 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100241int mbedtls_md2_ret(const unsigned char *input,
242 size_t ilen,
243 unsigned char output[16]);
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100244
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200245#if !defined(MBEDTLS_DEPRECATED_REMOVED)
246#if defined(MBEDTLS_DEPRECATED_WARNING)
247#define MBEDTLS_DEPRECATED __attribute__((deprecated))
248#else
249#define MBEDTLS_DEPRECATED
250#endif
251/**
252 * \brief Output = MD2( input buffer )
253 *
254 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
255 *
256 * \param input buffer holding the data
257 * \param ilen length of the input data
258 * \param output MD2 checksum result
259 *
260 * \warning MD2 is considered a weak message digest and its use
261 * constitutes a security risk. We recommend considering
262 * stronger message digests instead.
263 *
264 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100265MBEDTLS_DEPRECATED void mbedtls_md2(const unsigned char *input,
266 size_t ilen,
267 unsigned char output[16]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200268
269#undef MBEDTLS_DEPRECATED
270#endif /* !MBEDTLS_DEPRECATED_REMOVED */
271
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500272#if defined(MBEDTLS_SELF_TEST)
273
Paul Bakker5121ce52009-01-03 21:22:43 +0000274/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000275 * \brief Checkup routine
276 *
277 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100278 *
279 * \warning MD2 is considered a weak message digest and its use
280 * constitutes a security risk. We recommend considering
281 * stronger message digests instead.
282 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000283 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100284int mbedtls_md2_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000285
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500286#endif /* MBEDTLS_SELF_TEST */
287
Paul Bakker5121ce52009-01-03 21:22:43 +0000288#ifdef __cplusplus
289}
290#endif
291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292#endif /* mbedtls_md2.h */