Antonio de Angelis | 8bb9851 | 2024-01-16 14:13:36 +0000 | [diff] [blame^] | 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 | #include "mbedtls/private_access.h" |
| 13 | |
| 14 | #include "mbedtls/build_info.h" |
| 15 | |
| 16 | #include <stddef.h> |
| 17 | #include <stdint.h> |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | #if !defined(MBEDTLS_RIPEMD160_ALT) |
| 24 | // Regular implementation |
| 25 | // |
| 26 | |
| 27 | /** |
| 28 | * \brief RIPEMD-160 context structure |
| 29 | */ |
| 30 | typedef struct mbedtls_ripemd160_context { |
| 31 | uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */ |
| 32 | uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< intermediate digest state */ |
| 33 | unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */ |
| 34 | } |
| 35 | mbedtls_ripemd160_context; |
| 36 | |
| 37 | #else /* MBEDTLS_RIPEMD160_ALT */ |
| 38 | #include "ripemd160_alt.h" |
| 39 | #endif /* MBEDTLS_RIPEMD160_ALT */ |
| 40 | |
| 41 | /** |
| 42 | * \brief Initialize RIPEMD-160 context |
| 43 | * |
| 44 | * \param ctx RIPEMD-160 context to be initialized |
| 45 | */ |
| 46 | void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx); |
| 47 | |
| 48 | /** |
| 49 | * \brief Clear RIPEMD-160 context |
| 50 | * |
| 51 | * \param ctx RIPEMD-160 context to be cleared |
| 52 | */ |
| 53 | void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx); |
| 54 | |
| 55 | /** |
| 56 | * \brief Clone (the state of) a RIPEMD-160 context |
| 57 | * |
| 58 | * \param dst The destination context |
| 59 | * \param src The context to be cloned |
| 60 | */ |
| 61 | void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst, |
| 62 | const mbedtls_ripemd160_context *src); |
| 63 | |
| 64 | /** |
| 65 | * \brief RIPEMD-160 context setup |
| 66 | * |
| 67 | * \param ctx context to be initialized |
| 68 | * |
| 69 | * \return 0 if successful |
| 70 | */ |
| 71 | int mbedtls_ripemd160_starts(mbedtls_ripemd160_context *ctx); |
| 72 | |
| 73 | /** |
| 74 | * \brief RIPEMD-160 process buffer |
| 75 | * |
| 76 | * \param ctx RIPEMD-160 context |
| 77 | * \param input buffer holding the data |
| 78 | * \param ilen length of the input data |
| 79 | * |
| 80 | * \return 0 if successful |
| 81 | */ |
| 82 | int mbedtls_ripemd160_update(mbedtls_ripemd160_context *ctx, |
| 83 | const unsigned char *input, |
| 84 | size_t ilen); |
| 85 | |
| 86 | /** |
| 87 | * \brief RIPEMD-160 final digest |
| 88 | * |
| 89 | * \param ctx RIPEMD-160 context |
| 90 | * \param output RIPEMD-160 checksum result |
| 91 | * |
| 92 | * \return 0 if successful |
| 93 | */ |
| 94 | int mbedtls_ripemd160_finish(mbedtls_ripemd160_context *ctx, |
| 95 | unsigned char output[20]); |
| 96 | |
| 97 | /** |
| 98 | * \brief RIPEMD-160 process data block (internal use only) |
| 99 | * |
| 100 | * \param ctx RIPEMD-160 context |
| 101 | * \param data buffer holding one block of data |
| 102 | * |
| 103 | * \return 0 if successful |
| 104 | */ |
| 105 | int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx, |
| 106 | const unsigned char data[64]); |
| 107 | |
| 108 | /** |
| 109 | * \brief Output = RIPEMD-160( input buffer ) |
| 110 | * |
| 111 | * \param input buffer holding the data |
| 112 | * \param ilen length of the input data |
| 113 | * \param output RIPEMD-160 checksum result |
| 114 | * |
| 115 | * \return 0 if successful |
| 116 | */ |
| 117 | int mbedtls_ripemd160(const unsigned char *input, |
| 118 | size_t ilen, |
| 119 | unsigned char output[20]); |
| 120 | |
| 121 | #if defined(MBEDTLS_SELF_TEST) |
| 122 | |
| 123 | /** |
| 124 | * \brief Checkup routine |
| 125 | * |
| 126 | * \return 0 if successful, or 1 if the test failed |
| 127 | */ |
| 128 | int mbedtls_ripemd160_self_test(int verbose); |
| 129 | |
| 130 | #endif /* MBEDTLS_SELF_TEST */ |
| 131 | |
| 132 | #ifdef __cplusplus |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | #endif /* mbedtls_ripemd160.h */ |