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