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 |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 24 | #include "mbedtls/private_access.h" |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 25 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 26 | #include "mbedtls/build_info.h" |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 27 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 28 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 29 | #include <stdint.h> |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 30 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 35 | #if !defined(MBEDTLS_RIPEMD160_ALT) |
| 36 | // Regular implementation |
| 37 | // |
| 38 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 39 | /** |
| 40 | * \brief RIPEMD-160 context structure |
| 41 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 42 | typedef struct mbedtls_ripemd160_context |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 43 | { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 44 | uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */ |
| 45 | uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< intermediate digest state */ |
| 46 | unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */ |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 47 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 48 | mbedtls_ripemd160_context; |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 49 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 50 | #else /* MBEDTLS_RIPEMD160_ALT */ |
Jaeden Amero | 8045cfb | 2019-07-04 20:26:59 +0100 | [diff] [blame] | 51 | #include "ripemd160_alt.h" |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 52 | #endif /* MBEDTLS_RIPEMD160_ALT */ |
| 53 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 54 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 55 | * \brief Initialize RIPEMD-160 context |
| 56 | * |
| 57 | * \param ctx RIPEMD-160 context to be initialized |
| 58 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 59 | void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * \brief Clear RIPEMD-160 context |
| 63 | * |
| 64 | * \param ctx RIPEMD-160 context to be cleared |
| 65 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 67 | |
| 68 | /** |
Tom Cosgrove | ce7f18c | 2022-07-28 05:50:56 +0100 | [diff] [blame^] | 69 | * \brief Clone (the state of) a RIPEMD-160 context |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 70 | * |
| 71 | * \param dst The destination context |
| 72 | * \param src The context to be cloned |
| 73 | */ |
| 74 | void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, |
| 75 | const mbedtls_ripemd160_context *src ); |
| 76 | |
| 77 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 78 | * \brief RIPEMD-160 context setup |
| 79 | * |
| 80 | * \param ctx context to be initialized |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 81 | * |
| 82 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 83 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 84 | int mbedtls_ripemd160_starts( mbedtls_ripemd160_context *ctx ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * \brief RIPEMD-160 process buffer |
| 88 | * |
| 89 | * \param ctx RIPEMD-160 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 90 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 91 | * \param ilen length of the input data |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 92 | * |
| 93 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 94 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 95 | int mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx, |
| 96 | const unsigned char *input, |
| 97 | size_t ilen ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * \brief RIPEMD-160 final digest |
| 101 | * |
| 102 | * \param ctx RIPEMD-160 context |
| 103 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 104 | * |
| 105 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 106 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 107 | int mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx, |
| 108 | unsigned char output[20] ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 109 | |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 110 | /** |
| 111 | * \brief RIPEMD-160 process data block (internal use only) |
| 112 | * |
| 113 | * \param ctx RIPEMD-160 context |
| 114 | * \param data buffer holding one block of data |
| 115 | * |
| 116 | * \return 0 if successful |
| 117 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 118 | int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx, |
| 119 | const unsigned char data[64] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 120 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 121 | /** |
| 122 | * \brief Output = RIPEMD-160( input buffer ) |
| 123 | * |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 124 | * \param input buffer holding the data |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 125 | * \param ilen length of the input data |
| 126 | * \param output RIPEMD-160 checksum result |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 127 | * |
| 128 | * \return 0 if successful |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 129 | */ |
TRodziewicz | 26371e4 | 2021-06-08 16:45:41 +0200 | [diff] [blame] | 130 | int mbedtls_ripemd160( const unsigned char *input, |
| 131 | size_t ilen, |
| 132 | unsigned char output[20] ); |
Andres Amaya Garcia | b1a8bf9 | 2017-05-02 10:59:46 +0100 | [diff] [blame] | 133 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 134 | #if defined(MBEDTLS_SELF_TEST) |
| 135 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 136 | /** |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 137 | * \brief Checkup routine |
| 138 | * |
| 139 | * \return 0 if successful, or 1 if the test failed |
| 140 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 141 | int mbedtls_ripemd160_self_test( int verbose ); |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 142 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 143 | #endif /* MBEDTLS_SELF_TEST */ |
| 144 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 145 | #ifdef __cplusplus |
| 146 | } |
| 147 | #endif |
| 148 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 149 | #endif /* mbedtls_ripemd160.h */ |