blob: b42f6d2a9597ede9ec13bc67d93ee2b6ae1a1bbb [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
Ron Eldor9924bdc2018-10-04 10:59:13 +030036/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
37 */
Gilles Peskinea381fe82018-01-23 18:16:11 +010038#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
39
Paul Bakker61b699e2014-01-22 13:35:29 +010040#ifdef __cplusplus
41extern "C" {
42#endif
43
Ron Eldorb2aacec2017-05-18 16:53:08 +030044#if !defined(MBEDTLS_RIPEMD160_ALT)
45// Regular implementation
46//
47
Paul Bakker61b699e2014-01-22 13:35:29 +010048/**
49 * \brief RIPEMD-160 context structure
50 */
Dawid Drozd428cc522018-07-24 10:02:47 +020051typedef struct mbedtls_ripemd160_context
Paul Bakker61b699e2014-01-22 13:35:29 +010052{
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
Ron Eldorb2aacec2017-05-18 16:53:08 +030059#else /* MBEDTLS_RIPEMD160_ALT */
60#include "ripemd160.h"
61#endif /* MBEDTLS_RIPEMD160_ALT */
62
Paul Bakker61b699e2014-01-22 13:35:29 +010063/**
Paul Bakker5b4af392014-06-26 12:09:34 +020064 * \brief Initialize RIPEMD-160 context
65 *
66 * \param ctx RIPEMD-160 context to be initialized
67 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020069
70/**
71 * \brief Clear RIPEMD-160 context
72 *
73 * \param ctx RIPEMD-160 context to be cleared
74 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020076
77/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020078 * \brief Clone (the state of) an RIPEMD-160 context
79 *
80 * \param dst The destination context
81 * \param src The context to be cloned
82 */
83void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
84 const mbedtls_ripemd160_context *src );
85
86/**
Paul Bakker61b699e2014-01-22 13:35:29 +010087 * \brief RIPEMD-160 context setup
88 *
89 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010090 *
91 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010092 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010093int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
Paul Bakker61b699e2014-01-22 13:35:29 +010094
95/**
96 * \brief RIPEMD-160 process buffer
97 *
98 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010099 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100100 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100101 *
102 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100103 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100104int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100105 const unsigned char *input,
106 size_t ilen );
Paul Bakker61b699e2014-01-22 13:35:29 +0100107
108/**
109 * \brief RIPEMD-160 final digest
110 *
111 * \param ctx RIPEMD-160 context
112 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100113 *
114 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100115 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100116int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100117 unsigned char output[20] );
Paul Bakker61b699e2014-01-22 13:35:29 +0100118
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100119/**
120 * \brief RIPEMD-160 process data block (internal use only)
121 *
122 * \param ctx RIPEMD-160 context
123 * \param data buffer holding one block of data
124 *
125 * \return 0 if successful
126 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100127int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
128 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100129
130#if !defined(MBEDTLS_DEPRECATED_REMOVED)
131#if defined(MBEDTLS_DEPRECATED_WARNING)
132#define MBEDTLS_DEPRECATED __attribute__((deprecated))
133#else
134#define MBEDTLS_DEPRECATED
135#endif
136/**
137 * \brief RIPEMD-160 context setup
138 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100139 * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100140 *
141 * \param ctx context to be initialized
142 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000143MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
144 mbedtls_ripemd160_context *ctx );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100145
146/**
147 * \brief RIPEMD-160 process buffer
148 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100149 * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100150 *
151 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100152 * \param input buffer holding the data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100153 * \param ilen length of the input data
154 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000155MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100156 mbedtls_ripemd160_context *ctx,
157 const unsigned char *input,
Jaeden Amero041039f2018-02-19 15:28:08 +0000158 size_t ilen );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100159
160/**
161 * \brief RIPEMD-160 final digest
162 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100163 * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100164 *
165 * \param ctx RIPEMD-160 context
166 * \param output RIPEMD-160 checksum result
167 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000168MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100169 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000170 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100171
172/**
173 * \brief RIPEMD-160 process data block (internal use only)
174 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100175 * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100176 *
177 * \param ctx RIPEMD-160 context
178 * \param data buffer holding one block of data
179 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000180MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100181 mbedtls_ripemd160_context *ctx,
Jaeden Amero041039f2018-02-19 15:28:08 +0000182 const unsigned char data[64] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100183
184#undef MBEDTLS_DEPRECATED
185#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker9f4c1622014-01-22 14:14:26 +0100186
Paul Bakker61b699e2014-01-22 13:35:29 +0100187/**
188 * \brief Output = RIPEMD-160( input buffer )
189 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100190 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100191 * \param ilen length of the input data
192 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100193 *
194 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100195 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100196int mbedtls_ripemd160_ret( const unsigned char *input,
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100197 size_t ilen,
198 unsigned char output[20] );
199
200#if !defined(MBEDTLS_DEPRECATED_REMOVED)
201#if defined(MBEDTLS_DEPRECATED_WARNING)
202#define MBEDTLS_DEPRECATED __attribute__((deprecated))
203#else
204#define MBEDTLS_DEPRECATED
205#endif
206/**
207 * \brief Output = RIPEMD-160( input buffer )
208 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100209 * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100210 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100211 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100212 * \param ilen length of the input data
213 * \param output RIPEMD-160 checksum result
214 */
Jaeden Amero041039f2018-02-19 15:28:08 +0000215MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
216 size_t ilen,
217 unsigned char output[20] );
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100218
219#undef MBEDTLS_DEPRECATED
220#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker61b699e2014-01-22 13:35:29 +0100221
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500222#if defined(MBEDTLS_SELF_TEST)
223
Paul Bakker61b699e2014-01-22 13:35:29 +0100224/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100225 * \brief Checkup routine
226 *
227 * \return 0 if successful, or 1 if the test failed
228 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229int mbedtls_ripemd160_self_test( int verbose );
Paul Bakker61b699e2014-01-22 13:35:29 +0100230
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500231#endif /* MBEDTLS_SELF_TEST */
232
Paul Bakker61b699e2014-01-22 13:35:29 +0100233#ifdef __cplusplus
234}
235#endif
236
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200237#endif /* mbedtls_ripemd160.h */