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 | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
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 | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #ifndef MBEDTLS_RIPEMD160_H |
| 23 | #define MBEDTLS_RIPEMD160_H |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 24 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 26 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #endif |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 30 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 31 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 32 | #include <stdint.h> |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 33 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 38 | #if !defined(MBEDTLS_RIPEMD160_ALT) |
| 39 | // Regular implementation |
| 40 | // |
| 41 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 42 | /** |
| 43 | * \brief RIPEMD-160 context structure |
| 44 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 45 | typedef struct mbedtls_ripemd160_context |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 46 | { |
| 47 | uint32_t total[2]; /*!< number of bytes processed */ |
| 48 | uint32_t state[5]; /*!< intermediate digest state */ |
| 49 | unsigned char buffer[64]; /*!< data block being processed */ |
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 | mbedtls_ripemd160_context; |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 52 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 53 | #else /* MBEDTLS_RIPEMD160_ALT */ |
Jaeden Amero | 8045cfb | 2019-07-04 20:26:59 +0100 | [diff] [blame] | 54 | #include "ripemd160_alt.h" |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 55 | #endif /* MBEDTLS_RIPEMD160_ALT */ |
| 56 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 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 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 124 | /** |
| 125 | * \brief Output = RIPEMD-160( input buffer ) |
| 126 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 127 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 128 | * \param ilen length of the input data |
| 129 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 130 | * |
| 131 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 132 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 133 | int mbedtls_ripemd160_ret( const unsigned char *input, |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 134 | size_t ilen, |
| 135 | unsigned char output[20] ); |
| 136 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 137 | #if defined(MBEDTLS_SELF_TEST) |
| 138 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 139 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 140 | * \brief Checkup routine |
| 141 | * |
| 142 | * \return 0 if successful, or 1 if the test failed |
| 143 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 144 | int mbedtls_ripemd160_self_test( int verbose ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 145 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 146 | #endif /* MBEDTLS_SELF_TEST */ |
| 147 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 148 | #ifdef __cplusplus |
| 149 | } |
| 150 | #endif |
| 151 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 152 | #endif /* mbedtls_ripemd160.h */ |