blob: 6a8cf295c39d83f9856a6f5ebc5c9b0aed45ab58 [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-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úti4e9f7122020-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 * **********
48 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000049 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker61b699e2014-01-22 13:35:29 +010050 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#ifndef MBEDTLS_RIPEMD160_H
52#define MBEDTLS_RIPEMD160_H
Paul Bakker61b699e2014-01-22 13:35:29 +010053
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010055#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020058#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010059
Rich Evans00ab4702015-02-06 13:43:58 +000060#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020061#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010062
Gilles Peskinea381fe82018-01-23 18:16:11 +010063#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if !defined(MBEDTLS_RIPEMD160_ALT)
Paul Bakker9f4c1622014-01-22 14:14:26 +010066// Regular implementation
67//
68
Paul Bakker61b699e2014-01-22 13:35:29 +010069#ifdef __cplusplus
70extern "C" {
71#endif
72
73/**
74 * \brief RIPEMD-160 context structure
75 */
76typedef struct
77{
78 uint32_t total[2]; /*!< number of bytes processed */
79 uint32_t state[5]; /*!< intermediate digest state */
80 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010081}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010083
84/**
Paul Bakker5b4af392014-06-26 12:09:34 +020085 * \brief Initialize RIPEMD-160 context
86 *
87 * \param ctx RIPEMD-160 context to be initialized
88 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020090
91/**
92 * \brief Clear RIPEMD-160 context
93 *
94 * \param ctx RIPEMD-160 context to be cleared
95 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020097
98/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020099 * \brief Clone (the state of) an RIPEMD-160 context
100 *
101 * \param dst The destination context
102 * \param src The context to be cloned
103 */
104void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
105 const mbedtls_ripemd160_context *src );
106
107/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100108 * \brief RIPEMD-160 context setup
109 *
110 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100111 *
112 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100113 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100114int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +0100115
116/**
117 * \brief RIPEMD-160 process buffer
118 *
119 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100120 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100121 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100122 *
123 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100124 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100125int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100126 const unsigned char *input,
127 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100128
129/**
130 * \brief RIPEMD-160 final digest
131 *
132 * \param ctx RIPEMD-160 context
133 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100134 *
135 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100136 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100137int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100138 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100139
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100140/**
141 * \brief RIPEMD-160 process data block (internal use only)
142 *
143 * \param ctx RIPEMD-160 context
144 * \param data buffer holding one block of data
145 *
146 * \return 0 if successful
147 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100148int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
149 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100150
151#if !defined(MBEDTLS_DEPRECATED_REMOVED)
152#if defined(MBEDTLS_DEPRECATED_WARNING)
153#define MBEDTLS_DEPRECATED __attribute__((deprecated))
154#else
155#define MBEDTLS_DEPRECATED
156#endif
157/**
158 * \brief RIPEMD-160 context setup
159 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100160 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100161 *
162 * \param ctx context to be initialized
163 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000164MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
165 mbedtls_ripemd160_context *ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100166
167/**
168 * \brief RIPEMD-160 process buffer
169 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100170 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100171 *
172 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100173 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100174 * \param ilen length of the input data
175 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000176MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100177 mbedtls_ripemd160_context *ctx,
178 const unsigned char *input,
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000179 size_t ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100180
181/**
182 * \brief RIPEMD-160 final digest
183 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100184 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100185 *
186 * \param ctx RIPEMD-160 context
187 * \param output RIPEMD-160 checksum result
188 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000189MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100190 mbedtls_ripemd160_context *ctx,
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000191 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100192
193/**
194 * \brief RIPEMD-160 process data block (internal use only)
195 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100196 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100197 *
198 * \param ctx RIPEMD-160 context
199 * \param data buffer holding one block of data
200 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000201MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100202 mbedtls_ripemd160_context *ctx,
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000203 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100204
205#undef MBEDTLS_DEPRECATED
206#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100207
208#ifdef __cplusplus
209}
210#endif
211
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212#else /* MBEDTLS_RIPEMD160_ALT */
Gilles Peskine342d9282018-01-23 18:21:21 +0100213#include "ripemd160_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214#endif /* MBEDTLS_RIPEMD160_ALT */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100215
216#ifdef __cplusplus
217extern "C" {
218#endif
219
Paul Bakker61b699e2014-01-22 13:35:29 +0100220/**
221 * \brief Output = RIPEMD-160( input buffer )
222 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100223 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100224 * \param ilen length of the input data
225 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100226 *
227 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100228 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100229int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100230 size_t ilen,
231 unsigned char output[20] );
232
233#if !defined(MBEDTLS_DEPRECATED_REMOVED)
234#if defined(MBEDTLS_DEPRECATED_WARNING)
235#define MBEDTLS_DEPRECATED __attribute__((deprecated))
236#else
237#define MBEDTLS_DEPRECATED
238#endif
239/**
240 * \brief Output = RIPEMD-160( input buffer )
241 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100242 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100243 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100244 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100245 * \param ilen length of the input data
246 * \param output RIPEMD-160 checksum result
247 */
Jaeden Ameroa53ff8d2018-02-19 15:28:08 +0000248MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
249 size_t ilen,
250 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100251
252#undef MBEDTLS_DEPRECATED
253#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100254
Paul Bakker61b699e2014-01-22 13:35:29 +0100255/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100256 * \brief Checkup routine
257 *
258 * \return 0 if successful, or 1 if the test failed
259 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100261
Paul Bakker61b699e2014-01-22 13:35:29 +0100262#ifdef __cplusplus
263}
264#endif
265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266#endif /* mbedtls_ripemd160.h */