Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 1 | /** |
Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 2 | * \file ripemd160.h |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 3 | * |
| 4 | * \brief RIPE MD-160 message digest |
| 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 | 61b699e | 2014-01-22 13:35:29 +0100 | [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 | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 22 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #ifndef MBEDTLS_RIPEMD160_H |
| 24 | #define MBEDTLS_RIPEMD160_H |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [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 | 61b699e | 2014-01-22 13:35:29 +0100 | [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 | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 31 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 32 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 33 | #include <stdint.h> |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 34 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 35 | #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */ |
| 36 | |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 37 | #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ |
| 38 | !defined(inline) && !defined(__cplusplus) |
| 39 | #define inline __inline |
| 40 | #endif |
| 41 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 42 | #if !defined(MBEDTLS_RIPEMD160_ALT) |
Paul Bakker | 9f4c162 | 2014-01-22 14:14:26 +0100 | [diff] [blame] | 43 | // Regular implementation |
| 44 | // |
| 45 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
| 50 | /** |
| 51 | * \brief RIPEMD-160 context structure |
| 52 | */ |
| 53 | typedef struct |
| 54 | { |
| 55 | uint32_t total[2]; /*!< number of bytes processed */ |
| 56 | uint32_t state[5]; /*!< intermediate digest state */ |
| 57 | unsigned char buffer[64]; /*!< data block being processed */ |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 58 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 59 | mbedtls_ripemd160_context; |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 60 | |
| 61 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 62 | * \brief Initialize RIPEMD-160 context |
| 63 | * |
| 64 | * \param ctx RIPEMD-160 context to be initialized |
| 65 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * \brief Clear RIPEMD-160 context |
| 70 | * |
| 71 | * \param ctx RIPEMD-160 context to be cleared |
| 72 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 73 | void mbedtls_ripemd160_free( mbedtls_ripemd160_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 RIPEMD-160 context |
| 77 | * |
| 78 | * \param dst The destination context |
| 79 | * \param src The context to be cloned |
| 80 | */ |
| 81 | void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, |
| 82 | const mbedtls_ripemd160_context *src ); |
| 83 | |
| 84 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 85 | * \brief RIPEMD-160 context setup |
| 86 | * |
| 87 | * \param ctx context to be initialized |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 88 | * |
| 89 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 90 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 91 | int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * \brief RIPEMD-160 process buffer |
| 95 | * |
| 96 | * \param ctx RIPEMD-160 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 97 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 98 | * \param ilen length of the input data |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 99 | * |
| 100 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 101 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 102 | int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 103 | const unsigned char *input, |
| 104 | size_t ilen ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * \brief RIPEMD-160 final digest |
| 108 | * |
| 109 | * \param ctx RIPEMD-160 context |
| 110 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 111 | * |
| 112 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 113 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 114 | int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 115 | unsigned char output[20] ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 116 | |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 117 | /** |
| 118 | * \brief RIPEMD-160 process data block (internal use only) |
| 119 | * |
| 120 | * \param ctx RIPEMD-160 context |
| 121 | * \param data buffer holding one block of data |
| 122 | * |
| 123 | * \return 0 if successful |
| 124 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 125 | int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx, |
| 126 | const unsigned char data[64] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 127 | |
| 128 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 129 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 130 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 131 | #else |
| 132 | #define MBEDTLS_DEPRECATED |
| 133 | #endif |
| 134 | /** |
| 135 | * \brief RIPEMD-160 context setup |
| 136 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 137 | * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 138 | * |
| 139 | * \param ctx context to be initialized |
| 140 | */ |
| 141 | MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_starts( |
| 142 | mbedtls_ripemd160_context *ctx ) |
| 143 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 144 | mbedtls_ripemd160_starts_ret( ctx ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
| 148 | * \brief RIPEMD-160 process buffer |
| 149 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 150 | * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 151 | * |
| 152 | * \param ctx RIPEMD-160 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 153 | * \param input buffer holding the data |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 154 | * \param ilen length of the input data |
| 155 | */ |
| 156 | MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_update( |
| 157 | mbedtls_ripemd160_context *ctx, |
| 158 | const unsigned char *input, |
| 159 | size_t ilen ) |
| 160 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 161 | mbedtls_ripemd160_update_ret( ctx, input, ilen ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
| 165 | * \brief RIPEMD-160 final digest |
| 166 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 167 | * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 168 | * |
| 169 | * \param ctx RIPEMD-160 context |
| 170 | * \param output RIPEMD-160 checksum result |
| 171 | */ |
| 172 | MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_finish( |
| 173 | mbedtls_ripemd160_context *ctx, |
| 174 | unsigned char output[20] ) |
| 175 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 176 | mbedtls_ripemd160_finish_ret( ctx, output ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** |
| 180 | * \brief RIPEMD-160 process data block (internal use only) |
| 181 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 182 | * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 183 | * |
| 184 | * \param ctx RIPEMD-160 context |
| 185 | * \param data buffer holding one block of data |
| 186 | */ |
| 187 | MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_process( |
| 188 | mbedtls_ripemd160_context *ctx, |
| 189 | const unsigned char data[64] ) |
| 190 | { |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 191 | mbedtls_internal_ripemd160_process( ctx, data ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | #undef MBEDTLS_DEPRECATED |
| 195 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 9f4c162 | 2014-01-22 14:14:26 +0100 | [diff] [blame] | 196 | |
| 197 | #ifdef __cplusplus |
| 198 | } |
| 199 | #endif |
| 200 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 201 | #else /* MBEDTLS_RIPEMD160_ALT */ |
Gilles Peskine | 342d928 | 2018-01-23 18:21:21 +0100 | [diff] [blame^] | 202 | #include "ripemd160_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 203 | #endif /* MBEDTLS_RIPEMD160_ALT */ |
Paul Bakker | 9f4c162 | 2014-01-22 14:14:26 +0100 | [diff] [blame] | 204 | |
| 205 | #ifdef __cplusplus |
| 206 | extern "C" { |
| 207 | #endif |
| 208 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 209 | /** |
| 210 | * \brief Output = RIPEMD-160( input buffer ) |
| 211 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 212 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 213 | * \param ilen length of the input data |
| 214 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 215 | * |
| 216 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 217 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 218 | int mbedtls_ripemd160_ret( const unsigned char *input, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 219 | size_t ilen, |
| 220 | unsigned char output[20] ); |
| 221 | |
| 222 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 223 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 224 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 225 | #else |
| 226 | #define MBEDTLS_DEPRECATED |
| 227 | #endif |
| 228 | /** |
| 229 | * \brief Output = RIPEMD-160( input buffer ) |
| 230 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 231 | * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 232 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 233 | * \param input buffer holding the data |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 234 | * \param ilen length of the input data |
| 235 | * \param output RIPEMD-160 checksum result |
| 236 | */ |
| 237 | MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160( |
| 238 | const unsigned char *input, |
| 239 | size_t ilen, |
| 240 | unsigned char output[20] ) |
| 241 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 242 | mbedtls_ripemd160_ret( input, ilen, output ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | #undef MBEDTLS_DEPRECATED |
| 246 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 247 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 248 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 249 | * \brief Checkup routine |
| 250 | * |
| 251 | * \return 0 if successful, or 1 if the test failed |
| 252 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 253 | int mbedtls_ripemd160_self_test( int verbose ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 254 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 255 | #ifdef __cplusplus |
| 256 | } |
| 257 | #endif |
| 258 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 259 | #endif /* mbedtls_ripemd160.h */ |