blob: 279f92b5121e66ebe404ffac59b03d38a2f85bdb [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
Ron Eldorb2aacec2017-05-18 16:53:08 +030023#if !defined(MBEDTLS_RIPEMD160_ALT)
24// Regular implementation
25//
26
Paul Bakker61b699e2014-01-22 13:35:29 +010027/**
28 * \brief RIPEMD-160 context structure
29 */
Gilles Peskine449bd832023-01-11 14:50:10 +010030typedef struct mbedtls_ripemd160_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020031 uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
32 uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< intermediate digest state */
33 unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
Paul Bakker61b699e2014-01-22 13:35:29 +010034}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035mbedtls_ripemd160_context;
Paul Bakker61b699e2014-01-22 13:35:29 +010036
Ron Eldorb2aacec2017-05-18 16:53:08 +030037#else /* MBEDTLS_RIPEMD160_ALT */
Jaeden Amero8045cfb2019-07-04 20:26:59 +010038#include "ripemd160_alt.h"
Ron Eldorb2aacec2017-05-18 16:53:08 +030039#endif /* MBEDTLS_RIPEMD160_ALT */
40
Paul Bakker61b699e2014-01-22 13:35:29 +010041/**
Paul Bakker5b4af392014-06-26 12:09:34 +020042 * \brief Initialize RIPEMD-160 context
43 *
44 * \param ctx RIPEMD-160 context to be initialized
45 */
Gilles Peskine449bd832023-01-11 14:50:10 +010046void mbedtls_ripemd160_init(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020047
48/**
49 * \brief Clear RIPEMD-160 context
50 *
51 * \param ctx RIPEMD-160 context to be cleared
52 */
Gilles Peskine449bd832023-01-11 14:50:10 +010053void mbedtls_ripemd160_free(mbedtls_ripemd160_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020054
55/**
Tom Cosgrovece7f18c2022-07-28 05:50:56 +010056 * \brief Clone (the state of) a RIPEMD-160 context
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020057 *
58 * \param dst The destination context
59 * \param src The context to be cloned
60 */
Gilles Peskine449bd832023-01-11 14:50:10 +010061void mbedtls_ripemd160_clone(mbedtls_ripemd160_context *dst,
62 const mbedtls_ripemd160_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020063
64/**
Paul Bakker61b699e2014-01-22 13:35:29 +010065 * \brief RIPEMD-160 context setup
66 *
67 * \param ctx context to be initialized
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010068 *
69 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010070 */
Gilles Peskine449bd832023-01-11 14:50:10 +010071int mbedtls_ripemd160_starts(mbedtls_ripemd160_context *ctx);
Paul Bakker61b699e2014-01-22 13:35:29 +010072
73/**
74 * \brief RIPEMD-160 process buffer
75 *
76 * \param ctx RIPEMD-160 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010077 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +010078 * \param ilen length of the input data
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010079 *
80 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +010081 */
Gilles Peskine449bd832023-01-11 14:50:10 +010082int mbedtls_ripemd160_update(mbedtls_ripemd160_context *ctx,
83 const unsigned char *input,
84 size_t ilen);
Paul Bakker61b699e2014-01-22 13:35:29 +010085
86/**
87 * \brief RIPEMD-160 final digest
88 *
89 * \param ctx RIPEMD-160 context
90 * \param output RIPEMD-160 checksum result
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_finish(mbedtls_ripemd160_context *ctx,
95 unsigned char output[20]);
Paul Bakker61b699e2014-01-22 13:35:29 +010096
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +010097/**
98 * \brief RIPEMD-160 process data block (internal use only)
99 *
100 * \param ctx RIPEMD-160 context
101 * \param data buffer holding one block of data
102 *
103 * \return 0 if successful
104 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100105int mbedtls_internal_ripemd160_process(mbedtls_ripemd160_context *ctx,
106 const unsigned char data[64]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100107
Paul Bakker61b699e2014-01-22 13:35:29 +0100108/**
109 * \brief Output = RIPEMD-160( input buffer )
110 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100111 * \param input buffer holding the data
Paul Bakker61b699e2014-01-22 13:35:29 +0100112 * \param ilen length of the input data
113 * \param output RIPEMD-160 checksum result
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100114 *
115 * \return 0 if successful
Paul Bakker61b699e2014-01-22 13:35:29 +0100116 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100117int mbedtls_ripemd160(const unsigned char *input,
118 size_t ilen,
119 unsigned char output[20]);
Andres Amaya Garciab1a8bf92017-05-02 10:59:46 +0100120
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500121#if defined(MBEDTLS_SELF_TEST)
122
Paul Bakker61b699e2014-01-22 13:35:29 +0100123/**
Paul Bakker61b699e2014-01-22 13:35:29 +0100124 * \brief Checkup routine
125 *
126 * \return 0 if successful, or 1 if the test failed
127 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100128int mbedtls_ripemd160_self_test(int verbose);
Paul Bakker61b699e2014-01-22 13:35:29 +0100129
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500130#endif /* MBEDTLS_SELF_TEST */
131
Paul Bakker61b699e2014-01-22 13:35:29 +0100132#ifdef __cplusplus
133}
134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#endif /* mbedtls_ripemd160.h */