blob: ad548d302e57079d6bf1f38523c7063805aee313 [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
5 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Paul Bakker61b699e2014-01-22 13:35:29 +010020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker61b699e2014-01-22 13:35:29 +010022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_RIPEMD160_H
24#define MBEDTLS_RIPEMD160_H
Paul Bakker61b699e2014-01-22 13:35:29 +010025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010027#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010031
Rich Evans00ab4702015-02-06 13:43:58 +000032#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020033#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010034
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010035#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
36 !defined(inline) && !defined(__cplusplus)
37#define inline __inline
38#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if !defined(MBEDTLS_RIPEMD160_ALT)
Paul Bakker9f4c1622014-01-22 14:14:26 +010041// Regular implementation
42//
43
Paul Bakker61b699e2014-01-22 13:35:29 +010044#ifdef __cplusplus
45extern "C" {
46#endif
47
48/**
49 * \brief RIPEMD-160 context structure
50 */
51typedef struct
52{
53 uint32_t total[2]; /*!< number of bytes processed */
54 uint32_t state[5]; /*!< intermediate digest state */
55 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010056}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010058
59/**
Paul Bakker5b4af392014-06-26 12:09:34 +020060 * \brief Initialize RIPEMD-160 context
61 *
62 * \param ctx RIPEMD-160 context to be initialized
63 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020065
66/**
67 * \brief Clear RIPEMD-160 context
68 *
69 * \param ctx RIPEMD-160 context to be cleared
70 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020072
73/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020074 * \brief Clone (the state of) an RIPEMD-160 context
75 *
76 * \param dst The destination context
77 * \param src The context to be cloned
78 */
79void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
80 const mbedtls_ripemd160_context *src );
81
82/**
Paul Bakker61b699e2014-01-22 13:35:29 +010083 * \brief RIPEMD-160 context setup
84 *
85 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010086 *
87 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010088 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010089int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +010090
91/**
92 * \brief RIPEMD-160 process buffer
93 *
94 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010095 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010096 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010097 *
98 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010099 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100100int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100101 const unsigned char *input,
102 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100103
104/**
105 * \brief RIPEMD-160 final digest
106 *
107 * \param ctx RIPEMD-160 context
108 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100109 *
110 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100111 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100112int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100113 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100114
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100115/**
116 * \brief RIPEMD-160 process data block (internal use only)
117 *
118 * \param ctx RIPEMD-160 context
119 * \param data buffer holding one block of data
120 *
121 * \return 0 if successful
122 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100123int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
124 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100125
126#if !defined(MBEDTLS_DEPRECATED_REMOVED)
127#if defined(MBEDTLS_DEPRECATED_WARNING)
128#define MBEDTLS_DEPRECATED __attribute__((deprecated))
129#else
130#define MBEDTLS_DEPRECATED
131#endif
132/**
133 * \brief RIPEMD-160 context setup
134 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100135 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100136 *
137 * \param ctx context to be initialized
138 */
139MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_starts(
140 mbedtls_ripemd160_context *ctx )
141{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100142 mbedtls_ripemd160_starts_ret( ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100143}
144
145/**
146 * \brief RIPEMD-160 process buffer
147 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100148 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100149 *
150 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100151 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100152 * \param ilen length of the input data
153 */
154MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_update(
155 mbedtls_ripemd160_context *ctx,
156 const unsigned char *input,
157 size_t ilen )
158{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100159 mbedtls_ripemd160_update_ret( ctx, input, ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100160}
161
162/**
163 * \brief RIPEMD-160 final digest
164 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100165 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100166 *
167 * \param ctx RIPEMD-160 context
168 * \param output RIPEMD-160 checksum result
169 */
170MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_finish(
171 mbedtls_ripemd160_context *ctx,
172 unsigned char output[20] )
173{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100174 mbedtls_ripemd160_finish_ret( ctx, output );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100175}
176
177/**
178 * \brief RIPEMD-160 process data block (internal use only)
179 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100180 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100181 *
182 * \param ctx RIPEMD-160 context
183 * \param data buffer holding one block of data
184 */
185MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_process(
186 mbedtls_ripemd160_context *ctx,
187 const unsigned char data[64] )
188{
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100189 mbedtls_internal_ripemd160_process( ctx, data );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100190}
191
192#undef MBEDTLS_DEPRECATED
193#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100194
195#ifdef __cplusplus
196}
197#endif
198
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199#else /* MBEDTLS_RIPEMD160_ALT */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100200#include "ripemd160.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201#endif /* MBEDTLS_RIPEMD160_ALT */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100202
203#ifdef __cplusplus
204extern "C" {
205#endif
206
Paul Bakker61b699e2014-01-22 13:35:29 +0100207/**
208 * \brief Output = RIPEMD-160( input buffer )
209 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100210 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100211 * \param ilen length of the input data
212 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100213 *
214 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100215 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100216int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100217 size_t ilen,
218 unsigned char output[20] );
219
220#if !defined(MBEDTLS_DEPRECATED_REMOVED)
221#if defined(MBEDTLS_DEPRECATED_WARNING)
222#define MBEDTLS_DEPRECATED __attribute__((deprecated))
223#else
224#define MBEDTLS_DEPRECATED
225#endif
226/**
227 * \brief Output = RIPEMD-160( input buffer )
228 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100229 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100230 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100231 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100232 * \param ilen length of the input data
233 * \param output RIPEMD-160 checksum result
234 */
235MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160(
236 const unsigned char *input,
237 size_t ilen,
238 unsigned char output[20] )
239{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100240 mbedtls_ripemd160_ret( input, ilen, output );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100241}
242
243#undef MBEDTLS_DEPRECATED
244#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100245
Paul Bakker61b699e2014-01-22 13:35:29 +0100246/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100247 * \brief Checkup routine
248 *
249 * \return 0 if successful, or 1 if the test failed
250 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100252
Paul Bakker61b699e2014-01-22 13:35:29 +0100253#ifdef __cplusplus
254}
255#endif
256
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257#endif /* mbedtls_ripemd160.h */