Jaeden Amero | e54e693 | 2018-08-06 16:19:58 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file md2.h |
| 3 | * |
| 4 | * \brief MD2 message digest algorithm (hash function) |
| 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. |
| 9 | */ |
| 10 | /* |
| 11 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
| 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. |
| 25 | * |
| 26 | * This file is part of Mbed Crypto (https://tls.mbed.org) |
| 27 | * |
| 28 | */ |
| 29 | #ifndef MBEDCRYPTO_MD2_H |
| 30 | #define MBEDCRYPTO_MD2_H |
| 31 | |
| 32 | #if !defined(MBEDCRYPTO_CONFIG_FILE) |
| 33 | #include "config.h" |
| 34 | #else |
| 35 | #include MBEDCRYPTO_CONFIG_FILE |
| 36 | #endif |
| 37 | |
| 38 | #include <stddef.h> |
| 39 | |
| 40 | #define MBEDCRYPTO_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */ |
| 41 | |
| 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif |
| 45 | |
| 46 | #if !defined(MBEDCRYPTO_MD2_ALT) |
| 47 | // Regular implementation |
| 48 | // |
| 49 | |
| 50 | /** |
| 51 | * \brief MD2 context structure |
| 52 | * |
| 53 | * \warning MD2 is considered a weak message digest and its use |
| 54 | * constitutes a security risk. We recommend considering |
| 55 | * stronger message digests instead. |
| 56 | * |
| 57 | */ |
| 58 | typedef struct |
| 59 | { |
| 60 | unsigned char cksum[16]; /*!< checksum of the data block */ |
| 61 | unsigned char state[48]; /*!< intermediate digest state */ |
| 62 | unsigned char buffer[16]; /*!< data block being processed */ |
| 63 | size_t left; /*!< amount of data in buffer */ |
| 64 | } |
| 65 | mbedcrypto_md2_context; |
| 66 | |
| 67 | #else /* MBEDCRYPTO_MD2_ALT */ |
| 68 | #include "md2_alt.h" |
| 69 | #endif /* MBEDCRYPTO_MD2_ALT */ |
| 70 | |
| 71 | /** |
| 72 | * \brief Initialize MD2 context |
| 73 | * |
| 74 | * \param ctx MD2 context to be initialized |
| 75 | * |
| 76 | * \warning MD2 is considered a weak message digest and its use |
| 77 | * constitutes a security risk. We recommend considering |
| 78 | * stronger message digests instead. |
| 79 | * |
| 80 | */ |
| 81 | void mbedcrypto_md2_init( mbedcrypto_md2_context *ctx ); |
| 82 | |
| 83 | /** |
| 84 | * \brief Clear MD2 context |
| 85 | * |
| 86 | * \param ctx MD2 context to be cleared |
| 87 | * |
| 88 | * \warning MD2 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 mbedcrypto_md2_free( mbedcrypto_md2_context *ctx ); |
| 94 | |
| 95 | /** |
| 96 | * \brief Clone (the state of) an MD2 context |
| 97 | * |
| 98 | * \param dst The destination context |
| 99 | * \param src The context to be cloned |
| 100 | * |
| 101 | * \warning MD2 is considered a weak message digest and its use |
| 102 | * constitutes a security risk. We recommend considering |
| 103 | * stronger message digests instead. |
| 104 | * |
| 105 | */ |
| 106 | void mbedcrypto_md2_clone( mbedcrypto_md2_context *dst, |
| 107 | const mbedcrypto_md2_context *src ); |
| 108 | |
| 109 | /** |
| 110 | * \brief MD2 context setup |
| 111 | * |
| 112 | * \param ctx context to be initialized |
| 113 | * |
| 114 | * \return 0 if successful |
| 115 | * |
| 116 | * \warning MD2 is considered a weak message digest and its use |
| 117 | * constitutes a security risk. We recommend considering |
| 118 | * stronger message digests instead. |
| 119 | * |
| 120 | */ |
| 121 | int mbedcrypto_md2_starts_ret( mbedcrypto_md2_context *ctx ); |
| 122 | |
| 123 | /** |
| 124 | * \brief MD2 process buffer |
| 125 | * |
| 126 | * \param ctx MD2 context |
| 127 | * \param input buffer holding the data |
| 128 | * \param ilen length of the input data |
| 129 | * |
| 130 | * \return 0 if successful |
| 131 | * |
| 132 | * \warning MD2 is considered a weak message digest and its use |
| 133 | * constitutes a security risk. We recommend considering |
| 134 | * stronger message digests instead. |
| 135 | * |
| 136 | */ |
| 137 | int mbedcrypto_md2_update_ret( mbedcrypto_md2_context *ctx, |
| 138 | const unsigned char *input, |
| 139 | size_t ilen ); |
| 140 | |
| 141 | /** |
| 142 | * \brief MD2 final digest |
| 143 | * |
| 144 | * \param ctx MD2 context |
| 145 | * \param output MD2 checksum result |
| 146 | * |
| 147 | * \return 0 if successful |
| 148 | * |
| 149 | * \warning MD2 is considered a weak message digest and its use |
| 150 | * constitutes a security risk. We recommend considering |
| 151 | * stronger message digests instead. |
| 152 | * |
| 153 | */ |
| 154 | int mbedcrypto_md2_finish_ret( mbedcrypto_md2_context *ctx, |
| 155 | unsigned char output[16] ); |
| 156 | |
| 157 | /** |
| 158 | * \brief MD2 process data block (internal use only) |
| 159 | * |
| 160 | * \param ctx MD2 context |
| 161 | * |
| 162 | * \return 0 if successful |
| 163 | * |
| 164 | * \warning MD2 is considered a weak message digest and its use |
| 165 | * constitutes a security risk. We recommend considering |
| 166 | * stronger message digests instead. |
| 167 | * |
| 168 | */ |
| 169 | int mbedcrypto_internal_md2_process( mbedcrypto_md2_context *ctx ); |
| 170 | |
| 171 | #if !defined(MBEDCRYPTO_DEPRECATED_REMOVED) |
| 172 | #if defined(MBEDCRYPTO_DEPRECATED_WARNING) |
| 173 | #define MBEDCRYPTO_DEPRECATED __attribute__((deprecated)) |
| 174 | #else |
| 175 | #define MBEDCRYPTO_DEPRECATED |
| 176 | #endif |
| 177 | /** |
| 178 | * \brief MD2 context setup |
| 179 | * |
| 180 | * \deprecated Superseded by mbedcrypto_md2_starts_ret() in 2.7.0 |
| 181 | * |
| 182 | * \param ctx context to be initialized |
| 183 | * |
| 184 | * \warning MD2 is considered a weak message digest and its use |
| 185 | * constitutes a security risk. We recommend considering |
| 186 | * stronger message digests instead. |
| 187 | * |
| 188 | */ |
| 189 | MBEDCRYPTO_DEPRECATED void mbedcrypto_md2_starts( mbedcrypto_md2_context *ctx ); |
| 190 | |
| 191 | /** |
| 192 | * \brief MD2 process buffer |
| 193 | * |
| 194 | * \deprecated Superseded by mbedcrypto_md2_update_ret() in 2.7.0 |
| 195 | * |
| 196 | * \param ctx MD2 context |
| 197 | * \param input buffer holding the data |
| 198 | * \param ilen length of the input data |
| 199 | * |
| 200 | * \warning MD2 is considered a weak message digest and its use |
| 201 | * constitutes a security risk. We recommend considering |
| 202 | * stronger message digests instead. |
| 203 | * |
| 204 | */ |
| 205 | MBEDCRYPTO_DEPRECATED void mbedcrypto_md2_update( mbedcrypto_md2_context *ctx, |
| 206 | const unsigned char *input, |
| 207 | size_t ilen ); |
| 208 | |
| 209 | /** |
| 210 | * \brief MD2 final digest |
| 211 | * |
| 212 | * \deprecated Superseded by mbedcrypto_md2_finish_ret() in 2.7.0 |
| 213 | * |
| 214 | * \param ctx MD2 context |
| 215 | * \param output MD2 checksum result |
| 216 | * |
| 217 | * \warning MD2 is considered a weak message digest and its use |
| 218 | * constitutes a security risk. We recommend considering |
| 219 | * stronger message digests instead. |
| 220 | * |
| 221 | */ |
| 222 | MBEDCRYPTO_DEPRECATED void mbedcrypto_md2_finish( mbedcrypto_md2_context *ctx, |
| 223 | unsigned char output[16] ); |
| 224 | |
| 225 | /** |
| 226 | * \brief MD2 process data block (internal use only) |
| 227 | * |
| 228 | * \deprecated Superseded by mbedcrypto_internal_md2_process() in 2.7.0 |
| 229 | * |
| 230 | * \param ctx MD2 context |
| 231 | * |
| 232 | * \warning MD2 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 | MBEDCRYPTO_DEPRECATED void mbedcrypto_md2_process( mbedcrypto_md2_context *ctx ); |
| 238 | |
| 239 | #undef MBEDCRYPTO_DEPRECATED |
| 240 | #endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */ |
| 241 | |
| 242 | /** |
| 243 | * \brief Output = MD2( input buffer ) |
| 244 | * |
| 245 | * \param input buffer holding the data |
| 246 | * \param ilen length of the input data |
| 247 | * \param output MD2 checksum result |
| 248 | * |
| 249 | * \warning MD2 is considered a weak message digest and its use |
| 250 | * constitutes a security risk. We recommend considering |
| 251 | * stronger message digests instead. |
| 252 | * |
| 253 | */ |
| 254 | int mbedcrypto_md2_ret( const unsigned char *input, |
| 255 | size_t ilen, |
| 256 | unsigned char output[16] ); |
| 257 | |
| 258 | #if !defined(MBEDCRYPTO_DEPRECATED_REMOVED) |
| 259 | #if defined(MBEDCRYPTO_DEPRECATED_WARNING) |
| 260 | #define MBEDCRYPTO_DEPRECATED __attribute__((deprecated)) |
| 261 | #else |
| 262 | #define MBEDCRYPTO_DEPRECATED |
| 263 | #endif |
| 264 | /** |
| 265 | * \brief Output = MD2( input buffer ) |
| 266 | * |
| 267 | * \deprecated Superseded by mbedcrypto_md2_ret() in 2.7.0 |
| 268 | * |
| 269 | * \param input buffer holding the data |
| 270 | * \param ilen length of the input data |
| 271 | * \param output MD2 checksum result |
| 272 | * |
| 273 | * \warning MD2 is considered a weak message digest and its use |
| 274 | * constitutes a security risk. We recommend considering |
| 275 | * stronger message digests instead. |
| 276 | * |
| 277 | */ |
| 278 | MBEDCRYPTO_DEPRECATED void mbedcrypto_md2( const unsigned char *input, |
| 279 | size_t ilen, |
| 280 | unsigned char output[16] ); |
| 281 | |
| 282 | #undef MBEDCRYPTO_DEPRECATED |
| 283 | #endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */ |
| 284 | |
| 285 | /** |
| 286 | * \brief Checkup routine |
| 287 | * |
| 288 | * \return 0 if successful, or 1 if the test failed |
| 289 | * |
| 290 | * \warning MD2 is considered a weak message digest and its use |
| 291 | * constitutes a security risk. We recommend considering |
| 292 | * stronger message digests instead. |
| 293 | * |
| 294 | */ |
| 295 | int mbedcrypto_md2_self_test( int verbose ); |
| 296 | |
| 297 | #ifdef __cplusplus |
| 298 | } |
| 299 | #endif |
| 300 | |
| 301 | #endif /* mbedcrypto_md2.h */ |