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