blob: acec3c52dcdc46be5d8b2ff43a42e580e5896bf7 [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
Mateusz Starzyk846f0212021-05-19 19:44:07 +020024#include "mbedtls/private_access.h"
Paul Bakker61b699e2014-01-22 13:35:29 +010025
Bence Szépkútic662b362021-05-27 11:25:03 +020026#include "mbedtls/build_info.h"
Paul Bakker61b699e2014-01-22 13:35:29 +010027
Rich Evans00ab4702015-02-06 13:43:58 +000028#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020029#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010030
Paul Bakker61b699e2014-01-22 13:35:29 +010031#ifdef __cplusplus
32extern "C" {
33#endif
34
Ron Eldorb2aacec2017-05-18 16:53:08 +030035#if !defined(MBEDTLS_RIPEMD160_ALT)
36// Regular implementation
37//
38
Paul Bakker61b699e2014-01-22 13:35:29 +010039/**
40 * \brief RIPEMD-160 context structure
41 */
Gilles Peskine449bd832023-01-11 14:50:10 +010042typedef struct mbedtls_ripemd160_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020043 uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
44 uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< intermediate digest state */
45 unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010046}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010048
Ron Eldorb2aacec2017-05-18 16:53:08 +030049#else /* MBEDTLS_RIPEMD160_ALT */
Jaeden Amero8045cfb2019-07-04 20:26:59 +010050#include "ripemd160_alt.h"
Ron Eldorb2aacec2017-05-18 16:53:08 +030051#endif /* MBEDTLS_RIPEMD160_ALT */
52
Paul Bakker61b699e2014-01-22 13:35:29 +010053/**
Paul Bakker5b4af392014-06-26 12:09:34 +020054 * \brief Initialize RIPEMD-160 context
55 *
56 * \param ctx RIPEMD-160 context to be initialized
57 */
Gilles Peskine449bd832023-01-11 14:50:10 +010058void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020059
60/**
61 * \brief Clear RIPEMD-160 context
62 *
63 * \param ctx RIPEMD-160 context to be cleared
64 */
Gilles Peskine449bd832023-01-11 14:50:10 +010065void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020066
67/**
Tom Cosgrovece7f18c2022-07-28 05:50:56 +010068 * \brief Clone (the state of) a RIPEMD-160 context
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020069 *
70 * \param dst The destination context
71 * \param src The context to be cloned
72 */
Gilles Peskine449bd832023-01-11 14:50:10 +010073void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst,
74 const mbedtls_ripemd160_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020075
76/**
Paul Bakker61b699e2014-01-22 13:35:29 +010077 * \brief RIPEMD-160 context setup
78 *
79 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010080 *
81 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010082 */
Gilles Peskine449bd832023-01-11 14:50:10 +010083int mbedtls_ripemd160_starts(mbedtls_ripemd160_context *ctx);
Paul Bakker61b699e2014-01-22 13:35:29 +010084
85/**
86 * \brief RIPEMD-160 process buffer
87 *
88 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010089 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010090 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010091 *
92 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010093 */
Gilles Peskine449bd832023-01-11 14:50:10 +010094int mbedtls_ripemd160_update(mbedtls_ripemd160_context *ctx,
95 const unsigned char *input,
96 size_t ilen);
Paul Bakker61b699e2014-01-22 13:35:29 +010097
98/**
99 * \brief RIPEMD-160 final digest
100 *
101 * \param ctx RIPEMD-160 context
102 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100103 *
104 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100105 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100106int mbedtls_ripemd160_finish(mbedtls_ripemd160_context *ctx,
107 unsigned char output[20]);
Paul Bakker61b699e2014-01-22 13:35:29 +0100108
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100109/**
110 * \brief RIPEMD-160 process data block (internal use only)
111 *
112 * \param ctx RIPEMD-160 context
113 * \param data buffer holding one block of data
114 *
115 * \return 0 if successful
116 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100117int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx,
118 const unsigned char data[64]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100119
Paul Bakker61b699e2014-01-22 13:35:29 +0100120/**
121 * \brief Output = RIPEMD-160( input buffer )
122 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100123 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100124 * \param ilen length of the input data
125 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100126 *
127 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100128 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100129int mbedtls_ripemd160(const unsigned char *input,
130 size_t ilen,
131 unsigned char output[20]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100132
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500133#if defined(MBEDTLS_SELF_TEST)
134
Paul Bakker61b699e2014-01-22 13:35:29 +0100135/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100136 * \brief Checkup routine
137 *
138 * \return 0 if successful, or 1 if the test failed
139 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100140int mbedtls_ripemd160_self_test(int verbose);
Paul Bakker61b699e2014-01-22 13:35:29 +0100141
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500142#endif /* MBEDTLS_SELF_TEST */
143
Paul Bakker61b699e2014-01-22 13:35:29 +0100144#ifdef __cplusplus
145}
146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#endif /* mbedtls_ripemd160.h */