blob: 754322d6efba4ddd393a6127171fdf546bdfadde [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 *
6 * Copyright (C) 2014-2014, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_RIPEMD160_H
28#define POLARSSL_RIPEMD160_H
29
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker61b699e2014-01-22 13:35:29 +010031#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakker61b699e2014-01-22 13:35:29 +010035
36#include <string.h>
37
38#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
39#include <basetsd.h>
40typedef UINT32 uint32_t;
41#else
42#include <inttypes.h>
43#endif
44
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010045#define POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR -0x007E /**< Read/write error in file. */
Paul Bakker61b699e2014-01-22 13:35:29 +010046
Paul Bakker9f4c1622014-01-22 14:14:26 +010047#if !defined(POLARSSL_RIPEMD160_ALT)
48// Regular implementation
49//
50
Paul Bakker61b699e2014-01-22 13:35:29 +010051#ifdef __cplusplus
52extern "C" {
53#endif
54
55/**
56 * \brief RIPEMD-160 context structure
57 */
58typedef struct
59{
60 uint32_t total[2]; /*!< number of bytes processed */
61 uint32_t state[5]; /*!< intermediate digest state */
62 unsigned char buffer[64]; /*!< data block being processed */
63
64 unsigned char ipad[64]; /*!< HMAC: inner padding */
65 unsigned char opad[64]; /*!< HMAC: outer padding */
66}
67ripemd160_context;
68
69/**
70 * \brief RIPEMD-160 context setup
71 *
72 * \param ctx context to be initialized
73 */
74void ripemd160_starts( ripemd160_context *ctx );
75
76/**
77 * \brief RIPEMD-160 process buffer
78 *
79 * \param ctx RIPEMD-160 context
80 * \param input buffer holding the data
81 * \param ilen length of the input data
82 */
83void ripemd160_update( ripemd160_context *ctx,
84 const unsigned char *input, size_t ilen );
85
86/**
87 * \brief RIPEMD-160 final digest
88 *
89 * \param ctx RIPEMD-160 context
90 * \param output RIPEMD-160 checksum result
91 */
92void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
93
Paul Bakker9f4c1622014-01-22 14:14:26 +010094/* Internal use */
95void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
96
97#ifdef __cplusplus
98}
99#endif
100
101#else /* POLARSSL_RIPEMD160_ALT */
102#include "ripemd160.h"
103#endif /* POLARSSL_RIPEMD160_ALT */
104
105#ifdef __cplusplus
106extern "C" {
107#endif
108
Paul Bakker61b699e2014-01-22 13:35:29 +0100109/**
110 * \brief Output = RIPEMD-160( input buffer )
111 *
112 * \param input buffer holding the data
113 * \param ilen length of the input data
114 * \param output RIPEMD-160 checksum result
115 */
116void ripemd160( const unsigned char *input, size_t ilen,
117 unsigned char output[20] );
118
119#if defined(POLARSSL_FS_IO)
120/**
121 * \brief Output = RIPEMD-160( file contents )
122 *
123 * \param path input file name
124 * \param output RIPEMD-160 checksum result
125 *
126 * \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
127 */
128int ripemd160_file( const char *path, unsigned char output[20] );
129#endif /* POLARSSL_FS_IO */
130
131/**
132 * \brief RIPEMD-160 HMAC context setup
133 *
134 * \param ctx HMAC context to be initialized
135 * \param key HMAC secret key
136 * \param keylen length of the HMAC key
137 */
138void ripemd160_hmac_starts( ripemd160_context *ctx,
139 const unsigned char *key, size_t keylen );
140
141/**
142 * \brief RIPEMD-160 HMAC process buffer
143 *
144 * \param ctx HMAC context
145 * \param input buffer holding the data
146 * \param ilen length of the input data
147 */
148void ripemd160_hmac_update( ripemd160_context *ctx,
149 const unsigned char *input, size_t ilen );
150
151/**
152 * \brief RIPEMD-160 HMAC final digest
153 *
154 * \param ctx HMAC context
155 * \param output RIPEMD-160 HMAC checksum result
156 */
157void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
158
159/**
160 * \brief RIPEMD-160 HMAC context reset
161 *
162 * \param ctx HMAC context to be reset
163 */
164void ripemd160_hmac_reset( ripemd160_context *ctx );
165
166/**
167 * \brief Output = HMAC-RIPEMD-160( hmac key, input buffer )
168 *
169 * \param key HMAC secret key
170 * \param keylen length of the HMAC key
171 * \param input buffer holding the data
172 * \param ilen length of the input data
173 * \param output HMAC-RIPEMD-160 result
174 */
175void ripemd160_hmac( const unsigned char *key, size_t keylen,
176 const unsigned char *input, size_t ilen,
177 unsigned char output[20] );
178
179/**
180 * \brief Checkup routine
181 *
182 * \return 0 if successful, or 1 if the test failed
183 */
184int ripemd160_self_test( int verbose );
185
Paul Bakker61b699e2014-01-22 13:35:29 +0100186#ifdef __cplusplus
187}
188#endif
189
190#endif /* ripemd160.h */