blob: 8365f4eeb1ca7935a364e77b6420d873556dcde0 [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 *
Manuel Pégourié-Gonnard967a2a52015-01-22 14:28:16 +00008 * This file is part of mbed TLS (http://www.polarssl.org)
Paul Bakker61b699e2014-01-22 13:35:29 +01009 * 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/**
Paul Bakker5b4af392014-06-26 12:09:34 +020070 * \brief Initialize RIPEMD-160 context
71 *
72 * \param ctx RIPEMD-160 context to be initialized
73 */
74void ripemd160_init( ripemd160_context *ctx );
75
76/**
77 * \brief Clear RIPEMD-160 context
78 *
79 * \param ctx RIPEMD-160 context to be cleared
80 */
81void ripemd160_free( ripemd160_context *ctx );
82
83/**
Paul Bakker61b699e2014-01-22 13:35:29 +010084 * \brief RIPEMD-160 context setup
85 *
86 * \param ctx context to be initialized
87 */
88void ripemd160_starts( ripemd160_context *ctx );
89
90/**
91 * \brief RIPEMD-160 process buffer
92 *
93 * \param ctx RIPEMD-160 context
94 * \param input buffer holding the data
95 * \param ilen length of the input data
96 */
97void ripemd160_update( ripemd160_context *ctx,
98 const unsigned char *input, size_t ilen );
99
100/**
101 * \brief RIPEMD-160 final digest
102 *
103 * \param ctx RIPEMD-160 context
104 * \param output RIPEMD-160 checksum result
105 */
106void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
107
Paul Bakker9f4c1622014-01-22 14:14:26 +0100108/* Internal use */
109void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
110
111#ifdef __cplusplus
112}
113#endif
114
115#else /* POLARSSL_RIPEMD160_ALT */
116#include "ripemd160.h"
117#endif /* POLARSSL_RIPEMD160_ALT */
118
119#ifdef __cplusplus
120extern "C" {
121#endif
122
Paul Bakker61b699e2014-01-22 13:35:29 +0100123/**
124 * \brief Output = RIPEMD-160( input buffer )
125 *
126 * \param input buffer holding the data
127 * \param ilen length of the input data
128 * \param output RIPEMD-160 checksum result
129 */
130void ripemd160( const unsigned char *input, size_t ilen,
131 unsigned char output[20] );
132
133#if defined(POLARSSL_FS_IO)
134/**
135 * \brief Output = RIPEMD-160( file contents )
136 *
137 * \param path input file name
138 * \param output RIPEMD-160 checksum result
139 *
140 * \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
141 */
142int ripemd160_file( const char *path, unsigned char output[20] );
143#endif /* POLARSSL_FS_IO */
144
145/**
146 * \brief RIPEMD-160 HMAC context setup
147 *
148 * \param ctx HMAC context to be initialized
149 * \param key HMAC secret key
150 * \param keylen length of the HMAC key
151 */
152void ripemd160_hmac_starts( ripemd160_context *ctx,
153 const unsigned char *key, size_t keylen );
154
155/**
156 * \brief RIPEMD-160 HMAC process buffer
157 *
158 * \param ctx HMAC context
159 * \param input buffer holding the data
160 * \param ilen length of the input data
161 */
162void ripemd160_hmac_update( ripemd160_context *ctx,
163 const unsigned char *input, size_t ilen );
164
165/**
166 * \brief RIPEMD-160 HMAC final digest
167 *
168 * \param ctx HMAC context
169 * \param output RIPEMD-160 HMAC checksum result
170 */
171void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
172
173/**
174 * \brief RIPEMD-160 HMAC context reset
175 *
176 * \param ctx HMAC context to be reset
177 */
178void ripemd160_hmac_reset( ripemd160_context *ctx );
179
180/**
181 * \brief Output = HMAC-RIPEMD-160( hmac key, input buffer )
182 *
183 * \param key HMAC secret key
184 * \param keylen length of the HMAC key
185 * \param input buffer holding the data
186 * \param ilen length of the input data
187 * \param output HMAC-RIPEMD-160 result
188 */
189void ripemd160_hmac( const unsigned char *key, size_t keylen,
190 const unsigned char *input, size_t ilen,
191 unsigned char output[20] );
192
193/**
194 * \brief Checkup routine
195 *
196 * \return 0 if successful, or 1 if the test failed
197 */
198int ripemd160_self_test( int verbose );
199
Paul Bakker61b699e2014-01-22 13:35:29 +0100200#ifdef __cplusplus
201}
202#endif
203
204#endif /* ripemd160.h */