Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 2 | * \file md2.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief MD2 message digest algorithm (hash function) |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 5 | * |
| 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 Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 9 | */ |
| 10 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 11 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 12 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 13 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 14 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 15 | #ifndef MBEDTLS_MD2_H |
| 16 | #define MBEDTLS_MD2_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 17 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 18 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 19 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 20 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 21 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 22 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 23 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 24 | #include <stddef.h> |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 25 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 26 | /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */ |
Gilles Peskine | a397443 | 2021-07-26 18:48:10 +0200 | [diff] [blame] | 27 | /** MD2 hardware accelerator failed */ |
| 28 | #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 29 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 34 | #if !defined(MBEDTLS_MD2_ALT) |
| 35 | // Regular implementation |
| 36 | // |
| 37 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 38 | /** |
| 39 | * \brief MD2 context structure |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 40 | * |
| 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 45 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 46 | typedef struct mbedtls_md2_context { |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 47 | 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 Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 50 | size_t left; /*!< amount of data in buffer */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | mbedtls_md2_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 53 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 54 | #else /* MBEDTLS_MD2_ALT */ |
| 55 | #include "md2_alt.h" |
| 56 | #endif /* MBEDTLS_MD2_ALT */ |
| 57 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 59 | * \brief Initialize MD2 context |
| 60 | * |
| 61 | * \param ctx MD2 context to be initialized |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 62 | * |
| 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 Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 67 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 68 | void mbedtls_md2_init(mbedtls_md2_context *ctx); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * \brief Clear MD2 context |
| 72 | * |
| 73 | * \param ctx MD2 context to be cleared |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 74 | * |
| 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 Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 79 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 80 | void mbedtls_md2_free(mbedtls_md2_context *ctx); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 81 | |
| 82 | /** |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 83 | * \brief Clone (the state of) an MD2 context |
| 84 | * |
| 85 | * \param dst The destination context |
| 86 | * \param src The context to be cloned |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 87 | * |
| 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é-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 92 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 93 | void mbedtls_md2_clone(mbedtls_md2_context *dst, |
| 94 | const mbedtls_md2_context *src); |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 95 | |
| 96 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 97 | * \brief MD2 context setup |
| 98 | * |
| 99 | * \param ctx context to be initialized |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 100 | * |
| 101 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 102 | * |
| 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 107 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 108 | int mbedtls_md2_starts_ret(mbedtls_md2_context *ctx); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * \brief MD2 process buffer |
| 112 | * |
| 113 | * \param ctx MD2 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 114 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 115 | * \param ilen length of the input data |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 116 | * |
| 117 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 118 | * |
| 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 123 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 124 | int mbedtls_md2_update_ret(mbedtls_md2_context *ctx, |
| 125 | const unsigned char *input, |
| 126 | size_t ilen); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * \brief MD2 final digest |
| 130 | * |
| 131 | * \param ctx MD2 context |
| 132 | * \param output MD2 checksum result |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 133 | * |
| 134 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 135 | * |
| 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 140 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 141 | int mbedtls_md2_finish_ret(mbedtls_md2_context *ctx, |
| 142 | unsigned char output[16]); |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * \brief MD2 process data block (internal use only) |
| 146 | * |
| 147 | * \param ctx MD2 context |
| 148 | * |
| 149 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 150 | * |
| 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 Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 155 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 156 | int mbedtls_internal_md2_process(mbedtls_md2_context *ctx); |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 157 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 158 | #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 Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 176 | MBEDTLS_DEPRECATED void mbedtls_md2_starts(mbedtls_md2_context *ctx); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 177 | |
| 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 Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 192 | MBEDTLS_DEPRECATED void mbedtls_md2_update(mbedtls_md2_context *ctx, |
| 193 | const unsigned char *input, |
| 194 | size_t ilen); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 195 | |
| 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 Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 209 | MBEDTLS_DEPRECATED void mbedtls_md2_finish(mbedtls_md2_context *ctx, |
| 210 | unsigned char output[16]); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 211 | |
| 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 Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 224 | MBEDTLS_DEPRECATED void mbedtls_md2_process(mbedtls_md2_context *ctx); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 225 | |
| 226 | #undef MBEDTLS_DEPRECATED |
| 227 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 228 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 229 | /** |
| 230 | * \brief Output = MD2( input buffer ) |
| 231 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 232 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 233 | * \param ilen length of the input data |
| 234 | * \param output MD2 checksum result |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 235 | * |
| 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 240 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 241 | int mbedtls_md2_ret(const unsigned char *input, |
| 242 | size_t ilen, |
| 243 | unsigned char output[16]); |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 244 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 245 | #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 Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 265 | MBEDTLS_DEPRECATED void mbedtls_md2(const unsigned char *input, |
| 266 | size_t ilen, |
| 267 | unsigned char output[16]); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 268 | |
| 269 | #undef MBEDTLS_DEPRECATED |
| 270 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 271 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 272 | #if defined(MBEDTLS_SELF_TEST) |
| 273 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 274 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 275 | * \brief Checkup routine |
| 276 | * |
| 277 | * \return 0 if successful, or 1 if the test failed |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 278 | * |
| 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 283 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 284 | int mbedtls_md2_self_test(int verbose); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 285 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 286 | #endif /* MBEDTLS_SELF_TEST */ |
| 287 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 288 | #ifdef __cplusplus |
| 289 | } |
| 290 | #endif |
| 291 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 292 | #endif /* mbedtls_md2.h */ |