blob: 02a92f5aa1b7bc3684519d02e8d8c993d54d9f4d [file] [log] [blame]
Paul Bakker61b699e2014-01-22 13:35:29 +01001/**
2 * \file rdm160.h
3 *
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
30#include "config.h"
31
32#include <string.h>
33
34#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
35#include <basetsd.h>
36typedef UINT32 uint32_t;
37#else
38#include <inttypes.h>
39#endif
40
41#define POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
42
Paul Bakker9f4c1622014-01-22 14:14:26 +010043#if !defined(POLARSSL_RIPEMD160_ALT)
44// Regular implementation
45//
46
Paul Bakker61b699e2014-01-22 13:35:29 +010047#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * \brief RIPEMD-160 context structure
53 */
54typedef struct
55{
56 uint32_t total[2]; /*!< number of bytes processed */
57 uint32_t state[5]; /*!< intermediate digest state */
58 unsigned char buffer[64]; /*!< data block being processed */
59
60 unsigned char ipad[64]; /*!< HMAC: inner padding */
61 unsigned char opad[64]; /*!< HMAC: outer padding */
62}
63ripemd160_context;
64
65/**
66 * \brief RIPEMD-160 context setup
67 *
68 * \param ctx context to be initialized
69 */
70void ripemd160_starts( ripemd160_context *ctx );
71
72/**
73 * \brief RIPEMD-160 process buffer
74 *
75 * \param ctx RIPEMD-160 context
76 * \param input buffer holding the data
77 * \param ilen length of the input data
78 */
79void ripemd160_update( ripemd160_context *ctx,
80 const unsigned char *input, size_t ilen );
81
82/**
83 * \brief RIPEMD-160 final digest
84 *
85 * \param ctx RIPEMD-160 context
86 * \param output RIPEMD-160 checksum result
87 */
88void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
89
Paul Bakker9f4c1622014-01-22 14:14:26 +010090/* Internal use */
91void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
92
93#ifdef __cplusplus
94}
95#endif
96
97#else /* POLARSSL_RIPEMD160_ALT */
98#include "ripemd160.h"
99#endif /* POLARSSL_RIPEMD160_ALT */
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
Paul Bakker61b699e2014-01-22 13:35:29 +0100105/**
106 * \brief Output = RIPEMD-160( input buffer )
107 *
108 * \param input buffer holding the data
109 * \param ilen length of the input data
110 * \param output RIPEMD-160 checksum result
111 */
112void ripemd160( const unsigned char *input, size_t ilen,
113 unsigned char output[20] );
114
115#if defined(POLARSSL_FS_IO)
116/**
117 * \brief Output = RIPEMD-160( file contents )
118 *
119 * \param path input file name
120 * \param output RIPEMD-160 checksum result
121 *
122 * \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
123 */
124int ripemd160_file( const char *path, unsigned char output[20] );
125#endif /* POLARSSL_FS_IO */
126
127/**
128 * \brief RIPEMD-160 HMAC context setup
129 *
130 * \param ctx HMAC context to be initialized
131 * \param key HMAC secret key
132 * \param keylen length of the HMAC key
133 */
134void ripemd160_hmac_starts( ripemd160_context *ctx,
135 const unsigned char *key, size_t keylen );
136
137/**
138 * \brief RIPEMD-160 HMAC process buffer
139 *
140 * \param ctx HMAC context
141 * \param input buffer holding the data
142 * \param ilen length of the input data
143 */
144void ripemd160_hmac_update( ripemd160_context *ctx,
145 const unsigned char *input, size_t ilen );
146
147/**
148 * \brief RIPEMD-160 HMAC final digest
149 *
150 * \param ctx HMAC context
151 * \param output RIPEMD-160 HMAC checksum result
152 */
153void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
154
155/**
156 * \brief RIPEMD-160 HMAC context reset
157 *
158 * \param ctx HMAC context to be reset
159 */
160void ripemd160_hmac_reset( ripemd160_context *ctx );
161
162/**
163 * \brief Output = HMAC-RIPEMD-160( hmac key, input buffer )
164 *
165 * \param key HMAC secret key
166 * \param keylen length of the HMAC key
167 * \param input buffer holding the data
168 * \param ilen length of the input data
169 * \param output HMAC-RIPEMD-160 result
170 */
171void ripemd160_hmac( const unsigned char *key, size_t keylen,
172 const unsigned char *input, size_t ilen,
173 unsigned char output[20] );
174
175/**
176 * \brief Checkup routine
177 *
178 * \return 0 if successful, or 1 if the test failed
179 */
180int ripemd160_self_test( int verbose );
181
Paul Bakker61b699e2014-01-22 13:35:29 +0100182#ifdef __cplusplus
183}
184#endif
185
186#endif /* ripemd160.h */