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