blob: 63270d123943f1ab8d4332994289e3393babee3a [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
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * 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.
Paul Bakker61b699e2014-01-22 13:35:29 +010021 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#ifndef MBEDTLS_RIPEMD160_H
23#define MBEDTLS_RIPEMD160_H
Paul Bakker61b699e2014-01-22 13:35:29 +010024
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010026#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010030
Rich Evans00ab4702015-02-06 13:43:58 +000031#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020032#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010033
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020034/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
35 */
Gilles Peskinea3974432021-07-26 18:48:10 +020036/** RIPEMD160 hardware accelerator failed */
37#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +020038
Paul Bakker61b699e2014-01-22 13:35:29 +010039#ifdef __cplusplus
40extern "C" {
41#endif
42
Ron Eldorb2aacec2017-05-18 16:53:08 +030043#if !defined(MBEDTLS_RIPEMD160_ALT)
44// Regular implementation
45//
46
Paul Bakker61b699e2014-01-22 13:35:29 +010047/**
48 * \brief RIPEMD-160 context structure
49 */
Dawid Drozd428cc522018-07-24 10:02:47 +020050typedef struct mbedtls_ripemd160_context
Paul Bakker61b699e2014-01-22 13:35:29 +010051{
52 uint32_t total[2]; /*!< number of bytes processed */
53 uint32_t state[5]; /*!< intermediate digest state */
54 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010055}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010057
Ron Eldorb2aacec2017-05-18 16:53:08 +030058#else /* MBEDTLS_RIPEMD160_ALT */
Jaeden Amero8045cfb2019-07-04 20:26:59 +010059#include "ripemd160_alt.h"
Ron Eldorb2aacec2017-05-18 16:53:08 +030060#endif /* MBEDTLS_RIPEMD160_ALT */
61
Paul Bakker61b699e2014-01-22 13:35:29 +010062/**
Paul Bakker5b4af392014-06-26 12:09:34 +020063 * \brief Initialize RIPEMD-160 context
64 *
65 * \param ctx RIPEMD-160 context to be initialized
66 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020068
69/**
70 * \brief Clear RIPEMD-160 context
71 *
72 * \param ctx RIPEMD-160 context to be cleared
73 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020075
76/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020077 * \brief Clone (the state of) an RIPEMD-160 context
78 *
79 * \param dst The destination context
80 * \param src The context to be cloned
81 */
82void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
83 const mbedtls_ripemd160_context *src );
84
85/**
Paul Bakker61b699e2014-01-22 13:35:29 +010086 * \brief RIPEMD-160 context setup
87 *
88 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010089 *
90 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010091 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010092int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +010093
94/**
95 * \brief RIPEMD-160 process buffer
96 *
97 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010098 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010099 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100100 *
101 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100102 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100103int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100104 const unsigned char *input,
105 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100106
107/**
108 * \brief RIPEMD-160 final digest
109 *
110 * \param ctx RIPEMD-160 context
111 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100112 *
113 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100114 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100115int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100116 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100117
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100118/**
119 * \brief RIPEMD-160 process data block (internal use only)
120 *
121 * \param ctx RIPEMD-160 context
122 * \param data buffer holding one block of data
123 *
124 * \return 0 if successful
125 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100126int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
127 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100128
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200129#if !defined(MBEDTLS_DEPRECATED_REMOVED)
130#if defined(MBEDTLS_DEPRECATED_WARNING)
131#define MBEDTLS_DEPRECATED __attribute__((deprecated))
132#else
133#define MBEDTLS_DEPRECATED
134#endif
135/**
136 * \brief RIPEMD-160 context setup
137 *
138 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
139 *
140 * \param ctx context to be initialized
141 */
142MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
143 mbedtls_ripemd160_context *ctx );
144
145/**
146 * \brief RIPEMD-160 process buffer
147 *
148 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
149 *
150 * \param ctx RIPEMD-160 context
151 * \param input buffer holding the data
152 * \param ilen length of the input data
153 */
154MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
155 mbedtls_ripemd160_context *ctx,
156 const unsigned char *input,
157 size_t ilen );
158
159/**
160 * \brief RIPEMD-160 final digest
161 *
162 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
163 *
164 * \param ctx RIPEMD-160 context
165 * \param output RIPEMD-160 checksum result
166 */
167MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
168 mbedtls_ripemd160_context *ctx,
169 unsigned char output[20] );
170
171/**
172 * \brief RIPEMD-160 process data block (internal use only)
173 *
174 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
175 *
176 * \param ctx RIPEMD-160 context
177 * \param data buffer holding one block of data
178 */
179MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
180 mbedtls_ripemd160_context *ctx,
181 const unsigned char data[64] );
182
183#undef MBEDTLS_DEPRECATED
184#endif /* !MBEDTLS_DEPRECATED_REMOVED */
185
Paul Bakker61b699e2014-01-22 13:35:29 +0100186/**
187 * \brief Output = RIPEMD-160( input buffer )
188 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100189 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100190 * \param ilen length of the input data
191 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100192 *
193 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100194 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100195int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100196 size_t ilen,
197 unsigned char output[20] );
198
Manuel Pégourié-Gonnard93c08472021-04-15 12:23:55 +0200199#if !defined(MBEDTLS_DEPRECATED_REMOVED)
200#if defined(MBEDTLS_DEPRECATED_WARNING)
201#define MBEDTLS_DEPRECATED __attribute__((deprecated))
202#else
203#define MBEDTLS_DEPRECATED
204#endif
205/**
206 * \brief Output = RIPEMD-160( input buffer )
207 *
208 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
209 *
210 * \param input buffer holding the data
211 * \param ilen length of the input data
212 * \param output RIPEMD-160 checksum result
213 */
214MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
215 size_t ilen,
216 unsigned char output[20] );
217
218#undef MBEDTLS_DEPRECATED
219#endif /* !MBEDTLS_DEPRECATED_REMOVED */
220
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500221#if defined(MBEDTLS_SELF_TEST)
222
Paul Bakker61b699e2014-01-22 13:35:29 +0100223/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100224 * \brief Checkup routine
225 *
226 * \return 0 if successful, or 1 if the test failed
227 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100229
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500230#endif /* MBEDTLS_SELF_TEST */
231
Paul Bakker61b699e2014-01-22 13:35:29 +0100232#ifdef __cplusplus
233}
234#endif
235
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#endif /* mbedtls_ripemd160.h */