blob: 4762720fa9b2fffbcfb8ca07fa9a05cfe4e9cbf4 [file] [log] [blame]
Paul Bakker61b699e2014-01-22 13:35:29 +01001/**
Paul Bakkerd2c2c1c2014-04-11 15:28:52 +02002 * \file ripemd160.h
Paul Bakker61b699e2014-01-22 13:35:29 +01003 *
4 * \brief RIPE MD-160 message digest
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2014-2014, ARM Limited, All Rights Reserved
Paul Bakker61b699e2014-01-22 13:35:29 +01007 *
Manuel Pégourié-Gonnard860b5162015-01-28 17:12:07 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakker61b699e2014-01-22 13:35:29 +01009 *
Paul Bakker61b699e2014-01-22 13:35:29 +010010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24#ifndef POLARSSL_RIPEMD160_H
25#define POLARSSL_RIPEMD160_H
26
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker61b699e2014-01-22 13:35:29 +010034
35#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
36#include <basetsd.h>
37typedef UINT32 uint32_t;
38#else
39#include <inttypes.h>
40#endif
41
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010042#define POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR -0x007E /**< Read/write error in file. */
Paul Bakker61b699e2014-01-22 13:35:29 +010043
Paul Bakker9f4c1622014-01-22 14:14:26 +010044#if !defined(POLARSSL_RIPEMD160_ALT)
45// Regular implementation
46//
47
Paul Bakker61b699e2014-01-22 13:35:29 +010048#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * \brief RIPEMD-160 context structure
54 */
55typedef struct
56{
57 uint32_t total[2]; /*!< number of bytes processed */
58 uint32_t state[5]; /*!< intermediate digest state */
59 unsigned char buffer[64]; /*!< data block being processed */
60
61 unsigned char ipad[64]; /*!< HMAC: inner padding */
62 unsigned char opad[64]; /*!< HMAC: outer padding */
63}
64ripemd160_context;
65
66/**
Paul Bakker5b4af392014-06-26 12:09:34 +020067 * \brief Initialize RIPEMD-160 context
68 *
69 * \param ctx RIPEMD-160 context to be initialized
70 */
71void ripemd160_init( ripemd160_context *ctx );
72
73/**
74 * \brief Clear RIPEMD-160 context
75 *
76 * \param ctx RIPEMD-160 context to be cleared
77 */
78void ripemd160_free( ripemd160_context *ctx );
79
80/**
Paul Bakker61b699e2014-01-22 13:35:29 +010081 * \brief RIPEMD-160 context setup
82 *
83 * \param ctx context to be initialized
84 */
85void ripemd160_starts( ripemd160_context *ctx );
86
87/**
88 * \brief RIPEMD-160 process buffer
89 *
90 * \param ctx RIPEMD-160 context
91 * \param input buffer holding the data
92 * \param ilen length of the input data
93 */
94void ripemd160_update( ripemd160_context *ctx,
95 const unsigned char *input, size_t ilen );
96
97/**
98 * \brief RIPEMD-160 final digest
99 *
100 * \param ctx RIPEMD-160 context
101 * \param output RIPEMD-160 checksum result
102 */
103void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
104
Paul Bakker9f4c1622014-01-22 14:14:26 +0100105/* Internal use */
106void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
107
108#ifdef __cplusplus
109}
110#endif
111
112#else /* POLARSSL_RIPEMD160_ALT */
113#include "ripemd160.h"
114#endif /* POLARSSL_RIPEMD160_ALT */
115
116#ifdef __cplusplus
117extern "C" {
118#endif
119
Paul Bakker61b699e2014-01-22 13:35:29 +0100120/**
121 * \brief Output = RIPEMD-160( input buffer )
122 *
123 * \param input buffer holding the data
124 * \param ilen length of the input data
125 * \param output RIPEMD-160 checksum result
126 */
127void ripemd160( const unsigned char *input, size_t ilen,
128 unsigned char output[20] );
129
130#if defined(POLARSSL_FS_IO)
131/**
132 * \brief Output = RIPEMD-160( file contents )
133 *
134 * \param path input file name
135 * \param output RIPEMD-160 checksum result
136 *
137 * \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
138 */
139int ripemd160_file( const char *path, unsigned char output[20] );
140#endif /* POLARSSL_FS_IO */
141
142/**
143 * \brief RIPEMD-160 HMAC context setup
144 *
145 * \param ctx HMAC context to be initialized
146 * \param key HMAC secret key
147 * \param keylen length of the HMAC key
148 */
149void ripemd160_hmac_starts( ripemd160_context *ctx,
150 const unsigned char *key, size_t keylen );
151
152/**
153 * \brief RIPEMD-160 HMAC process buffer
154 *
155 * \param ctx HMAC context
156 * \param input buffer holding the data
157 * \param ilen length of the input data
158 */
159void ripemd160_hmac_update( ripemd160_context *ctx,
160 const unsigned char *input, size_t ilen );
161
162/**
163 * \brief RIPEMD-160 HMAC final digest
164 *
165 * \param ctx HMAC context
166 * \param output RIPEMD-160 HMAC checksum result
167 */
168void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
169
170/**
171 * \brief RIPEMD-160 HMAC context reset
172 *
173 * \param ctx HMAC context to be reset
174 */
175void ripemd160_hmac_reset( ripemd160_context *ctx );
176
177/**
178 * \brief Output = HMAC-RIPEMD-160( hmac key, input buffer )
179 *
180 * \param key HMAC secret key
181 * \param keylen length of the HMAC key
182 * \param input buffer holding the data
183 * \param ilen length of the input data
184 * \param output HMAC-RIPEMD-160 result
185 */
186void ripemd160_hmac( const unsigned char *key, size_t keylen,
187 const unsigned char *input, size_t ilen,
188 unsigned char output[20] );
189
190/**
191 * \brief Checkup routine
192 *
193 * \return 0 if successful, or 1 if the test failed
194 */
195int ripemd160_self_test( int verbose );
196
Paul Bakker61b699e2014-01-22 13:35:29 +0100197#ifdef __cplusplus
198}
199#endif
200
201#endif /* ripemd160.h */