Jaeden Amero | e54e693 | 2018-08-06 16:19:58 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file ripemd160.h |
| 3 | * |
| 4 | * \brief RIPE MD-160 message digest |
| 5 | */ |
| 6 | /* |
| 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
| 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 | * This file is part of Mbed Crypto (https://tls.mbed.org) |
| 23 | */ |
| 24 | #ifndef MBEDCRYPTO_RIPEMD160_H |
| 25 | #define MBEDCRYPTO_RIPEMD160_H |
| 26 | |
| 27 | #if !defined(MBEDCRYPTO_CONFIG_FILE) |
| 28 | #include "config.h" |
| 29 | #else |
| 30 | #include MBEDCRYPTO_CONFIG_FILE |
| 31 | #endif |
| 32 | |
| 33 | #include <stddef.h> |
| 34 | #include <stdint.h> |
| 35 | |
| 36 | #define MBEDCRYPTO_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */ |
| 37 | |
| 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
| 42 | #if !defined(MBEDCRYPTO_RIPEMD160_ALT) |
| 43 | // Regular implementation |
| 44 | // |
| 45 | |
| 46 | /** |
| 47 | * \brief RIPEMD-160 context structure |
| 48 | */ |
| 49 | typedef struct |
| 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 | mbedcrypto_ripemd160_context; |
| 56 | |
| 57 | #else /* MBEDCRYPTO_RIPEMD160_ALT */ |
| 58 | #include "ripemd160.h" |
| 59 | #endif /* MBEDCRYPTO_RIPEMD160_ALT */ |
| 60 | |
| 61 | /** |
| 62 | * \brief Initialize RIPEMD-160 context |
| 63 | * |
| 64 | * \param ctx RIPEMD-160 context to be initialized |
| 65 | */ |
| 66 | void mbedcrypto_ripemd160_init( mbedcrypto_ripemd160_context *ctx ); |
| 67 | |
| 68 | /** |
| 69 | * \brief Clear RIPEMD-160 context |
| 70 | * |
| 71 | * \param ctx RIPEMD-160 context to be cleared |
| 72 | */ |
| 73 | void mbedcrypto_ripemd160_free( mbedcrypto_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 mbedcrypto_ripemd160_clone( mbedcrypto_ripemd160_context *dst, |
| 82 | const mbedcrypto_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 mbedcrypto_ripemd160_starts_ret( mbedcrypto_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 mbedcrypto_ripemd160_update_ret( mbedcrypto_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 mbedcrypto_ripemd160_finish_ret( mbedcrypto_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 mbedcrypto_internal_ripemd160_process( mbedcrypto_ripemd160_context *ctx, |
| 126 | const unsigned char data[64] ); |
| 127 | |
| 128 | #if !defined(MBEDCRYPTO_DEPRECATED_REMOVED) |
| 129 | #if defined(MBEDCRYPTO_DEPRECATED_WARNING) |
| 130 | #define MBEDCRYPTO_DEPRECATED __attribute__((deprecated)) |
| 131 | #else |
| 132 | #define MBEDCRYPTO_DEPRECATED |
| 133 | #endif |
| 134 | /** |
| 135 | * \brief RIPEMD-160 context setup |
| 136 | * |
| 137 | * \deprecated Superseded by mbedcrypto_ripemd160_starts_ret() in 2.7.0 |
| 138 | * |
| 139 | * \param ctx context to be initialized |
| 140 | */ |
| 141 | MBEDCRYPTO_DEPRECATED void mbedcrypto_ripemd160_starts( |
| 142 | mbedcrypto_ripemd160_context *ctx ); |
| 143 | |
| 144 | /** |
| 145 | * \brief RIPEMD-160 process buffer |
| 146 | * |
| 147 | * \deprecated Superseded by mbedcrypto_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 | MBEDCRYPTO_DEPRECATED void mbedcrypto_ripemd160_update( |
| 154 | mbedcrypto_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 mbedcrypto_ripemd160_finish_ret() in 2.7.0 |
| 162 | * |
| 163 | * \param ctx RIPEMD-160 context |
| 164 | * \param output RIPEMD-160 checksum result |
| 165 | */ |
| 166 | MBEDCRYPTO_DEPRECATED void mbedcrypto_ripemd160_finish( |
| 167 | mbedcrypto_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 mbedcrypto_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 | MBEDCRYPTO_DEPRECATED void mbedcrypto_ripemd160_process( |
| 179 | mbedcrypto_ripemd160_context *ctx, |
| 180 | const unsigned char data[64] ); |
| 181 | |
| 182 | #undef MBEDCRYPTO_DEPRECATED |
| 183 | #endif /* !MBEDCRYPTO_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 mbedcrypto_ripemd160_ret( const unsigned char *input, |
| 195 | size_t ilen, |
| 196 | unsigned char output[20] ); |
| 197 | |
| 198 | #if !defined(MBEDCRYPTO_DEPRECATED_REMOVED) |
| 199 | #if defined(MBEDCRYPTO_DEPRECATED_WARNING) |
| 200 | #define MBEDCRYPTO_DEPRECATED __attribute__((deprecated)) |
| 201 | #else |
| 202 | #define MBEDCRYPTO_DEPRECATED |
| 203 | #endif |
| 204 | /** |
| 205 | * \brief Output = RIPEMD-160( input buffer ) |
| 206 | * |
| 207 | * \deprecated Superseded by mbedcrypto_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 | MBEDCRYPTO_DEPRECATED void mbedcrypto_ripemd160( const unsigned char *input, |
| 214 | size_t ilen, |
| 215 | unsigned char output[20] ); |
| 216 | |
| 217 | #undef MBEDCRYPTO_DEPRECATED |
| 218 | #endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */ |
| 219 | |
| 220 | /** |
| 221 | * \brief Checkup routine |
| 222 | * |
| 223 | * \return 0 if successful, or 1 if the test failed |
| 224 | */ |
| 225 | int mbedcrypto_ripemd160_self_test( int verbose ); |
| 226 | |
| 227 | #ifdef __cplusplus |
| 228 | } |
| 229 | #endif |
| 230 | |
| 231 | #endif /* mbedcrypto_ripemd160.h */ |