blob: 4a83ec4260f74bd28ba744848ee4d8fdee1d701e [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)
Jaeden Amero203fdf72019-07-04 20:01:14 +010028#include "mbedtls/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
Jaeden Amero59ebddf2019-07-10 11:03:03 +010033#include "mbedtls/platform_util.h"
34
Rich Evans00ab4702015-02-06 13:43:58 +000035#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020036#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010037
Ron Eldor9924bdc2018-10-04 10:59:13 +030038/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
39 */
Gilles Peskinea381fe82018-01-23 18:16:11 +010040#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
41
Paul Bakker61b699e2014-01-22 13:35:29 +010042#ifdef __cplusplus
43extern "C" {
44#endif
45
Ron Eldorb2aacec2017-05-18 16:53:08 +030046#if !defined(MBEDTLS_RIPEMD160_ALT)
47// Regular implementation
48//
49
Paul Bakker61b699e2014-01-22 13:35:29 +010050/**
51 * \brief RIPEMD-160 context structure
52 */
Dawid Drozd428cc522018-07-24 10:02:47 +020053typedef struct mbedtls_ripemd160_context
Paul Bakker61b699e2014-01-22 13:35:29 +010054{
55 uint32_t total[2]; /*!< number of bytes processed */
56 uint32_t state[5]; /*!< intermediate digest state */
57 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010058}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010060
Ron Eldorb2aacec2017-05-18 16:53:08 +030061#else /* MBEDTLS_RIPEMD160_ALT */
Jaeden Amero697c68c2019-07-04 20:26:59 +010062#include "ripemd160_alt.h"
Ron Eldorb2aacec2017-05-18 16:53:08 +030063#endif /* MBEDTLS_RIPEMD160_ALT */
64
Paul Bakker61b699e2014-01-22 13:35:29 +010065/**
Paul Bakker5b4af392014-06-26 12:09:34 +020066 * \brief Initialize RIPEMD-160 context
67 *
68 * \param ctx RIPEMD-160 context to be initialized
69 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020071
72/**
73 * \brief Clear RIPEMD-160 context
74 *
75 * \param ctx RIPEMD-160 context to be cleared
76 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020078
79/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020080 * \brief Clone (the state of) an RIPEMD-160 context
81 *
82 * \param dst The destination context
83 * \param src The context to be cloned
84 */
85void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
86 const mbedtls_ripemd160_context *src );
87
88/**
Paul Bakker61b699e2014-01-22 13:35:29 +010089 * \brief RIPEMD-160 context setup
90 *
91 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010092 *
93 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010094 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010095int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +010096
97/**
98 * \brief RIPEMD-160 process buffer
99 *
100 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100101 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100102 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100103 *
104 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100105 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100106int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100107 const unsigned char *input,
108 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100109
110/**
111 * \brief RIPEMD-160 final digest
112 *
113 * \param ctx RIPEMD-160 context
114 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100115 *
116 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100117 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100118int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100119 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100120
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100121/**
122 * \brief RIPEMD-160 process data block (internal use only)
123 *
124 * \param ctx RIPEMD-160 context
125 * \param data buffer holding one block of data
126 *
127 * \return 0 if successful
128 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100129int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
130 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100131
132#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100133/**
134 * \brief RIPEMD-160 context setup
135 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100136 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100137 *
138 * \param ctx context to be initialized
139 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000140MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
141 mbedtls_ripemd160_context *ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100142
143/**
144 * \brief RIPEMD-160 process buffer
145 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100146 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100147 *
148 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100149 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100150 * \param ilen length of the input data
151 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000152MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100153 mbedtls_ripemd160_context *ctx,
154 const unsigned char *input,
Jaeden Amero041039f2018-02-19 15:28:08 +0000155 size_t ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100156
157/**
158 * \brief RIPEMD-160 final digest
159 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100160 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100161 *
162 * \param ctx RIPEMD-160 context
163 * \param output RIPEMD-160 checksum result
164 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000165MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100166 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000167 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100168
169/**
170 * \brief RIPEMD-160 process data block (internal use only)
171 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100172 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100173 *
174 * \param ctx RIPEMD-160 context
175 * \param data buffer holding one block of data
176 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000177MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100178 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000179 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100180#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100181
Paul Bakker61b699e2014-01-22 13:35:29 +0100182/**
183 * \brief Output = RIPEMD-160( input buffer )
184 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100185 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100186 * \param ilen length of the input data
187 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100188 *
189 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100190 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100191int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100192 size_t ilen,
193 unsigned char output[20] );
194
195#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100196/**
197 * \brief Output = RIPEMD-160( input buffer )
198 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100199 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100200 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100201 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100202 * \param ilen length of the input data
203 * \param output RIPEMD-160 checksum result
204 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000205MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
206 size_t ilen,
207 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100208#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100209
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500210#if defined(MBEDTLS_SELF_TEST)
211
Paul Bakker61b699e2014-01-22 13:35:29 +0100212/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100213 * \brief Checkup routine
214 *
215 * \return 0 if successful, or 1 if the test failed
216 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100218
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500219#endif /* MBEDTLS_SELF_TEST */
220
Paul Bakker61b699e2014-01-22 13:35:29 +0100221#ifdef __cplusplus
222}
223#endif
224
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225#endif /* mbedtls_ripemd160.h */