1 /** 2 * \file md4.h 3 * 4 * \brief MD4 message digest algorithm (hash function) 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. 9 */ 10 /* 11 * Copyright The Mbed TLS Contributors 12 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 13 * 14 */ 15 #ifndef MBEDTLS_MD4_H 16 #define MBEDTLS_MD4_H 17 18 #if !defined(MBEDTLS_CONFIG_FILE) 19 #include "mbedtls/config.h" 20 #else 21 #include MBEDTLS_CONFIG_FILE 22 #endif 23 24 #include <stddef.h> 25 #include <stdint.h> 26 27 /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */ 28 /** MD4 hardware accelerator failed */ 29 #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #if !defined(MBEDTLS_MD4_ALT) 36 // Regular implementation 37 // 38 39 /** 40 * \brief MD4 context structure 41 * 42 * \warning MD4 is considered a weak message digest and its use 43 * constitutes a security risk. We recommend considering 44 * stronger message digests instead. 45 * 46 */ 47 typedef struct mbedtls_md4_context { 48 uint32_t total[2]; /*!< number of bytes processed */ 49 uint32_t state[4]; /*!< intermediate digest state */ 50 unsigned char buffer[64]; /*!< data block being processed */ 51 } 52 mbedtls_md4_context; 53 54 #else /* MBEDTLS_MD4_ALT */ 55 #include "md4_alt.h" 56 #endif /* MBEDTLS_MD4_ALT */ 57 58 /** 59 * \brief Initialize MD4 context 60 * 61 * \param ctx MD4 context to be initialized 62 * 63 * \warning MD4 is considered a weak message digest and its use 64 * constitutes a security risk. We recommend considering 65 * stronger message digests instead. 66 * 67 */ 68 void mbedtls_md4_init(mbedtls_md4_context *ctx); 69 70 /** 71 * \brief Clear MD4 context 72 * 73 * \param ctx MD4 context to be cleared 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 * 79 */ 80 void mbedtls_md4_free(mbedtls_md4_context *ctx); 81 82 /** 83 * \brief Clone (the state of) an MD4 context 84 * 85 * \param dst The destination context 86 * \param src The context to be cloned 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 * 92 */ 93 void mbedtls_md4_clone(mbedtls_md4_context *dst, 94 const mbedtls_md4_context *src); 95 96 /** 97 * \brief MD4 context setup 98 * 99 * \param ctx context to be initialized 100 * 101 * \return 0 if successful 102 * 103 * \warning MD4 is considered a weak message digest and its use 104 * constitutes a security risk. We recommend considering 105 * stronger message digests instead. 106 */ 107 int mbedtls_md4_starts_ret(mbedtls_md4_context *ctx); 108 109 /** 110 * \brief MD4 process buffer 111 * 112 * \param ctx MD4 context 113 * \param input buffer holding the data 114 * \param ilen length of the input data 115 * 116 * \return 0 if successful 117 * 118 * \warning MD4 is considered a weak message digest and its use 119 * constitutes a security risk. We recommend considering 120 * stronger message digests instead. 121 * 122 */ 123 int mbedtls_md4_update_ret(mbedtls_md4_context *ctx, 124 const unsigned char *input, 125 size_t ilen); 126 127 /** 128 * \brief MD4 final digest 129 * 130 * \param ctx MD4 context 131 * \param output MD4 checksum result 132 * 133 * \return 0 if successful 134 * 135 * \warning MD4 is considered a weak message digest and its use 136 * constitutes a security risk. We recommend considering 137 * stronger message digests instead. 138 * 139 */ 140 int mbedtls_md4_finish_ret(mbedtls_md4_context *ctx, 141 unsigned char output[16]); 142 143 /** 144 * \brief MD4 process data block (internal use only) 145 * 146 * \param ctx MD4 context 147 * \param data buffer holding one block of data 148 * 149 * \return 0 if successful 150 * 151 * \warning MD4 is considered a weak message digest and its use 152 * constitutes a security risk. We recommend considering 153 * stronger message digests instead. 154 * 155 */ 156 int mbedtls_internal_md4_process(mbedtls_md4_context *ctx, 157 const unsigned char data[64]); 158 159 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 160 #if defined(MBEDTLS_DEPRECATED_WARNING) 161 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 162 #else 163 #define MBEDTLS_DEPRECATED 164 #endif 165 /** 166 * \brief MD4 context setup 167 * 168 * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0 169 * 170 * \param ctx context to be initialized 171 * 172 * \warning MD4 is considered a weak message digest and its use 173 * constitutes a security risk. We recommend considering 174 * stronger message digests instead. 175 * 176 */ 177 MBEDTLS_DEPRECATED void mbedtls_md4_starts(mbedtls_md4_context *ctx); 178 179 /** 180 * \brief MD4 process buffer 181 * 182 * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0 183 * 184 * \param ctx MD4 context 185 * \param input buffer holding the data 186 * \param ilen length of the input data 187 * 188 * \warning MD4 is considered a weak message digest and its use 189 * constitutes a security risk. We recommend considering 190 * stronger message digests instead. 191 * 192 */ 193 MBEDTLS_DEPRECATED void mbedtls_md4_update(mbedtls_md4_context *ctx, 194 const unsigned char *input, 195 size_t ilen); 196 197 /** 198 * \brief MD4 final digest 199 * 200 * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0 201 * 202 * \param ctx MD4 context 203 * \param output MD4 checksum result 204 * 205 * \warning MD4 is considered a weak message digest and its use 206 * constitutes a security risk. We recommend considering 207 * stronger message digests instead. 208 * 209 */ 210 MBEDTLS_DEPRECATED void mbedtls_md4_finish(mbedtls_md4_context *ctx, 211 unsigned char output[16]); 212 213 /** 214 * \brief MD4 process data block (internal use only) 215 * 216 * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0 217 * 218 * \param ctx MD4 context 219 * \param data buffer holding one block of data 220 * 221 * \warning MD4 is considered a weak message digest and its use 222 * constitutes a security risk. We recommend considering 223 * stronger message digests instead. 224 * 225 */ 226 MBEDTLS_DEPRECATED void mbedtls_md4_process(mbedtls_md4_context *ctx, 227 const unsigned char data[64]); 228 229 #undef MBEDTLS_DEPRECATED 230 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 231 232 /** 233 * \brief Output = MD4( input buffer ) 234 * 235 * \param input buffer holding the data 236 * \param ilen length of the input data 237 * \param output MD4 checksum result 238 * 239 * \return 0 if successful 240 * 241 * \warning MD4 is considered a weak message digest and its use 242 * constitutes a security risk. We recommend considering 243 * stronger message digests instead. 244 * 245 */ 246 int mbedtls_md4_ret(const unsigned char *input, 247 size_t ilen, 248 unsigned char output[16]); 249 250 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 251 #if defined(MBEDTLS_DEPRECATED_WARNING) 252 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 253 #else 254 #define MBEDTLS_DEPRECATED 255 #endif 256 /** 257 * \brief Output = MD4( input buffer ) 258 * 259 * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0 260 * 261 * \param input buffer holding the data 262 * \param ilen length of the input data 263 * \param output MD4 checksum result 264 * 265 * \warning MD4 is considered a weak message digest and its use 266 * constitutes a security risk. We recommend considering 267 * stronger message digests instead. 268 * 269 */ 270 MBEDTLS_DEPRECATED void mbedtls_md4(const unsigned char *input, 271 size_t ilen, 272 unsigned char output[16]); 273 274 #undef MBEDTLS_DEPRECATED 275 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 276 277 #if defined(MBEDTLS_SELF_TEST) 278 279 /** 280 * \brief Checkup routine 281 * 282 * \return 0 if successful, or 1 if the test failed 283 * 284 * \warning MD4 is considered a weak message digest and its use 285 * constitutes a security risk. We recommend considering 286 * stronger message digests instead. 287 * 288 */ 289 int mbedtls_md4_self_test(int verbose); 290 291 #endif /* MBEDTLS_SELF_TEST */ 292 293 #ifdef __cplusplus 294 } 295 #endif 296 297 #endif /* mbedtls_md4.h */ 298