blob: a21a98c04ef28030a0518c25d9a9949a32edfacd [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
Paul Bakker61b699e2014-01-22 13:35:29 +010034#ifdef __cplusplus
35extern "C" {
36#endif
37
Ron Eldorb2aacec2017-05-18 16:53:08 +030038#if !defined(MBEDTLS_RIPEMD160_ALT)
39// Regular implementation
40//
41
Paul Bakker61b699e2014-01-22 13:35:29 +010042/**
43 * \brief RIPEMD-160 context structure
44 */
Dawid Drozd428cc522018-07-24 10:02:47 +020045typedef struct mbedtls_ripemd160_context
Paul Bakker61b699e2014-01-22 13:35:29 +010046{
47 uint32_t total[2]; /*!< number of bytes processed */
48 uint32_t state[5]; /*!< intermediate digest state */
49 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010050}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010052
Ron Eldorb2aacec2017-05-18 16:53:08 +030053#else /* MBEDTLS_RIPEMD160_ALT */
Jaeden Amero8045cfb2019-07-04 20:26:59 +010054#include "ripemd160_alt.h"
Ron Eldorb2aacec2017-05-18 16:53:08 +030055#endif /* MBEDTLS_RIPEMD160_ALT */
56
Paul Bakker61b699e2014-01-22 13:35:29 +010057/**
Paul Bakker5b4af392014-06-26 12:09:34 +020058 * \brief Initialize RIPEMD-160 context
59 *
60 * \param ctx RIPEMD-160 context to be initialized
61 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020063
64/**
65 * \brief Clear RIPEMD-160 context
66 *
67 * \param ctx RIPEMD-160 context to be cleared
68 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020070
71/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020072 * \brief Clone (the state of) an RIPEMD-160 context
73 *
74 * \param dst The destination context
75 * \param src The context to be cloned
76 */
77void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
78 const mbedtls_ripemd160_context *src );
79
80/**
Paul Bakker61b699e2014-01-22 13:35:29 +010081 * \brief RIPEMD-160 context setup
82 *
83 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010084 *
85 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010086 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010087int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +010088
89/**
90 * \brief RIPEMD-160 process buffer
91 *
92 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010093 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010094 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010095 *
96 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010097 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010098int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010099 const unsigned char *input,
100 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100101
102/**
103 * \brief RIPEMD-160 final digest
104 *
105 * \param ctx RIPEMD-160 context
106 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100107 *
108 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100109 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100110int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100111 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100112
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100113/**
114 * \brief RIPEMD-160 process data block (internal use only)
115 *
116 * \param ctx RIPEMD-160 context
117 * \param data buffer holding one block of data
118 *
119 * \return 0 if successful
120 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100121int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
122 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100123
124#if !defined(MBEDTLS_DEPRECATED_REMOVED)
125#if defined(MBEDTLS_DEPRECATED_WARNING)
126#define MBEDTLS_DEPRECATED __attribute__((deprecated))
127#else
128#define MBEDTLS_DEPRECATED
129#endif
130/**
131 * \brief RIPEMD-160 context setup
132 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100133 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100134 *
135 * \param ctx context to be initialized
136 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000137MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
138 mbedtls_ripemd160_context *ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100139
140/**
141 * \brief RIPEMD-160 process buffer
142 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100143 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100144 *
145 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100146 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100147 * \param ilen length of the input data
148 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000149MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100150 mbedtls_ripemd160_context *ctx,
151 const unsigned char *input,
Jaeden Amero041039f2018-02-19 15:28:08 +0000152 size_t ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100153
154/**
155 * \brief RIPEMD-160 final digest
156 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100157 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100158 *
159 * \param ctx RIPEMD-160 context
160 * \param output RIPEMD-160 checksum result
161 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000162MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100163 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000164 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100165
166/**
167 * \brief RIPEMD-160 process data block (internal use only)
168 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100169 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100170 *
171 * \param ctx RIPEMD-160 context
172 * \param data buffer holding one block of data
173 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000174MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100175 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000176 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100177
178#undef MBEDTLS_DEPRECATED
179#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100180
Paul Bakker61b699e2014-01-22 13:35:29 +0100181/**
182 * \brief Output = RIPEMD-160( input buffer )
183 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100184 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100185 * \param ilen length of the input data
186 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100187 *
188 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100189 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100190int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100191 size_t ilen,
192 unsigned char output[20] );
193
194#if !defined(MBEDTLS_DEPRECATED_REMOVED)
195#if defined(MBEDTLS_DEPRECATED_WARNING)
196#define MBEDTLS_DEPRECATED __attribute__((deprecated))
197#else
198#define MBEDTLS_DEPRECATED
199#endif
200/**
201 * \brief Output = RIPEMD-160( input buffer )
202 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100203 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100204 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100205 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100206 * \param ilen length of the input data
207 * \param output RIPEMD-160 checksum result
208 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000209MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
210 size_t ilen,
211 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100212
213#undef MBEDTLS_DEPRECATED
214#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100215
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500216#if defined(MBEDTLS_SELF_TEST)
217
Paul Bakker61b699e2014-01-22 13:35:29 +0100218/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100219 * \brief Checkup routine
220 *
221 * \return 0 if successful, or 1 if the test failed
222 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100224
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500225#endif /* MBEDTLS_SELF_TEST */
226
Paul Bakker61b699e2014-01-22 13:35:29 +0100227#ifdef __cplusplus
228}
229#endif
230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231#endif /* mbedtls_ripemd160.h */