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