Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/sha3/sph_ripemd.h
1201 views
1
/* $Id: sph_ripemd.h 216 2010-06-08 09:46:57Z tp $ */
2
/**
3
* RIPEMD, RIPEMD-128 and RIPEMD-160 interface.
4
*
5
* RIPEMD was first described in: Research and Development in Advanced
6
* Communication Technologies in Europe, "RIPE Integrity Primitives:
7
* Final Report of RACE Integrity Primitives Evaluation (R1040)", RACE,
8
* June 1992.
9
*
10
* A new, strengthened version, dubbed RIPEMD-160, was published in: H.
11
* Dobbertin, A. Bosselaers, and B. Preneel, "RIPEMD-160, a strengthened
12
* version of RIPEMD", Fast Software Encryption - FSE'96, LNCS 1039,
13
* Springer (1996), pp. 71--82.
14
*
15
* This article describes both RIPEMD-160, with a 160-bit output, and a
16
* reduced version called RIPEMD-128, which has a 128-bit output. RIPEMD-128
17
* was meant as a "drop-in" replacement for any hash function with 128-bit
18
* output, especially the original RIPEMD.
19
*
20
* @warning Collisions, and an efficient method to build other collisions,
21
* have been published for the original RIPEMD, which is thus considered as
22
* cryptographically broken. It is also very rarely encountered, and there
23
* seems to exist no free description or implementation of RIPEMD (except
24
* the sphlib code, of course). As of january 2007, RIPEMD-128 and RIPEMD-160
25
* seem as secure as their output length allows.
26
*
27
* ==========================(LICENSE BEGIN)============================
28
*
29
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
30
*
31
* Permission is hereby granted, free of charge, to any person obtaining
32
* a copy of this software and associated documentation files (the
33
* "Software"), to deal in the Software without restriction, including
34
* without limitation the rights to use, copy, modify, merge, publish,
35
* distribute, sublicense, and/or sell copies of the Software, and to
36
* permit persons to whom the Software is furnished to do so, subject to
37
* the following conditions:
38
*
39
* The above copyright notice and this permission notice shall be
40
* included in all copies or substantial portions of the Software.
41
*
42
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
*
50
* ===========================(LICENSE END)=============================
51
*
52
* @file sph_ripemd.h
53
* @author Thomas Pornin <[email protected]>
54
*/
55
56
#ifndef SPH_RIPEMD_H__
57
#define SPH_RIPEMD_H__
58
59
#include <stddef.h>
60
#include "sph_types.h"
61
62
/**
63
* Output size (in bits) for RIPEMD.
64
*/
65
#define SPH_SIZE_ripemd 128
66
67
/**
68
* Output size (in bits) for RIPEMD-128.
69
*/
70
#define SPH_SIZE_ripemd128 128
71
72
/**
73
* Output size (in bits) for RIPEMD-160.
74
*/
75
#define SPH_SIZE_ripemd160 160
76
77
/**
78
* This structure is a context for RIPEMD computations: it contains the
79
* intermediate values and some data from the last entered block. Once
80
* a RIPEMD computation has been performed, the context can be reused for
81
* another computation.
82
*
83
* The contents of this structure are private. A running RIPEMD computation
84
* can be cloned by copying the context (e.g. with a simple
85
* <code>memcpy()</code>).
86
*/
87
typedef struct {
88
#ifndef DOXYGEN_IGNORE
89
unsigned char buf[64]; /* first field, for alignment */
90
sph_u32 val[4];
91
#if SPH_64
92
sph_u64 count;
93
#else
94
sph_u32 count_high, count_low;
95
#endif
96
#endif
97
} sph_ripemd_context;
98
99
/**
100
* Initialize a RIPEMD context. This process performs no memory allocation.
101
*
102
* @param cc the RIPEMD context (pointer to
103
* a <code>sph_ripemd_context</code>)
104
*/
105
void sph_ripemd_init(void *cc);
106
107
/**
108
* Process some data bytes. It is acceptable that <code>len</code> is zero
109
* (in which case this function does nothing).
110
*
111
* @param cc the RIPEMD context
112
* @param data the input data
113
* @param len the input data length (in bytes)
114
*/
115
void sph_ripemd(void *cc, const void *data, size_t len);
116
117
/**
118
* Terminate the current RIPEMD computation and output the result into the
119
* provided buffer. The destination buffer must be wide enough to
120
* accomodate the result (16 bytes). The context is automatically
121
* reinitialized.
122
*
123
* @param cc the RIPEMD context
124
* @param dst the destination buffer
125
*/
126
void sph_ripemd_close(void *cc, void *dst);
127
128
/**
129
* Apply the RIPEMD compression function on the provided data. The
130
* <code>msg</code> parameter contains the 16 32-bit input blocks,
131
* as numerical values (hence after the little-endian decoding). The
132
* <code>val</code> parameter contains the 5 32-bit input blocks for
133
* the compression function; the output is written in place in this
134
* array.
135
*
136
* @param msg the message block (16 values)
137
* @param val the function 128-bit input and output
138
*/
139
void sph_ripemd_comp(const sph_u32 msg[16], sph_u32 val[4]);
140
141
/* ===================================================================== */
142
143
/**
144
* This structure is a context for RIPEMD-128 computations: it contains the
145
* intermediate values and some data from the last entered block. Once
146
* a RIPEMD-128 computation has been performed, the context can be reused for
147
* another computation.
148
*
149
* The contents of this structure are private. A running RIPEMD-128 computation
150
* can be cloned by copying the context (e.g. with a simple
151
* <code>memcpy()</code>).
152
*/
153
typedef struct {
154
#ifndef DOXYGEN_IGNORE
155
unsigned char buf[64]; /* first field, for alignment */
156
sph_u32 val[4];
157
#if SPH_64
158
sph_u64 count;
159
#else
160
sph_u32 count_high, count_low;
161
#endif
162
#endif
163
} sph_ripemd128_context;
164
165
/**
166
* Initialize a RIPEMD-128 context. This process performs no memory allocation.
167
*
168
* @param cc the RIPEMD-128 context (pointer to
169
* a <code>sph_ripemd128_context</code>)
170
*/
171
void sph_ripemd128_init(void *cc);
172
173
/**
174
* Process some data bytes. It is acceptable that <code>len</code> is zero
175
* (in which case this function does nothing).
176
*
177
* @param cc the RIPEMD-128 context
178
* @param data the input data
179
* @param len the input data length (in bytes)
180
*/
181
void sph_ripemd128(void *cc, const void *data, size_t len);
182
183
/**
184
* Terminate the current RIPEMD-128 computation and output the result into the
185
* provided buffer. The destination buffer must be wide enough to
186
* accomodate the result (16 bytes). The context is automatically
187
* reinitialized.
188
*
189
* @param cc the RIPEMD-128 context
190
* @param dst the destination buffer
191
*/
192
void sph_ripemd128_close(void *cc, void *dst);
193
194
/**
195
* Apply the RIPEMD-128 compression function on the provided data. The
196
* <code>msg</code> parameter contains the 16 32-bit input blocks,
197
* as numerical values (hence after the little-endian decoding). The
198
* <code>val</code> parameter contains the 5 32-bit input blocks for
199
* the compression function; the output is written in place in this
200
* array.
201
*
202
* @param msg the message block (16 values)
203
* @param val the function 128-bit input and output
204
*/
205
void sph_ripemd128_comp(const sph_u32 msg[16], sph_u32 val[4]);
206
207
/* ===================================================================== */
208
209
/**
210
* This structure is a context for RIPEMD-160 computations: it contains the
211
* intermediate values and some data from the last entered block. Once
212
* a RIPEMD-160 computation has been performed, the context can be reused for
213
* another computation.
214
*
215
* The contents of this structure are private. A running RIPEMD-160 computation
216
* can be cloned by copying the context (e.g. with a simple
217
* <code>memcpy()</code>).
218
*/
219
typedef struct {
220
#ifndef DOXYGEN_IGNORE
221
unsigned char buf[64]; /* first field, for alignment */
222
sph_u32 val[5];
223
#if SPH_64
224
sph_u64 count;
225
#else
226
sph_u32 count_high, count_low;
227
#endif
228
#endif
229
} sph_ripemd160_context;
230
231
/**
232
* Initialize a RIPEMD-160 context. This process performs no memory allocation.
233
*
234
* @param cc the RIPEMD-160 context (pointer to
235
* a <code>sph_ripemd160_context</code>)
236
*/
237
void sph_ripemd160_init(void *cc);
238
239
/**
240
* Process some data bytes. It is acceptable that <code>len</code> is zero
241
* (in which case this function does nothing).
242
*
243
* @param cc the RIPEMD-160 context
244
* @param data the input data
245
* @param len the input data length (in bytes)
246
*/
247
void sph_ripemd160(void *cc, const void *data, size_t len);
248
249
/**
250
* Terminate the current RIPEMD-160 computation and output the result into the
251
* provided buffer. The destination buffer must be wide enough to
252
* accomodate the result (20 bytes). The context is automatically
253
* reinitialized.
254
*
255
* @param cc the RIPEMD-160 context
256
* @param dst the destination buffer
257
*/
258
void sph_ripemd160_close(void *cc, void *dst);
259
260
/**
261
* Apply the RIPEMD-160 compression function on the provided data. The
262
* <code>msg</code> parameter contains the 16 32-bit input blocks,
263
* as numerical values (hence after the little-endian decoding). The
264
* <code>val</code> parameter contains the 5 32-bit input blocks for
265
* the compression function; the output is written in place in this
266
* array.
267
*
268
* @param msg the message block (16 values)
269
* @param val the function 160-bit input and output
270
*/
271
void sph_ripemd160_comp(const sph_u32 msg[16], sph_u32 val[5]);
272
273
#endif
274
275
276