blob: 415c8975302e96519d6b13320c259260b8cbddc7 [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útia2947ac2020-08-19 16:37:36 +02007 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakker61b699e2014-01-22 13:35:29 +010027 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
Paul Bakker61b699e2014-01-22 13:35:29 +010048 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#ifndef MBEDTLS_RIPEMD160_H
50#define MBEDTLS_RIPEMD160_H
Paul Bakker61b699e2014-01-22 13:35:29 +010051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010053#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020054#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010057
Rich Evans00ab4702015-02-06 13:43:58 +000058#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020059#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010060
Ron Eldor9924bdc2018-10-04 10:59:13 +030061/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
62 */
Gilles Peskine1990fab2021-07-26 18:48:10 +020063/** RIPEMD160 hardware accelerator failed */
64#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031
Gilles Peskinea381fe82018-01-23 18:16:11 +010065
Paul Bakker61b699e2014-01-22 13:35:29 +010066#ifdef __cplusplus
67extern "C" {
68#endif
69
Ron Eldorb2aacec2017-05-18 16:53:08 +030070#if !defined(MBEDTLS_RIPEMD160_ALT)
71// Regular implementation
72//
73
Paul Bakker61b699e2014-01-22 13:35:29 +010074/**
75 * \brief RIPEMD-160 context structure
76 */
Dawid Drozd428cc522018-07-24 10:02:47 +020077typedef struct mbedtls_ripemd160_context
Paul Bakker61b699e2014-01-22 13:35:29 +010078{
79 uint32_t total[2]; /*!< number of bytes processed */
80 uint32_t state[5]; /*!< intermediate digest state */
81 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010082}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010084
Ron Eldorb2aacec2017-05-18 16:53:08 +030085#else /* MBEDTLS_RIPEMD160_ALT */
86#include "ripemd160.h"
87#endif /* MBEDTLS_RIPEMD160_ALT */
88
Paul Bakker61b699e2014-01-22 13:35:29 +010089/**
Paul Bakker5b4af392014-06-26 12:09:34 +020090 * \brief Initialize RIPEMD-160 context
91 *
92 * \param ctx RIPEMD-160 context to be initialized
93 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020095
96/**
97 * \brief Clear RIPEMD-160 context
98 *
99 * \param ctx RIPEMD-160 context to be cleared
100 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +0200102
103/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200104 * \brief Clone (the state of) an RIPEMD-160 context
105 *
106 * \param dst The destination context
107 * \param src The context to be cloned
108 */
109void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
110 const mbedtls_ripemd160_context *src );
111
112/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100113 * \brief RIPEMD-160 context setup
114 *
115 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100116 *
117 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100118 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100119int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +0100120
121/**
122 * \brief RIPEMD-160 process buffer
123 *
124 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100125 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100126 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100127 *
128 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100129 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100130int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100131 const unsigned char *input,
132 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100133
134/**
135 * \brief RIPEMD-160 final digest
136 *
137 * \param ctx RIPEMD-160 context
138 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100139 *
140 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100141 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100142int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100143 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100144
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100145/**
146 * \brief RIPEMD-160 process data block (internal use only)
147 *
148 * \param ctx RIPEMD-160 context
149 * \param data buffer holding one block of data
150 *
151 * \return 0 if successful
152 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100153int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
154 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100155
156#if !defined(MBEDTLS_DEPRECATED_REMOVED)
157#if defined(MBEDTLS_DEPRECATED_WARNING)
158#define MBEDTLS_DEPRECATED __attribute__((deprecated))
159#else
160#define MBEDTLS_DEPRECATED
161#endif
162/**
163 * \brief RIPEMD-160 context setup
164 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100165 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100166 *
167 * \param ctx context to be initialized
168 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000169MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
170 mbedtls_ripemd160_context *ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100171
172/**
173 * \brief RIPEMD-160 process buffer
174 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100175 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100176 *
177 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100178 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100179 * \param ilen length of the input data
180 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000181MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100182 mbedtls_ripemd160_context *ctx,
183 const unsigned char *input,
Jaeden Amero041039f2018-02-19 15:28:08 +0000184 size_t ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100185
186/**
187 * \brief RIPEMD-160 final digest
188 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100189 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100190 *
191 * \param ctx RIPEMD-160 context
192 * \param output RIPEMD-160 checksum result
193 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000194MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100195 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000196 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100197
198/**
199 * \brief RIPEMD-160 process data block (internal use only)
200 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100201 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100202 *
203 * \param ctx RIPEMD-160 context
204 * \param data buffer holding one block of data
205 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000206MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100207 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000208 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100209
210#undef MBEDTLS_DEPRECATED
211#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100212
Paul Bakker61b699e2014-01-22 13:35:29 +0100213/**
214 * \brief Output = RIPEMD-160( input buffer )
215 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100216 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100217 * \param ilen length of the input data
218 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100219 *
220 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100221 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100222int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100223 size_t ilen,
224 unsigned char output[20] );
225
226#if !defined(MBEDTLS_DEPRECATED_REMOVED)
227#if defined(MBEDTLS_DEPRECATED_WARNING)
228#define MBEDTLS_DEPRECATED __attribute__((deprecated))
229#else
230#define MBEDTLS_DEPRECATED
231#endif
232/**
233 * \brief Output = RIPEMD-160( input buffer )
234 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100235 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100236 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100237 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100238 * \param ilen length of the input data
239 * \param output RIPEMD-160 checksum result
240 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000241MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
242 size_t ilen,
243 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100244
245#undef MBEDTLS_DEPRECATED
246#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100247
Ron Eldorfa8f6352017-06-20 15:48:46 +0300248#if defined(MBEDTLS_SELF_TEST)
249
Paul Bakker61b699e2014-01-22 13:35:29 +0100250/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100251 * \brief Checkup routine
252 *
253 * \return 0 if successful, or 1 if the test failed
254 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100256
Ron Eldorfa8f6352017-06-20 15:48:46 +0300257#endif /* MBEDTLS_SELF_TEST */
258
Paul Bakker61b699e2014-01-22 13:35:29 +0100259#ifdef __cplusplus
260}
261#endif
262
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263#endif /* mbedtls_ripemd160.h */