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