1 /** 2 * \file ripemd160.h 3 * 4 * \brief RIPE MD-160 message digest 5 */ 6 /* 7 * Copyright The Mbed TLS Contributors 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. 21 */ 22 #ifndef MBEDTLS_RIPEMD160_H 23 #define MBEDTLS_RIPEMD160_H 24 25 #if !defined(MBEDTLS_CONFIG_FILE) 26 #include "mbedtls/config.h" 27 #else 28 #include MBEDTLS_CONFIG_FILE 29 #endif 30 31 #include <stddef.h> 32 #include <stdint.h> 33 34 /* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used. 35 */ 36 #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */ 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #if !defined(MBEDTLS_RIPEMD160_ALT) 43 // Regular implementation 44 // 45 46 /** 47 * \brief RIPEMD-160 context structure 48 */ 49 typedef struct mbedtls_ripemd160_context 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 */ 54 } 55 mbedtls_ripemd160_context; 56 57 #else /* MBEDTLS_RIPEMD160_ALT */ 58 #include "ripemd160_alt.h" 59 #endif /* MBEDTLS_RIPEMD160_ALT */ 60 61 /** 62 * \brief Initialize RIPEMD-160 context 63 * 64 * \param ctx RIPEMD-160 context to be initialized 65 */ 66 void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx ); 67 68 /** 69 * \brief Clear RIPEMD-160 context 70 * 71 * \param ctx RIPEMD-160 context to be cleared 72 */ 73 void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx ); 74 75 /** 76 * \brief Clone (the state of) an RIPEMD-160 context 77 * 78 * \param dst The destination context 79 * \param src The context to be cloned 80 */ 81 void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst, 82 const mbedtls_ripemd160_context *src ); 83 84 /** 85 * \brief RIPEMD-160 context setup 86 * 87 * \param ctx context to be initialized 88 * 89 * \return 0 if successful 90 */ 91 int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx ); 92 93 /** 94 * \brief RIPEMD-160 process buffer 95 * 96 * \param ctx RIPEMD-160 context 97 * \param input buffer holding the data 98 * \param ilen length of the input data 99 * 100 * \return 0 if successful 101 */ 102 int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx, 103 const unsigned char *input, 104 size_t ilen ); 105 106 /** 107 * \brief RIPEMD-160 final digest 108 * 109 * \param ctx RIPEMD-160 context 110 * \param output RIPEMD-160 checksum result 111 * 112 * \return 0 if successful 113 */ 114 int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx, 115 unsigned char output[20] ); 116 117 /** 118 * \brief RIPEMD-160 process data block (internal use only) 119 * 120 * \param ctx RIPEMD-160 context 121 * \param data buffer holding one block of data 122 * 123 * \return 0 if successful 124 */ 125 int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx, 126 const unsigned char data[64] ); 127 128 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 129 #if defined(MBEDTLS_DEPRECATED_WARNING) 130 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 131 #else 132 #define MBEDTLS_DEPRECATED 133 #endif 134 /** 135 * \brief RIPEMD-160 context setup 136 * 137 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0 138 * 139 * \param ctx context to be initialized 140 */ 141 MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts( 142 mbedtls_ripemd160_context *ctx ); 143 144 /** 145 * \brief RIPEMD-160 process buffer 146 * 147 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0 148 * 149 * \param ctx RIPEMD-160 context 150 * \param input buffer holding the data 151 * \param ilen length of the input data 152 */ 153 MBEDTLS_DEPRECATED void mbedtls_ripemd160_update( 154 mbedtls_ripemd160_context *ctx, 155 const unsigned char *input, 156 size_t ilen ); 157 158 /** 159 * \brief RIPEMD-160 final digest 160 * 161 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0 162 * 163 * \param ctx RIPEMD-160 context 164 * \param output RIPEMD-160 checksum result 165 */ 166 MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish( 167 mbedtls_ripemd160_context *ctx, 168 unsigned char output[20] ); 169 170 /** 171 * \brief RIPEMD-160 process data block (internal use only) 172 * 173 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0 174 * 175 * \param ctx RIPEMD-160 context 176 * \param data buffer holding one block of data 177 */ 178 MBEDTLS_DEPRECATED void mbedtls_ripemd160_process( 179 mbedtls_ripemd160_context *ctx, 180 const unsigned char data[64] ); 181 182 #undef MBEDTLS_DEPRECATED 183 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 184 185 /** 186 * \brief Output = RIPEMD-160( input buffer ) 187 * 188 * \param input buffer holding the data 189 * \param ilen length of the input data 190 * \param output RIPEMD-160 checksum result 191 * 192 * \return 0 if successful 193 */ 194 int mbedtls_ripemd160_ret( const unsigned char *input, 195 size_t ilen, 196 unsigned char output[20] ); 197 198 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 199 #if defined(MBEDTLS_DEPRECATED_WARNING) 200 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 201 #else 202 #define MBEDTLS_DEPRECATED 203 #endif 204 /** 205 * \brief Output = RIPEMD-160( input buffer ) 206 * 207 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0 208 * 209 * \param input buffer holding the data 210 * \param ilen length of the input data 211 * \param output RIPEMD-160 checksum result 212 */ 213 MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input, 214 size_t ilen, 215 unsigned char output[20] ); 216 217 #undef MBEDTLS_DEPRECATED 218 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 219 220 #if defined(MBEDTLS_SELF_TEST) 221 222 /** 223 * \brief Checkup routine 224 * 225 * \return 0 if successful, or 1 if the test failed 226 */ 227 int mbedtls_ripemd160_self_test( int verbose ); 228 229 #endif /* MBEDTLS_SELF_TEST */ 230 231 #ifdef __cplusplus 232 } 233 #endif 234 235 #endif /* mbedtls_ripemd160.h */ 236