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) |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 21 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 22 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 23 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 24 | #ifndef MBEDTLS_MD4_H |
| 25 | #define MBEDTLS_MD4_H |
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 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 28 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 30 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 31 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 32 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 33 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 34 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 35 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 36 | #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */ |
| 37 | |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 38 | #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ |
| 39 | !defined(inline) && !defined(__cplusplus) |
| 40 | #define inline __inline |
| 41 | #endif |
| 42 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | #if !defined(MBEDTLS_MD4_ALT) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 44 | // Regular implementation |
| 45 | // |
| 46 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif |
| 50 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | /** |
| 52 | * \brief MD4 context structure |
| 53 | */ |
| 54 | typedef struct |
| 55 | { |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 56 | uint32_t total[2]; /*!< number of bytes processed */ |
| 57 | uint32_t state[4]; /*!< intermediate digest state */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | unsigned char buffer[64]; /*!< data block being processed */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 59 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | mbedtls_md4_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 61 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 62 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 63 | * \brief Initialize MD4 context |
| 64 | * |
| 65 | * \param ctx MD4 context to be initialized |
| 66 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 67 | void mbedtls_md4_init( mbedtls_md4_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * \brief Clear MD4 context |
| 71 | * |
| 72 | * \param ctx MD4 context to be cleared |
| 73 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | void mbedtls_md4_free( mbedtls_md4_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 75 | |
| 76 | /** |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 77 | * \brief Clone (the state of) an MD4 context |
| 78 | * |
| 79 | * \param dst The destination context |
| 80 | * \param src The context to be cloned |
| 81 | */ |
| 82 | void mbedtls_md4_clone( mbedtls_md4_context *dst, |
| 83 | const mbedtls_md4_context *src ); |
| 84 | |
| 85 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 86 | * \brief MD4 context setup |
| 87 | * |
| 88 | * \param ctx context to be initialized |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 89 | * |
| 90 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 92 | int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * \brief MD4 process buffer |
| 96 | * |
| 97 | * \param ctx MD4 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 98 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 99 | * \param ilen length of the input data |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 100 | * |
| 101 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 102 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 103 | int mbedtls_md4_update_ret( mbedtls_md4_context *ctx, |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 104 | const unsigned char *input, |
| 105 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * \brief MD4 final digest |
| 109 | * |
| 110 | * \param ctx MD4 context |
| 111 | * \param output MD4 checksum result |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 112 | * |
| 113 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 114 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 115 | int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx, |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 116 | unsigned char output[16] ); |
| 117 | |
| 118 | /** |
| 119 | * \brief MD4 process data block (internal use only) |
| 120 | * |
| 121 | * \param ctx MD4 context |
| 122 | * \param data buffer holding one block of data |
| 123 | * |
| 124 | * \return 0 if successful |
| 125 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 126 | int mbedtls_internal_md4_process( mbedtls_md4_context *ctx, |
| 127 | const unsigned char data[64] ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 128 | |
| 129 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 130 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 131 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 132 | #else |
| 133 | #define MBEDTLS_DEPRECATED |
| 134 | #endif |
| 135 | /** |
| 136 | * \brief MD4 context setup |
| 137 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 138 | * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0 |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 139 | * |
| 140 | * \param ctx context to be initialized |
| 141 | */ |
| 142 | MBEDTLS_DEPRECATED static inline void mbedtls_md4_starts( |
| 143 | mbedtls_md4_context *ctx ) |
| 144 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 145 | mbedtls_md4_starts_ret( ctx ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
| 149 | * \brief MD4 process buffer |
| 150 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 151 | * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0 |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 152 | * |
| 153 | * \param ctx MD4 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 154 | * \param input buffer holding the data |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 155 | * \param ilen length of the input data |
| 156 | */ |
| 157 | MBEDTLS_DEPRECATED static inline void mbedtls_md4_update( |
| 158 | mbedtls_md4_context *ctx, |
| 159 | const unsigned char *input, |
| 160 | size_t ilen ) |
| 161 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 162 | mbedtls_md4_update_ret( ctx, input, ilen ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
| 166 | * \brief MD4 final digest |
| 167 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 168 | * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0 |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 169 | * |
| 170 | * \param ctx MD4 context |
| 171 | * \param output MD4 checksum result |
| 172 | */ |
| 173 | MBEDTLS_DEPRECATED static inline void mbedtls_md4_finish( |
| 174 | mbedtls_md4_context *ctx, |
| 175 | unsigned char output[16] ) |
| 176 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 177 | mbedtls_md4_finish_ret( ctx, output ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
| 181 | * \brief MD4 process data block (internal use only) |
| 182 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 183 | * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0 |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 184 | * |
| 185 | * \param ctx MD4 context |
| 186 | * \param data buffer holding one block of data |
| 187 | */ |
| 188 | MBEDTLS_DEPRECATED static inline void mbedtls_md4_process( |
| 189 | mbedtls_md4_context *ctx, |
| 190 | const unsigned char data[64] ) |
| 191 | { |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 192 | mbedtls_internal_md4_process( ctx, data ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | #undef MBEDTLS_DEPRECATED |
| 196 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 197 | |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 198 | #ifdef __cplusplus |
| 199 | } |
| 200 | #endif |
| 201 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 202 | #else /* MBEDTLS_MD4_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 203 | #include "md4_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 204 | #endif /* MBEDTLS_MD4_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 205 | |
| 206 | #ifdef __cplusplus |
| 207 | extern "C" { |
| 208 | #endif |
| 209 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 210 | /** |
| 211 | * \brief Output = MD4( input buffer ) |
| 212 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 213 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 214 | * \param ilen length of the input data |
| 215 | * \param output MD4 checksum result |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 216 | * |
| 217 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 218 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 219 | int mbedtls_md4_ret( const unsigned char *input, |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 220 | size_t ilen, |
| 221 | unsigned char output[16] ); |
| 222 | |
| 223 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 224 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 225 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 226 | #else |
| 227 | #define MBEDTLS_DEPRECATED |
| 228 | #endif |
| 229 | /** |
| 230 | * \brief Output = MD4( input buffer ) |
| 231 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 232 | * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0 |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 233 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 234 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 235 | * \param ilen length of the input data |
| 236 | * \param output MD4 checksum result |
| 237 | */ |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 238 | MBEDTLS_DEPRECATED static inline void mbedtls_md4( const unsigned char *input, |
| 239 | size_t ilen, |
| 240 | unsigned char output[16] ) |
| 241 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 242 | mbedtls_md4_ret( input, ilen, output ); |
Andres Amaya Garcia | bee0635 | 2017-04-28 17:00:30 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | #undef MBEDTLS_DEPRECATED |
| 246 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 247 | |
| 248 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 249 | * \brief Checkup routine |
| 250 | * |
| 251 | * \return 0 if successful, or 1 if the test failed |
| 252 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 253 | int mbedtls_md4_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 254 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 255 | #ifdef __cplusplus |
| 256 | } |
| 257 | #endif |
| 258 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 259 | #endif /* mbedtls_md4.h */ |