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 md2.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 MD2 message digest algorithm (hash function) |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 5 | * |
| 6 | * \warning MD2 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_MD2_H |
| 28 | #define MBEDTLS_MD2_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 29 | #include "mbedtls/private_access.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 30 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 31 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 32 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 33 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 34 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 35 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 36 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 37 | #include <stddef.h> |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 38 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 39 | #ifdef __cplusplus |
| 40 | extern "C" { |
| 41 | #endif |
| 42 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 43 | #if !defined(MBEDTLS_MD2_ALT) |
| 44 | // Regular implementation |
| 45 | // |
| 46 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 47 | /** |
| 48 | * \brief MD2 context structure |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 49 | * |
| 50 | * \warning MD2 is considered a weak message digest and its use |
| 51 | * constitutes a security risk. We recommend considering |
| 52 | * stronger message digests instead. |
| 53 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 55 | typedef struct mbedtls_md2_context |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 56 | { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 57 | unsigned char MBEDTLS_PRIVATE(cksum)[16]; /*!< checksum of the data block */ |
| 58 | unsigned char MBEDTLS_PRIVATE(state)[48]; /*!< intermediate digest state */ |
| 59 | unsigned char MBEDTLS_PRIVATE(buffer)[16]; /*!< data block being processed */ |
| 60 | size_t MBEDTLS_PRIVATE(left); /*!< amount of data in buffer */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 61 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | mbedtls_md2_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 63 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 64 | #else /* MBEDTLS_MD2_ALT */ |
| 65 | #include "md2_alt.h" |
| 66 | #endif /* MBEDTLS_MD2_ALT */ |
| 67 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 68 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 69 | * \brief Initialize MD2 context |
| 70 | * |
| 71 | * \param ctx MD2 context to be initialized |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 72 | * |
| 73 | * \warning MD2 is considered a weak message digest and its use |
| 74 | * constitutes a security risk. We recommend considering |
| 75 | * stronger message digests instead. |
| 76 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 77 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 78 | void mbedtls_md2_init( mbedtls_md2_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * \brief Clear MD2 context |
| 82 | * |
| 83 | * \param ctx MD2 context to be cleared |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 84 | * |
| 85 | * \warning MD2 is considered a weak message digest and its use |
| 86 | * constitutes a security risk. We recommend considering |
| 87 | * stronger message digests instead. |
| 88 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 89 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | void mbedtls_md2_free( mbedtls_md2_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 91 | |
| 92 | /** |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 93 | * \brief Clone (the state of) an MD2 context |
| 94 | * |
| 95 | * \param dst The destination context |
| 96 | * \param src The context to be cloned |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 97 | * |
| 98 | * \warning MD2 is considered a weak message digest and its use |
| 99 | * constitutes a security risk. We recommend considering |
| 100 | * stronger message digests instead. |
| 101 | * |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 102 | */ |
| 103 | void mbedtls_md2_clone( mbedtls_md2_context *dst, |
| 104 | const mbedtls_md2_context *src ); |
| 105 | |
| 106 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 107 | * \brief MD2 context setup |
| 108 | * |
| 109 | * \param ctx context to be initialized |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 110 | * |
| 111 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 112 | * |
| 113 | * \warning MD2 is considered a weak message digest and its use |
| 114 | * constitutes a security risk. We recommend considering |
| 115 | * stronger message digests instead. |
| 116 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 117 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 118 | int mbedtls_md2_starts( mbedtls_md2_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * \brief MD2 process buffer |
| 122 | * |
| 123 | * \param ctx MD2 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 124 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 125 | * \param ilen length of the input data |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 126 | * |
| 127 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 128 | * |
| 129 | * \warning MD2 is considered a weak message digest and its use |
| 130 | * constitutes a security risk. We recommend considering |
| 131 | * stronger message digests instead. |
| 132 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 133 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 134 | int mbedtls_md2_update( mbedtls_md2_context *ctx, |
| 135 | const unsigned char *input, |
| 136 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * \brief MD2 final digest |
| 140 | * |
| 141 | * \param ctx MD2 context |
| 142 | * \param output MD2 checksum result |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 143 | * |
| 144 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 145 | * |
| 146 | * \warning MD2 is considered a weak message digest and its use |
| 147 | * constitutes a security risk. We recommend considering |
| 148 | * stronger message digests instead. |
| 149 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 150 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 151 | int mbedtls_md2_finish( mbedtls_md2_context *ctx, |
| 152 | unsigned char output[16] ); |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * \brief MD2 process data block (internal use only) |
| 156 | * |
| 157 | * \param ctx MD2 context |
| 158 | * |
| 159 | * \return 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 160 | * |
| 161 | * \warning MD2 is considered a weak message digest and its use |
| 162 | * constitutes a security risk. We recommend considering |
| 163 | * stronger message digests instead. |
| 164 | * |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 165 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 166 | int mbedtls_internal_md2_process( mbedtls_md2_context *ctx ); |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 167 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 168 | /** |
| 169 | * \brief Output = MD2( input buffer ) |
| 170 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 171 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 172 | * \param ilen length of the input data |
| 173 | * \param output MD2 checksum result |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 174 | * |
| 175 | * \warning MD2 is considered a weak message digest and its use |
| 176 | * constitutes a security risk. We recommend considering |
| 177 | * stronger message digests instead. |
| 178 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 179 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 180 | int mbedtls_md2( const unsigned char *input, |
| 181 | size_t ilen, |
| 182 | unsigned char output[16] ); |
Andres Amaya Garcia | 1d85213 | 2017-04-28 16:21:40 +0100 | [diff] [blame] | 183 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 184 | #if defined(MBEDTLS_SELF_TEST) |
| 185 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 186 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 187 | * \brief Checkup routine |
| 188 | * |
| 189 | * \return 0 if successful, or 1 if the test failed |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 190 | * |
| 191 | * \warning MD2 is considered a weak message digest and its use |
| 192 | * constitutes a security risk. We recommend considering |
| 193 | * stronger message digests instead. |
| 194 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 195 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | int mbedtls_md2_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 197 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 198 | #endif /* MBEDTLS_SELF_TEST */ |
| 199 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 200 | #ifdef __cplusplus |
| 201 | } |
| 202 | #endif |
| 203 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 204 | #endif /* mbedtls_md2.h */ |