blob: 442b49cdd45acdcf8408c4efad4ff01d052e93a7 [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
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é-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker61b699e2014-01-22 13:35:29 +010023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_RIPEMD160_H
25#define MBEDTLS_RIPEMD160_H
Paul Bakker61b699e2014-01-22 13:35:29 +010026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020034#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010035
Gilles Peskinea381fe82018-01-23 18:16:11 +010036#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
37
Paul Bakker61b699e2014-01-22 13:35:29 +010038#ifdef __cplusplus
39extern "C" {
40#endif
41
Ron Eldorb2aacec2017-05-18 16:53:08 +030042#if !defined(MBEDTLS_RIPEMD160_ALT)
43// Regular implementation
44//
45
Paul Bakker61b699e2014-01-22 13:35:29 +010046/**
47 * \brief RIPEMD-160 context structure
48 */
49typedef struct
50{
51 uint32_t total[2]; /*!< number of bytes processed */
52 uint32_t state[5]; /*!< intermediate digest state */
53 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010054}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010056
Ron Eldorb2aacec2017-05-18 16:53:08 +030057#else /* MBEDTLS_RIPEMD160_ALT */
58#include "ripemd160.h"
59#endif /* MBEDTLS_RIPEMD160_ALT */
60
Paul Bakker61b699e2014-01-22 13:35:29 +010061/**
Paul Bakker5b4af392014-06-26 12:09:34 +020062 * \brief Initialize RIPEMD-160 context
63 *
64 * \param ctx RIPEMD-160 context to be initialized
65 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020067
68/**
69 * \brief Clear RIPEMD-160 context
70 *
71 * \param ctx RIPEMD-160 context to be cleared
72 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020074
75/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020076 * \brief Clone (the state of) an RIPEMD-160 context
77 *
78 * \param dst The destination context
79 * \param src The context to be cloned
80 */
81void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
82 const mbedtls_ripemd160_context *src );
83
84/**
Paul Bakker61b699e2014-01-22 13:35:29 +010085 * \brief RIPEMD-160 context setup
86 *
87 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010088 *
89 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010090 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010091int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +010092
93/**
94 * \brief RIPEMD-160 process buffer
95 *
96 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010097 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010098 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010099 *
100 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100101 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100102int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100103 const unsigned char *input,
104 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100105
106/**
107 * \brief RIPEMD-160 final digest
108 *
109 * \param ctx RIPEMD-160 context
110 * \param output RIPEMD-160 checksum result
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_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100115 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100116
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100117/**
118 * \brief RIPEMD-160 process data block (internal use only)
119 *
120 * \param ctx RIPEMD-160 context
121 * \param data buffer holding one block of data
122 *
123 * \return 0 if successful
124 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100125int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
126 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100127
128#if !defined(MBEDTLS_DEPRECATED_REMOVED)
129#if defined(MBEDTLS_DEPRECATED_WARNING)
130#define MBEDTLS_DEPRECATED __attribute__((deprecated))
131#else
132#define MBEDTLS_DEPRECATED
133#endif
134/**
135 * \brief RIPEMD-160 context setup
136 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100137 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100138 *
139 * \param ctx context to be initialized
140 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000141MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
142 mbedtls_ripemd160_context *ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100143
144/**
145 * \brief RIPEMD-160 process buffer
146 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100147 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100148 *
149 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100150 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100151 * \param ilen length of the input data
152 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000153MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100154 mbedtls_ripemd160_context *ctx,
155 const unsigned char *input,
Jaeden Amero041039f2018-02-19 15:28:08 +0000156 size_t ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100157
158/**
159 * \brief RIPEMD-160 final digest
160 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100161 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100162 *
163 * \param ctx RIPEMD-160 context
164 * \param output RIPEMD-160 checksum result
165 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000166MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100167 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000168 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100169
170/**
171 * \brief RIPEMD-160 process data block (internal use only)
172 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100173 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100174 *
175 * \param ctx RIPEMD-160 context
176 * \param data buffer holding one block of data
177 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000178MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100179 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000180 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100181
182#undef MBEDTLS_DEPRECATED
183#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100184
Paul Bakker61b699e2014-01-22 13:35:29 +0100185/**
186 * \brief Output = RIPEMD-160( input buffer )
187 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100188 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100189 * \param ilen length of the input data
190 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100191 *
192 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100193 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100194int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100195 size_t ilen,
196 unsigned char output[20] );
197
198#if !defined(MBEDTLS_DEPRECATED_REMOVED)
199#if defined(MBEDTLS_DEPRECATED_WARNING)
200#define MBEDTLS_DEPRECATED __attribute__((deprecated))
201#else
202#define MBEDTLS_DEPRECATED
203#endif
204/**
205 * \brief Output = RIPEMD-160( input buffer )
206 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100207 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100208 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100209 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100210 * \param ilen length of the input data
211 * \param output RIPEMD-160 checksum result
212 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000213MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
214 size_t ilen,
215 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100216
217#undef MBEDTLS_DEPRECATED
218#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100219
Ron Eldorfa8f6352017-06-20 15:48:46 +0300220#if defined(MBEDTLS_SELF_TEST)
221
Paul Bakker61b699e2014-01-22 13:35:29 +0100222/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100223 * \brief Checkup routine
224 *
225 * \return 0 if successful, or 1 if the test failed
226 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100228
Ron Eldorfa8f6352017-06-20 15:48:46 +0300229#endif /* MBEDTLS_SELF_TEST */
230
Paul Bakker61b699e2014-01-22 13:35:29 +0100231#ifdef __cplusplus
232}
233#endif
234
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#endif /* mbedtls_ripemd160.h */