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 md4.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 MD4 message digest algorithm (hash function) |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 5 | * |
| 6 | * \warning MD4 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 |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 12 | * 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 Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 25 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 27 | #ifndef MBEDTLS_MD4_H |
| 28 | #define MBEDTLS_MD4_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 29 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 30 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 31 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 32 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 33 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 34 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 35 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 36 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 37 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 38 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 39 | /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */ |
Gilles Peskine | a397443 | 2021-07-26 18:48:10 +0200 | [diff] [blame^] | 40 | /** MD4 hardware accelerator failed */ |
| 41 | #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 42 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 43 | #ifdef __cplusplus |
| 44 | extern "C" { |
| 45 | #endif |
| 46 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 47 | #if !defined(MBEDTLS_MD4_ALT) |
| 48 | // Regular implementation |
| 49 | // |
| 50 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | /** |
| 52 | * \brief MD4 context structure |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 53 | * |
| 54 | * \warning MD4 is considered a weak message digest and its use |
| 55 | * constitutes a security risk. We recommend considering |
| 56 | * stronger message digests instead. |
| 57 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 59 | typedef struct mbedtls_md4_context |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 60 | { |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 61 | uint32_t total[2]; /*!< number of bytes processed */ |
| 62 | uint32_t state[4]; /*!< intermediate digest state */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 63 | unsigned char buffer[64]; /*!< data block being processed */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 64 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 65 | mbedtls_md4_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 66 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 67 | #else /* MBEDTLS_MD4_ALT */ |
| 68 | #include "md4_alt.h" |
| 69 | #endif /* MBEDTLS_MD4_ALT */ |
| 70 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 71 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 72 | * \brief Initialize MD4 context |
| 73 | * |
| 74 | * \param ctx MD4 context to be initialized |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 75 | * |
| 76 | * \warning MD4 is considered a weak message digest and its use |
| 77 | * constitutes a security risk. We recommend considering |
| 78 | * stronger message digests instead. |
| 79 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 80 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 81 | void mbedtls_md4_init( mbedtls_md4_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * \brief Clear MD4 context |
| 85 | * |
| 86 | * \param ctx MD4 context to be cleared |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 87 | * |
| 88 | * \warning MD4 is considered a weak message digest and its use |
| 89 | * constitutes a security risk. We recommend considering |
| 90 | * stronger message digests instead. |
| 91 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 92 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | void mbedtls_md4_free( mbedtls_md4_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 94 | |
| 95 | /** |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 96 | * \brief Clone (the state of) an MD4 context |
| 97 | * |
| 98 | * \param dst The destination context |
| 99 | * \param src The context to be cloned |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 100 | * |
| 101 | * \warning MD4 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é-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 105 | */ |
| 106 | void mbedtls_md4_clone( mbedtls_md4_context *dst, |
| 107 | const mbedtls_md4_context *src ); |
| 108 | |
| 109 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 110 | * \brief MD4 context setup |
| 111 | * |
| 112 | * \param ctx context to be initialized |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 113 | * |
| 114 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 115 | * |
| 116 | * \warning MD4 is considered a weak message digest and its use |
| 117 | * constitutes a security risk. We recommend considering |
| 118 | * stronger message digests instead. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 120 | int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * \brief MD4 process buffer |
| 124 | * |
| 125 | * \param ctx MD4 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 126 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 127 | * \param ilen length of the input data |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 128 | * |
| 129 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 130 | * |
| 131 | * \warning MD4 is considered a weak message digest and its use |
| 132 | * constitutes a security risk. We recommend considering |
| 133 | * stronger message digests instead. |
| 134 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 136 | int mbedtls_md4_update_ret( mbedtls_md4_context *ctx, |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 137 | const unsigned char *input, |
| 138 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * \brief MD4 final digest |
| 142 | * |
| 143 | * \param ctx MD4 context |
| 144 | * \param output MD4 checksum result |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 145 | * |
| 146 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 147 | * |
| 148 | * \warning MD4 is considered a weak message digest and its use |
| 149 | * constitutes a security risk. We recommend considering |
| 150 | * stronger message digests instead. |
| 151 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 152 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 153 | int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx, |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 154 | unsigned char output[16] ); |
| 155 | |
| 156 | /** |
| 157 | * \brief MD4 process data block (internal use only) |
| 158 | * |
| 159 | * \param ctx MD4 context |
| 160 | * \param data buffer holding one block of data |
| 161 | * |
| 162 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 163 | * |
| 164 | * \warning MD4 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 Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 168 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 169 | int mbedtls_internal_md4_process( mbedtls_md4_context *ctx, |
| 170 | const unsigned char data[64] ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 171 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 172 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 173 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 174 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 175 | #else |
| 176 | #define MBEDTLS_DEPRECATED |
| 177 | #endif |
| 178 | /** |
| 179 | * \brief MD4 context setup |
| 180 | * |
| 181 | * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0 |
| 182 | * |
| 183 | * \param ctx context to be initialized |
| 184 | * |
| 185 | * \warning MD4 is considered a weak message digest and its use |
| 186 | * constitutes a security risk. We recommend considering |
| 187 | * stronger message digests instead. |
| 188 | * |
| 189 | */ |
| 190 | MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx ); |
| 191 | |
| 192 | /** |
| 193 | * \brief MD4 process buffer |
| 194 | * |
| 195 | * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0 |
| 196 | * |
| 197 | * \param ctx MD4 context |
| 198 | * \param input buffer holding the data |
| 199 | * \param ilen length of the input data |
| 200 | * |
| 201 | * \warning MD4 is considered a weak message digest and its use |
| 202 | * constitutes a security risk. We recommend considering |
| 203 | * stronger message digests instead. |
| 204 | * |
| 205 | */ |
| 206 | MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx, |
| 207 | const unsigned char *input, |
| 208 | size_t ilen ); |
| 209 | |
| 210 | /** |
| 211 | * \brief MD4 final digest |
| 212 | * |
| 213 | * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0 |
| 214 | * |
| 215 | * \param ctx MD4 context |
| 216 | * \param output MD4 checksum result |
| 217 | * |
| 218 | * \warning MD4 is considered a weak message digest and its use |
| 219 | * constitutes a security risk. We recommend considering |
| 220 | * stronger message digests instead. |
| 221 | * |
| 222 | */ |
| 223 | MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx, |
| 224 | unsigned char output[16] ); |
| 225 | |
| 226 | /** |
| 227 | * \brief MD4 process data block (internal use only) |
| 228 | * |
| 229 | * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0 |
| 230 | * |
| 231 | * \param ctx MD4 context |
| 232 | * \param data buffer holding one block of data |
| 233 | * |
| 234 | * \warning MD4 is considered a weak message digest and its use |
| 235 | * constitutes a security risk. We recommend considering |
| 236 | * stronger message digests instead. |
| 237 | * |
| 238 | */ |
| 239 | MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx, |
| 240 | const unsigned char data[64] ); |
| 241 | |
| 242 | #undef MBEDTLS_DEPRECATED |
| 243 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 244 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 245 | /** |
| 246 | * \brief Output = MD4( input buffer ) |
| 247 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 248 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 249 | * \param ilen length of the input data |
| 250 | * \param output MD4 checksum result |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 251 | * |
| 252 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 253 | * |
| 254 | * \warning MD4 is considered a weak message digest and its use |
| 255 | * constitutes a security risk. We recommend considering |
| 256 | * stronger message digests instead. |
| 257 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 258 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 259 | int mbedtls_md4_ret( const unsigned char *input, |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 260 | size_t ilen, |
| 261 | unsigned char output[16] ); |
| 262 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 263 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 264 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 265 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 266 | #else |
| 267 | #define MBEDTLS_DEPRECATED |
| 268 | #endif |
| 269 | /** |
| 270 | * \brief Output = MD4( input buffer ) |
| 271 | * |
| 272 | * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0 |
| 273 | * |
| 274 | * \param input buffer holding the data |
| 275 | * \param ilen length of the input data |
| 276 | * \param output MD4 checksum result |
| 277 | * |
| 278 | * \warning MD4 is considered a weak message digest and its use |
| 279 | * constitutes a security risk. We recommend considering |
| 280 | * stronger message digests instead. |
| 281 | * |
| 282 | */ |
| 283 | MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input, |
| 284 | size_t ilen, |
| 285 | unsigned char output[16] ); |
| 286 | |
| 287 | #undef MBEDTLS_DEPRECATED |
| 288 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 289 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 290 | #if defined(MBEDTLS_SELF_TEST) |
| 291 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 292 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 293 | * \brief Checkup routine |
| 294 | * |
| 295 | * \return 0 if successful, or 1 if the test failed |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 296 | * |
| 297 | * \warning MD4 is considered a weak message digest and its use |
| 298 | * constitutes a security risk. We recommend considering |
| 299 | * stronger message digests instead. |
| 300 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 301 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 302 | int mbedtls_md4_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 303 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 304 | #endif /* MBEDTLS_SELF_TEST */ |
| 305 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 306 | #ifdef __cplusplus |
| 307 | } |
| 308 | #endif |
| 309 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 310 | #endif /* mbedtls_md4.h */ |