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 |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 44bfbe3 | 2020-08-19 16:54:51 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 9 | * |
| 10 | * This file is provided under the Apache License 2.0, or the |
| 11 | * GNU General Public License v2.0 or later. |
| 12 | * |
| 13 | * ********** |
| 14 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 15 | * |
| 16 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 17 | * not use this file except in compliance with the License. |
| 18 | * You may obtain a copy of the License at |
| 19 | * |
| 20 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | * |
| 22 | * Unless required by applicable law or agreed to in writing, software |
| 23 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | * See the License for the specific language governing permissions and |
| 26 | * limitations under the License. |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 27 | * |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 28 | * ********** |
| 29 | * |
| 30 | * ********** |
| 31 | * GNU General Public License v2.0 or later: |
| 32 | * |
| 33 | * This program is free software; you can redistribute it and/or modify |
| 34 | * it under the terms of the GNU General Public License as published by |
| 35 | * the Free Software Foundation; either version 2 of the License, or |
| 36 | * (at your option) any later version. |
| 37 | * |
| 38 | * This program is distributed in the hope that it will be useful, |
| 39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 41 | * GNU General Public License for more details. |
| 42 | * |
| 43 | * You should have received a copy of the GNU General Public License along |
| 44 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 45 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 46 | * |
| 47 | * ********** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 48 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | #ifndef MBEDTLS_RIPEMD160_H |
| 50 | #define MBEDTLS_RIPEMD160_H |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 51 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 53 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 54 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 56 | #endif |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 57 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 58 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 59 | #include <stdint.h> |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 60 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 61 | #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */ |
| 62 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | #if !defined(MBEDTLS_RIPEMD160_ALT) |
Paul Bakker | 9f4c162 | 2014-01-22 14:14:26 +0100 | [diff] [blame] | 64 | // Regular implementation |
| 65 | // |
| 66 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 67 | #ifdef __cplusplus |
| 68 | extern "C" { |
| 69 | #endif |
| 70 | |
| 71 | /** |
| 72 | * \brief RIPEMD-160 context structure |
| 73 | */ |
| 74 | typedef struct |
| 75 | { |
| 76 | uint32_t total[2]; /*!< number of bytes processed */ |
| 77 | uint32_t state[5]; /*!< intermediate digest state */ |
| 78 | unsigned char buffer[64]; /*!< data block being processed */ |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 79 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | mbedtls_ripemd160_context; |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 81 | |
| 82 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 83 | * \brief Initialize RIPEMD-160 context |
| 84 | * |
| 85 | * \param ctx RIPEMD-160 context to be initialized |
| 86 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 87 | void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * \brief Clear RIPEMD-160 context |
| 91 | * |
| 92 | * \param ctx RIPEMD-160 context to be cleared |
| 93 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 94 | void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 95 | |
| 96 | /** |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 97 | * \brief Clone (the state of) an RIPEMD-160 context |
| 98 | * |
| 99 | * \param dst The destination context |
| 100 | * \param src The context to be cloned |
| 101 | */ |
| 102 | void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, |
| 103 | const mbedtls_ripemd160_context *src ); |
| 104 | |
| 105 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 106 | * \brief RIPEMD-160 context setup |
| 107 | * |
| 108 | * \param ctx context to be initialized |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 109 | * |
| 110 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 111 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 112 | int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * \brief RIPEMD-160 process buffer |
| 116 | * |
| 117 | * \param ctx RIPEMD-160 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 118 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 119 | * \param ilen length of the input data |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 120 | * |
| 121 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 122 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 123 | int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 124 | const unsigned char *input, |
| 125 | size_t ilen ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * \brief RIPEMD-160 final digest |
| 129 | * |
| 130 | * \param ctx RIPEMD-160 context |
| 131 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 132 | * |
| 133 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 134 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 135 | int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 136 | unsigned char output[20] ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 137 | |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 138 | /** |
| 139 | * \brief RIPEMD-160 process data block (internal use only) |
| 140 | * |
| 141 | * \param ctx RIPEMD-160 context |
| 142 | * \param data buffer holding one block of data |
| 143 | * |
| 144 | * \return 0 if successful |
| 145 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 146 | int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx, |
| 147 | const unsigned char data[64] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 148 | |
| 149 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 150 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 151 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 152 | #else |
| 153 | #define MBEDTLS_DEPRECATED |
| 154 | #endif |
| 155 | /** |
| 156 | * \brief RIPEMD-160 context setup |
| 157 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 158 | * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 159 | * |
| 160 | * \param ctx context to be initialized |
| 161 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 162 | MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts( |
| 163 | mbedtls_ripemd160_context *ctx ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * \brief RIPEMD-160 process buffer |
| 167 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 168 | * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 169 | * |
| 170 | * \param ctx RIPEMD-160 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 171 | * \param input buffer holding the data |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 172 | * \param ilen length of the input data |
| 173 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 174 | MBEDTLS_DEPRECATED void mbedtls_ripemd160_update( |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 175 | mbedtls_ripemd160_context *ctx, |
| 176 | const unsigned char *input, |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 177 | size_t ilen ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * \brief RIPEMD-160 final digest |
| 181 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 182 | * \deprecated Superseded by mbedtls_ripemd160_finish_ret() 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 output RIPEMD-160 checksum result |
| 186 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 187 | MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish( |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 188 | mbedtls_ripemd160_context *ctx, |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 189 | unsigned char output[20] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * \brief RIPEMD-160 process data block (internal use only) |
| 193 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 194 | * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 195 | * |
| 196 | * \param ctx RIPEMD-160 context |
| 197 | * \param data buffer holding one block of data |
| 198 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 199 | MBEDTLS_DEPRECATED void mbedtls_ripemd160_process( |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 200 | mbedtls_ripemd160_context *ctx, |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 201 | const unsigned char data[64] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 202 | |
| 203 | #undef MBEDTLS_DEPRECATED |
| 204 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 9f4c162 | 2014-01-22 14:14:26 +0100 | [diff] [blame] | 205 | |
| 206 | #ifdef __cplusplus |
| 207 | } |
| 208 | #endif |
| 209 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 210 | #else /* MBEDTLS_RIPEMD160_ALT */ |
Gilles Peskine | 342d928 | 2018-01-23 18:21:21 +0100 | [diff] [blame] | 211 | #include "ripemd160_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 212 | #endif /* MBEDTLS_RIPEMD160_ALT */ |
Paul Bakker | 9f4c162 | 2014-01-22 14:14:26 +0100 | [diff] [blame] | 213 | |
| 214 | #ifdef __cplusplus |
| 215 | extern "C" { |
| 216 | #endif |
| 217 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 218 | /** |
| 219 | * \brief Output = RIPEMD-160( input buffer ) |
| 220 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 221 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 222 | * \param ilen length of the input data |
| 223 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 224 | * |
| 225 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 226 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 227 | int mbedtls_ripemd160_ret( const unsigned char *input, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 228 | size_t ilen, |
| 229 | unsigned char output[20] ); |
| 230 | |
| 231 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 232 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 233 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 234 | #else |
| 235 | #define MBEDTLS_DEPRECATED |
| 236 | #endif |
| 237 | /** |
| 238 | * \brief Output = RIPEMD-160( input buffer ) |
| 239 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 240 | * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0 |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 241 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 242 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 243 | * \param ilen length of the input data |
| 244 | * \param output RIPEMD-160 checksum result |
| 245 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 246 | MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input, |
| 247 | size_t ilen, |
| 248 | unsigned char output[20] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 249 | |
| 250 | #undef MBEDTLS_DEPRECATED |
| 251 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 252 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 253 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 254 | * \brief Checkup routine |
| 255 | * |
| 256 | * \return 0 if successful, or 1 if the test failed |
| 257 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 258 | int mbedtls_ripemd160_self_test( int verbose ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 259 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 260 | #ifdef __cplusplus |
| 261 | } |
| 262 | #endif |
| 263 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 264 | #endif /* mbedtls_ripemd160.h */ |