blob: 38318a2b880d4c0e55026a8c57aa5b16236a4099 [file] [log] [blame]
Paul Bakker61b699e2014-01-22 13:35:29 +01001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file ripemd160.h
Paul Bakker61b699e2014-01-22 13:35:29 +01003 *
4 * \brief RIPE MD-160 message digest
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker61b699e2014-01-22 13:35:29 +01009 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#ifndef MBEDTLS_RIPEMD160_H
11#define MBEDTLS_RIPEMD160_H
Paul Bakker61b699e2014-01-22 13:35:29 +010012
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020013#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010014#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020015#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020016#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020017#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010018
Rich Evans00ab4702015-02-06 13:43:58 +000019#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020020#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010021
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020022/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
23 */
Gilles Peskinea3974432021-07-26 18:48:10 +020024/** RIPEMD160 hardware accelerator failed */
25#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020026
Paul Bakker61b699e2014-01-22 13:35:29 +010027#ifdef __cplusplus
28extern "C" {
29#endif
30
Ron Eldorb2aacec2017-05-18 16:53:08 +030031#if !defined(MBEDTLS_RIPEMD160_ALT)
32// Regular implementation
33//
34
Paul Bakker61b699e2014-01-22 13:35:29 +010035/**
36 * \brief RIPEMD-160 context structure
37 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010038typedef struct mbedtls_ripemd160_context {
Paul Bakker61b699e2014-01-22 13:35:29 +010039 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 */
Paul Bakker61b699e2014-01-22 13:35:29 +010042}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010044
Ron Eldorb2aacec2017-05-18 16:53:08 +030045#else /* MBEDTLS_RIPEMD160_ALT */
Jaeden Amero8045cfb2019-07-04 20:26:59 +010046#include "ripemd160_alt.h"
Ron Eldorb2aacec2017-05-18 16:53:08 +030047#endif /* MBEDTLS_RIPEMD160_ALT */
48
Paul Bakker61b699e2014-01-22 13:35:29 +010049/**
Paul Bakker5b4af392014-06-26 12:09:34 +020050 * \brief Initialize RIPEMD-160 context
51 *
52 * \param ctx RIPEMD-160 context to be initialized
53 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010054void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020055
56/**
57 * \brief Clear RIPEMD-160 context
58 *
59 * \param ctx RIPEMD-160 context to be cleared
60 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010061void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020062
63/**
Tom Cosgrove5205c972022-07-28 06:12:08 +010064 * \brief Clone (the state of) a RIPEMD-160 context
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020065 *
66 * \param dst The destination context
67 * \param src The context to be cloned
68 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010069void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst,
70 const mbedtls_ripemd160_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020071
72/**
Paul Bakker61b699e2014-01-22 13:35:29 +010073 * \brief RIPEMD-160 context setup
74 *
75 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010076 *
77 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010078 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010079int mbedtls_ripemd160_starts_ret(mbedtls_ripemd160_context *ctx);
Paul Bakker61b699e2014-01-22 13:35:29 +010080
81/**
82 * \brief RIPEMD-160 process buffer
83 *
84 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010085 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010086 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010087 *
88 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010089 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010090int mbedtls_ripemd160_update_ret(mbedtls_ripemd160_context *ctx,
91 const unsigned char *input,
92 size_t ilen);
Paul Bakker61b699e2014-01-22 13:35:29 +010093
94/**
95 * \brief RIPEMD-160 final digest
96 *
97 * \param ctx RIPEMD-160 context
98 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010099 *
100 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100101 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100102int mbedtls_ripemd160_finish_ret(mbedtls_ripemd160_context *ctx,
103 unsigned char output[20]);
Paul Bakker61b699e2014-01-22 13:35:29 +0100104
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100105/**
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 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100113int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx,
114 const unsigned char data[64]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100115
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200116#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 */
129MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100130 mbedtls_ripemd160_context *ctx);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200131
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 */
141MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100142 mbedtls_ripemd160_context *ctx,
143 const unsigned char *input,
144 size_t ilen);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200145
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 */
154MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100155 mbedtls_ripemd160_context *ctx,
156 unsigned char output[20]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200157
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 */
166MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100167 mbedtls_ripemd160_context *ctx,
168 const unsigned char data[64]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200169
170#undef MBEDTLS_DEPRECATED
171#endif /* !MBEDTLS_DEPRECATED_REMOVED */
172
Paul Bakker61b699e2014-01-22 13:35:29 +0100173/**
174 * \brief Output = RIPEMD-160( input buffer )
175 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100176 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100177 * \param ilen length of the input data
178 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100179 *
180 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100181 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100182int mbedtls_ripemd160_ret(const unsigned char *input,
183 size_t ilen,
184 unsigned char output[20]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100185
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200186#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 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100201MBEDTLS_DEPRECATED void mbedtls_ripemd160(const unsigned char *input,
202 size_t ilen,
203 unsigned char output[20]);
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200204
205#undef MBEDTLS_DEPRECATED
206#endif /* !MBEDTLS_DEPRECATED_REMOVED */
207
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500208#if defined(MBEDTLS_SELF_TEST)
209
Paul Bakker61b699e2014-01-22 13:35:29 +0100210/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100211 * \brief Checkup routine
212 *
213 * \return 0 if successful, or 1 if the test failed
214 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100215int mbedtls_ripemd160_self_test(int verbose);
Paul Bakker61b699e2014-01-22 13:35:29 +0100216
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500217#endif /* MBEDTLS_SELF_TEST */
218
Paul Bakker61b699e2014-01-22 13:35:29 +0100219#ifdef __cplusplus
220}
221#endif
222
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223#endif /* mbedtls_ripemd160.h */