1 /** 2 * \file md5.h 3 * 4 * \brief MD5 message digest algorithm (hash function) 5 * 6 * \warning MD5 is considered a weak message digest and its use constitutes a 7 * security risk. We recommend considering stronger message 8 * digests instead. 9 */ 10 /* 11 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 12 * SPDX-License-Identifier: GPL-2.0 13 * 14 * This program is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation; either version 2 of the License, or 17 * (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License along 25 * with this program; if not, write to the Free Software Foundation, Inc., 26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 27 * 28 * This file is part of mbed TLS (https://tls.mbed.org) 29 */ 30 #ifndef MBEDTLS_MD5_H 31 #define MBEDTLS_MD5_H 32 33 #if !defined(MBEDTLS_CONFIG_FILE) 34 #include "config.h" 35 #else 36 #include MBEDTLS_CONFIG_FILE 37 #endif 38 39 #include <stddef.h> 40 #include <stdint.h> 41 42 #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */ 43 44 #if !defined(MBEDTLS_MD5_ALT) 45 // Regular implementation 46 // 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 /** 53 * \brief MD5 context structure 54 * 55 * \warning MD5 is considered a weak message digest and its use 56 * constitutes a security risk. We recommend considering 57 * stronger message digests instead. 58 * 59 */ 60 typedef struct 61 { 62 uint32_t total[2]; /*!< number of bytes processed */ 63 uint32_t state[4]; /*!< intermediate digest state */ 64 unsigned char buffer[64]; /*!< data block being processed */ 65 } 66 mbedtls_md5_context; 67 68 /** 69 * \brief Initialize MD5 context 70 * 71 * \param ctx MD5 context to be initialized 72 * 73 * \warning MD5 is considered a weak message digest and its use 74 * constitutes a security risk. We recommend considering 75 * stronger message digests instead. 76 * 77 */ 78 void mbedtls_md5_init( mbedtls_md5_context *ctx ); 79 80 /** 81 * \brief Clear MD5 context 82 * 83 * \param ctx MD5 context to be cleared 84 * 85 * \warning MD5 is considered a weak message digest and its use 86 * constitutes a security risk. We recommend considering 87 * stronger message digests instead. 88 * 89 */ 90 void mbedtls_md5_free( mbedtls_md5_context *ctx ); 91 92 /** 93 * \brief Clone (the state of) an MD5 context 94 * 95 * \param dst The destination context 96 * \param src The context to be cloned 97 * 98 * \warning MD5 is considered a weak message digest and its use 99 * constitutes a security risk. We recommend considering 100 * stronger message digests instead. 101 * 102 */ 103 void mbedtls_md5_clone( mbedtls_md5_context *dst, 104 const mbedtls_md5_context *src ); 105 106 /** 107 * \brief MD5 context setup 108 * 109 * \param ctx context to be initialized 110 * 111 * \return 0 if successful 112 * 113 * \warning MD5 is considered a weak message digest and its use 114 * constitutes a security risk. We recommend considering 115 * stronger message digests instead. 116 * 117 */ 118 int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx ); 119 120 /** 121 * \brief MD5 process buffer 122 * 123 * \param ctx MD5 context 124 * \param input buffer holding the data 125 * \param ilen length of the input data 126 * 127 * \return 0 if successful 128 * 129 * \warning MD5 is considered a weak message digest and its use 130 * constitutes a security risk. We recommend considering 131 * stronger message digests instead. 132 * 133 */ 134 int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, 135 const unsigned char *input, 136 size_t ilen ); 137 138 /** 139 * \brief MD5 final digest 140 * 141 * \param ctx MD5 context 142 * \param output MD5 checksum result 143 * 144 * \return 0 if successful 145 * 146 * \warning MD5 is considered a weak message digest and its use 147 * constitutes a security risk. We recommend considering 148 * stronger message digests instead. 149 * 150 */ 151 int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx, 152 unsigned char output[16] ); 153 154 /** 155 * \brief MD5 process data block (internal use only) 156 * 157 * \param ctx MD5 context 158 * \param data buffer holding one block of data 159 * 160 * \return 0 if successful 161 * 162 * \warning MD5 is considered a weak message digest and its use 163 * constitutes a security risk. We recommend considering 164 * stronger message digests instead. 165 * 166 */ 167 int mbedtls_internal_md5_process( mbedtls_md5_context *ctx, 168 const unsigned char data[64] ); 169 170 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 171 #if defined(MBEDTLS_DEPRECATED_WARNING) 172 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 173 #else 174 #define MBEDTLS_DEPRECATED 175 #endif 176 /** 177 * \brief MD5 context setup 178 * 179 * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0 180 * 181 * \param ctx context to be initialized 182 * 183 * \warning MD5 is considered a weak message digest and its use 184 * constitutes a security risk. We recommend considering 185 * stronger message digests instead. 186 * 187 */ 188 MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx ); 189 190 /** 191 * \brief MD5 process buffer 192 * 193 * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0 194 * 195 * \param ctx MD5 context 196 * \param input buffer holding the data 197 * \param ilen length of the input data 198 * 199 * \warning MD5 is considered a weak message digest and its use 200 * constitutes a security risk. We recommend considering 201 * stronger message digests instead. 202 * 203 */ 204 MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx, 205 const unsigned char *input, 206 size_t ilen ); 207 208 /** 209 * \brief MD5 final digest 210 * 211 * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0 212 * 213 * \param ctx MD5 context 214 * \param output MD5 checksum result 215 * 216 * \warning MD5 is considered a weak message digest and its use 217 * constitutes a security risk. We recommend considering 218 * stronger message digests instead. 219 * 220 */ 221 MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx, 222 unsigned char output[16] ); 223 224 /** 225 * \brief MD5 process data block (internal use only) 226 * 227 * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0 228 * 229 * \param ctx MD5 context 230 * \param data buffer holding one block of data 231 * 232 * \warning MD5 is considered a weak message digest and its use 233 * constitutes a security risk. We recommend considering 234 * stronger message digests instead. 235 * 236 */ 237 MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx, 238 const unsigned char data[64] ); 239 240 #undef MBEDTLS_DEPRECATED 241 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 242 243 #ifdef __cplusplus 244 } 245 #endif 246 247 #else /* MBEDTLS_MD5_ALT */ 248 #include "md5_alt.h" 249 #endif /* MBEDTLS_MD5_ALT */ 250 251 #ifdef __cplusplus 252 extern "C" { 253 #endif 254 255 /** 256 * \brief Output = MD5( input buffer ) 257 * 258 * \param input buffer holding the data 259 * \param ilen length of the input data 260 * \param output MD5 checksum result 261 * 262 * \return 0 if successful 263 * 264 * \warning MD5 is considered a weak message digest and its use 265 * constitutes a security risk. We recommend considering 266 * stronger message digests instead. 267 * 268 */ 269 int mbedtls_md5_ret( const unsigned char *input, 270 size_t ilen, 271 unsigned char output[16] ); 272 273 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 274 #if defined(MBEDTLS_DEPRECATED_WARNING) 275 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 276 #else 277 #define MBEDTLS_DEPRECATED 278 #endif 279 /** 280 * \brief Output = MD5( input buffer ) 281 * 282 * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0 283 * 284 * \param input buffer holding the data 285 * \param ilen length of the input data 286 * \param output MD5 checksum result 287 * 288 * \warning MD5 is considered a weak message digest and its use 289 * constitutes a security risk. We recommend considering 290 * stronger message digests instead. 291 * 292 */ 293 MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input, 294 size_t ilen, 295 unsigned char output[16] ); 296 297 #undef MBEDTLS_DEPRECATED 298 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 299 300 /** 301 * \brief Checkup routine 302 * 303 * \return 0 if successful, or 1 if the test failed 304 * 305 * \warning MD5 is considered a weak message digest and its use 306 * constitutes a security risk. We recommend considering 307 * stronger message digests instead. 308 * 309 */ 310 int mbedtls_md5_self_test( int verbose ); 311 312 #ifdef __cplusplus 313 } 314 #endif 315 316 #endif /* mbedtls_md5.h */ 317