blob: 570ab2e441d8a8e13f04298257282b1ec83b6a4e [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
Dave Rodgman16799db2023-11-02 19:47:20 +00008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker61b699e2014-01-22 13:35:29 +01009 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#ifndef MBEDTLS_RIPEMD160_H
11#define MBEDTLS_RIPEMD160_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020012#include "mbedtls/private_access.h"
Paul Bakker61b699e2014-01-22 13:35:29 +010013
Bence Szépkútic662b362021-05-27 11:25:03 +020014#include "mbedtls/build_info.h"
Paul Bakker61b699e2014-01-22 13:35:29 +010015
Rich Evans00ab4702015-02-06 13:43:58 +000016#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020017#include <stdint.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010018
Paul Bakker61b699e2014-01-22 13:35:29 +010019#ifdef __cplusplus
20extern "C" {
21#endif
22
23/**
24 * \brief RIPEMD-160 context structure
25 */
Gilles Peskine449bd832023-01-11 14:50:10 +010026typedef struct mbedtls_ripemd160_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020027 uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
28 uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< intermediate digest state */
29 unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010030}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010032
33/**
Paul Bakker5b4af392014-06-26 12:09:34 +020034 * \brief Initialize RIPEMD-160 context
35 *
36 * \param ctx RIPEMD-160 context to be initialized
37 */
Gilles Peskine449bd832023-01-11 14:50:10 +010038void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020039
40/**
41 * \brief Clear RIPEMD-160 context
42 *
43 * \param ctx RIPEMD-160 context to be cleared
44 */
Gilles Peskine449bd832023-01-11 14:50:10 +010045void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020046
47/**
Tom Cosgrovece7f18c2022-07-28 05:50:56 +010048 * \brief Clone (the state of) a RIPEMD-160 context
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020049 *
50 * \param dst The destination context
51 * \param src The context to be cloned
52 */
Gilles Peskine449bd832023-01-11 14:50:10 +010053void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst,
54 const mbedtls_ripemd160_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020055
56/**
Paul Bakker61b699e2014-01-22 13:35:29 +010057 * \brief RIPEMD-160 context setup
58 *
59 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010060 *
61 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010062 */
Gilles Peskine449bd832023-01-11 14:50:10 +010063int mbedtls_ripemd160_starts(mbedtls_ripemd160_context *ctx);
Paul Bakker61b699e2014-01-22 13:35:29 +010064
65/**
66 * \brief RIPEMD-160 process buffer
67 *
68 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010069 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010070 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010071 *
72 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010073 */
Gilles Peskine449bd832023-01-11 14:50:10 +010074int mbedtls_ripemd160_update(mbedtls_ripemd160_context *ctx,
75 const unsigned char *input,
76 size_t ilen);
Paul Bakker61b699e2014-01-22 13:35:29 +010077
78/**
79 * \brief RIPEMD-160 final digest
80 *
81 * \param ctx RIPEMD-160 context
82 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010083 *
84 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010085 */
Gilles Peskine449bd832023-01-11 14:50:10 +010086int mbedtls_ripemd160_finish(mbedtls_ripemd160_context *ctx,
87 unsigned char output[20]);
Paul Bakker61b699e2014-01-22 13:35:29 +010088
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010089/**
90 * \brief RIPEMD-160 process data block (internal use only)
91 *
92 * \param ctx RIPEMD-160 context
93 * \param data buffer holding one block of data
94 *
95 * \return 0 if successful
96 */
Gilles Peskine449bd832023-01-11 14:50:10 +010097int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx,
98 const unsigned char data[64]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010099
Paul Bakker61b699e2014-01-22 13:35:29 +0100100/**
101 * \brief Output = RIPEMD-160( input buffer )
102 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100103 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100104 * \param ilen length of the input data
105 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100106 *
107 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100108 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100109int mbedtls_ripemd160(const unsigned char *input,
110 size_t ilen,
111 unsigned char output[20]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100112
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500113#if defined(MBEDTLS_SELF_TEST)
114
Paul Bakker61b699e2014-01-22 13:35:29 +0100115/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100116 * \brief Checkup routine
117 *
118 * \return 0 if successful, or 1 if the test failed
119 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100120int mbedtls_ripemd160_self_test(int verbose);
Paul Bakker61b699e2014-01-22 13:35:29 +0100121
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500122#endif /* MBEDTLS_SELF_TEST */
123
Paul Bakker61b699e2014-01-22 13:35:29 +0100124#ifdef __cplusplus
125}
126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#endif /* mbedtls_ripemd160.h */