| 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 md5.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 MD5 message digest algorithm (hash function) | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 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. | 
| 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 | 
| Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 12 | *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 13 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 14 | #ifndef MBEDTLS_MD5_H | 
|  | 15 | #define MBEDTLS_MD5_H | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 16 | #include "mbedtls/private_access.h" | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 17 |  | 
| Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 18 | #include "mbedtls/build_info.h" | 
| Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 19 |  | 
| Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 20 | #include <stddef.h> | 
| Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 21 | #include <stdint.h> | 
| Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 22 |  | 
| Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 23 | #ifdef __cplusplus | 
|  | 24 | extern "C" { | 
|  | 25 | #endif | 
|  | 26 |  | 
| Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 27 | #if !defined(MBEDTLS_MD5_ALT) | 
|  | 28 | // Regular implementation | 
|  | 29 | // | 
|  | 30 |  | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 31 | /** | 
|  | 32 | * \brief          MD5 context structure | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 33 | * | 
|  | 34 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 35 | *                 constitutes a security risk. We recommend considering | 
|  | 36 | *                 stronger message digests instead. | 
|  | 37 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 38 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 39 | typedef struct mbedtls_md5_context { | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 40 | uint32_t MBEDTLS_PRIVATE(total)[2];          /*!< number of bytes processed  */ | 
|  | 41 | uint32_t MBEDTLS_PRIVATE(state)[4];          /*!< intermediate digest state  */ | 
|  | 42 | unsigned char MBEDTLS_PRIVATE(buffer)[64];   /*!< data block being processed */ | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 43 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 44 | mbedtls_md5_context; | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 45 |  | 
| Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 46 | #else  /* MBEDTLS_MD5_ALT */ | 
|  | 47 | #include "md5_alt.h" | 
|  | 48 | #endif /* MBEDTLS_MD5_ALT */ | 
|  | 49 |  | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 | /** | 
| Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 51 | * \brief          Initialize MD5 context | 
|  | 52 | * | 
|  | 53 | * \param ctx      MD5 context to be initialized | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 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 | * | 
| Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 59 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 60 | void mbedtls_md5_init(mbedtls_md5_context *ctx); | 
| Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 61 |  | 
|  | 62 | /** | 
|  | 63 | * \brief          Clear MD5 context | 
|  | 64 | * | 
|  | 65 | * \param ctx      MD5 context to be cleared | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 66 | * | 
|  | 67 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 68 | *                 constitutes a security risk. We recommend considering | 
|  | 69 | *                 stronger message digests instead. | 
|  | 70 | * | 
| Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 71 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 72 | void mbedtls_md5_free(mbedtls_md5_context *ctx); | 
| Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 73 |  | 
|  | 74 | /** | 
| Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 75 | * \brief          Clone (the state of) an MD5 context | 
|  | 76 | * | 
|  | 77 | * \param dst      The destination context | 
|  | 78 | * \param src      The context to be cloned | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 79 | * | 
|  | 80 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 81 | *                 constitutes a security risk. We recommend considering | 
|  | 82 | *                 stronger message digests instead. | 
|  | 83 | * | 
| Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 84 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 85 | void mbedtls_md5_clone(mbedtls_md5_context *dst, | 
|  | 86 | const mbedtls_md5_context *src); | 
| Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 87 |  | 
|  | 88 | /** | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 89 | * \brief          MD5 context setup | 
|  | 90 | * | 
|  | 91 | * \param ctx      context to be initialized | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 92 | * | 
|  | 93 | * \return         0 if successful | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 94 | * | 
|  | 95 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 96 | *                 constitutes a security risk. We recommend considering | 
|  | 97 | *                 stronger message digests instead. | 
|  | 98 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 99 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 100 | int mbedtls_md5_starts(mbedtls_md5_context *ctx); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 101 |  | 
|  | 102 | /** | 
|  | 103 | * \brief          MD5 process buffer | 
|  | 104 | * | 
|  | 105 | * \param ctx      MD5 context | 
| Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 106 | * \param input    buffer holding the data | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 107 | * \param ilen     length of the input data | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 108 | * | 
|  | 109 | * \return         0 if successful | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 110 | * | 
|  | 111 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 112 | *                 constitutes a security risk. We recommend considering | 
|  | 113 | *                 stronger message digests instead. | 
|  | 114 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 115 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 116 | int mbedtls_md5_update(mbedtls_md5_context *ctx, | 
|  | 117 | const unsigned char *input, | 
|  | 118 | size_t ilen); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 |  | 
|  | 120 | /** | 
|  | 121 | * \brief          MD5 final digest | 
|  | 122 | * | 
|  | 123 | * \param ctx      MD5 context | 
|  | 124 | * \param output   MD5 checksum result | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 125 | * | 
|  | 126 | * \return         0 if successful | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 127 | * | 
|  | 128 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 129 | *                 constitutes a security risk. We recommend considering | 
|  | 130 | *                 stronger message digests instead. | 
|  | 131 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 132 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 133 | int mbedtls_md5_finish(mbedtls_md5_context *ctx, | 
|  | 134 | unsigned char output[16]); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 |  | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 136 | /** | 
|  | 137 | * \brief          MD5 process data block (internal use only) | 
|  | 138 | * | 
|  | 139 | * \param ctx      MD5 context | 
|  | 140 | * \param data     buffer holding one block of data | 
|  | 141 | * | 
|  | 142 | * \return         0 if successful | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 143 | * | 
|  | 144 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 145 | *                 constitutes a security risk. We recommend considering | 
|  | 146 | *                 stronger message digests instead. | 
|  | 147 | * | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 148 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 149 | int mbedtls_internal_md5_process(mbedtls_md5_context *ctx, | 
|  | 150 | const unsigned char data[64]); | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 151 |  | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 152 | /** | 
|  | 153 | * \brief          Output = MD5( input buffer ) | 
|  | 154 | * | 
| Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 155 | * \param input    buffer holding the data | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 156 | * \param ilen     length of the input data | 
|  | 157 | * \param output   MD5 checksum result | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 158 | * | 
|  | 159 | * \return         0 if successful | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 160 | * | 
|  | 161 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 162 | *                 constitutes a security risk. We recommend considering | 
|  | 163 | *                 stronger message digests instead. | 
|  | 164 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 166 | int mbedtls_md5(const unsigned char *input, | 
|  | 167 | size_t ilen, | 
|  | 168 | unsigned char output[16]); | 
| Andres Amaya Garcia | 2cfd7a9 | 2017-05-02 10:19:27 +0100 | [diff] [blame] | 169 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 170 | #if defined(MBEDTLS_SELF_TEST) | 
|  | 171 |  | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 172 | /** | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 173 | * \brief          Checkup routine | 
|  | 174 | * | 
|  | 175 | * \return         0 if successful, or 1 if the test failed | 
| Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 176 | * | 
|  | 177 | * \warning        MD5 is considered a weak message digest and its use | 
|  | 178 | *                 constitutes a security risk. We recommend considering | 
|  | 179 | *                 stronger message digests instead. | 
|  | 180 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 181 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 182 | int mbedtls_md5_self_test(int verbose); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 183 |  | 
| Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 184 | #endif /* MBEDTLS_SELF_TEST */ | 
|  | 185 |  | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 186 | #ifdef __cplusplus | 
|  | 187 | } | 
|  | 188 | #endif | 
|  | 189 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 190 | #endif /* mbedtls_md5.h */ |