blob: 47a73bd9e6bfbab523203ae2ff6afc5ae3d747e4 [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
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/**
48 * \brief RIPEMD-160 context structure
49 */
50typedef struct
51{
52 uint32_t total[2]; /*!< number of bytes processed */
53 uint32_t state[5]; /*!< intermediate digest state */
54 unsigned char buffer[64]; /*!< data block being processed */
55
56 unsigned char ipad[64]; /*!< HMAC: inner padding */
57 unsigned char opad[64]; /*!< HMAC: outer padding */
58}
59ripemd160_context;
60
61/**
62 * \brief RIPEMD-160 context setup
63 *
64 * \param ctx context to be initialized
65 */
66void ripemd160_starts( ripemd160_context *ctx );
67
68/**
69 * \brief RIPEMD-160 process buffer
70 *
71 * \param ctx RIPEMD-160 context
72 * \param input buffer holding the data
73 * \param ilen length of the input data
74 */
75void ripemd160_update( ripemd160_context *ctx,
76 const unsigned char *input, size_t ilen );
77
78/**
79 * \brief RIPEMD-160 final digest
80 *
81 * \param ctx RIPEMD-160 context
82 * \param output RIPEMD-160 checksum result
83 */
84void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
85
86/**
87 * \brief Output = RIPEMD-160( input buffer )
88 *
89 * \param input buffer holding the data
90 * \param ilen length of the input data
91 * \param output RIPEMD-160 checksum result
92 */
93void ripemd160( const unsigned char *input, size_t ilen,
94 unsigned char output[20] );
95
96#if defined(POLARSSL_FS_IO)
97/**
98 * \brief Output = RIPEMD-160( file contents )
99 *
100 * \param path input file name
101 * \param output RIPEMD-160 checksum result
102 *
103 * \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
104 */
105int ripemd160_file( const char *path, unsigned char output[20] );
106#endif /* POLARSSL_FS_IO */
107
108/**
109 * \brief RIPEMD-160 HMAC context setup
110 *
111 * \param ctx HMAC context to be initialized
112 * \param key HMAC secret key
113 * \param keylen length of the HMAC key
114 */
115void ripemd160_hmac_starts( ripemd160_context *ctx,
116 const unsigned char *key, size_t keylen );
117
118/**
119 * \brief RIPEMD-160 HMAC process buffer
120 *
121 * \param ctx HMAC context
122 * \param input buffer holding the data
123 * \param ilen length of the input data
124 */
125void ripemd160_hmac_update( ripemd160_context *ctx,
126 const unsigned char *input, size_t ilen );
127
128/**
129 * \brief RIPEMD-160 HMAC final digest
130 *
131 * \param ctx HMAC context
132 * \param output RIPEMD-160 HMAC checksum result
133 */
134void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
135
136/**
137 * \brief RIPEMD-160 HMAC context reset
138 *
139 * \param ctx HMAC context to be reset
140 */
141void ripemd160_hmac_reset( ripemd160_context *ctx );
142
143/**
144 * \brief Output = HMAC-RIPEMD-160( hmac key, input buffer )
145 *
146 * \param key HMAC secret key
147 * \param keylen length of the HMAC key
148 * \param input buffer holding the data
149 * \param ilen length of the input data
150 * \param output HMAC-RIPEMD-160 result
151 */
152void ripemd160_hmac( const unsigned char *key, size_t keylen,
153 const unsigned char *input, size_t ilen,
154 unsigned char output[20] );
155
156/**
157 * \brief Checkup routine
158 *
159 * \return 0 if successful, or 1 if the test failed
160 */
161int ripemd160_self_test( int verbose );
162
163/* Internal use */
164void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* ripemd160.h */