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