Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/sha3/sph_echo.h
1201 views
1
/* $Id: sph_echo.h 216 2010-06-08 09:46:57Z tp $ */
2
/**
3
* ECHO interface. ECHO is a family of functions which differ by
4
* their output size; this implementation defines ECHO for output
5
* sizes 224, 256, 384 and 512 bits.
6
*
7
* ==========================(LICENSE BEGIN)============================
8
*
9
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
10
*
11
* Permission is hereby granted, free of charge, to any person obtaining
12
* a copy of this software and associated documentation files (the
13
* "Software"), to deal in the Software without restriction, including
14
* without limitation the rights to use, copy, modify, merge, publish,
15
* distribute, sublicense, and/or sell copies of the Software, and to
16
* permit persons to whom the Software is furnished to do so, subject to
17
* the following conditions:
18
*
19
* The above copyright notice and this permission notice shall be
20
* included in all copies or substantial portions of the Software.
21
*
22
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
*
30
* ===========================(LICENSE END)=============================
31
*
32
* @file sph_echo.h
33
* @author Thomas Pornin <[email protected]>
34
*/
35
36
#ifndef SPH_ECHO_H__
37
#define SPH_ECHO_H__
38
39
#ifdef __cplusplus
40
extern "C"{
41
#endif
42
43
#include <stddef.h>
44
#include "sph_types.h"
45
46
/**
47
* Output size (in bits) for ECHO-224.
48
*/
49
#define SPH_SIZE_echo224 224
50
51
/**
52
* Output size (in bits) for ECHO-256.
53
*/
54
#define SPH_SIZE_echo256 256
55
56
/**
57
* Output size (in bits) for ECHO-384.
58
*/
59
#define SPH_SIZE_echo384 384
60
61
/**
62
* Output size (in bits) for ECHO-512.
63
*/
64
#define SPH_SIZE_echo512 512
65
66
/**
67
* This structure is a context for ECHO computations: it contains the
68
* intermediate values and some data from the last entered block. Once
69
* an ECHO computation has been performed, the context can be reused for
70
* another computation. This specific structure is used for ECHO-224
71
* and ECHO-256.
72
*
73
* The contents of this structure are private. A running ECHO computation
74
* can be cloned by copying the context (e.g. with a simple
75
* <code>memcpy()</code>).
76
*/
77
typedef struct {
78
#ifndef DOXYGEN_IGNORE
79
unsigned char buf[192]; /* first field, for alignment */
80
size_t ptr;
81
union {
82
sph_u32 Vs[4][4];
83
#if SPH_64
84
sph_u64 Vb[4][2];
85
#endif
86
} u;
87
sph_u32 C0, C1, C2, C3;
88
#endif
89
} sph_echo_small_context;
90
91
/**
92
* This structure is a context for ECHO computations: it contains the
93
* intermediate values and some data from the last entered block. Once
94
* an ECHO computation has been performed, the context can be reused for
95
* another computation. This specific structure is used for ECHO-384
96
* and ECHO-512.
97
*
98
* The contents of this structure are private. A running ECHO computation
99
* can be cloned by copying the context (e.g. with a simple
100
* <code>memcpy()</code>).
101
*/
102
typedef struct {
103
#ifndef DOXYGEN_IGNORE
104
unsigned char buf[128]; /* first field, for alignment */
105
size_t ptr;
106
union {
107
sph_u32 Vs[8][4];
108
#if SPH_64
109
sph_u64 Vb[8][2];
110
#endif
111
} u;
112
sph_u32 C0, C1, C2, C3;
113
#endif
114
} sph_echo_big_context;
115
116
/**
117
* Type for a ECHO-224 context (identical to the common "small" context).
118
*/
119
typedef sph_echo_small_context sph_echo224_context;
120
121
/**
122
* Type for a ECHO-256 context (identical to the common "small" context).
123
*/
124
typedef sph_echo_small_context sph_echo256_context;
125
126
/**
127
* Type for a ECHO-384 context (identical to the common "big" context).
128
*/
129
typedef sph_echo_big_context sph_echo384_context;
130
131
/**
132
* Type for a ECHO-512 context (identical to the common "big" context).
133
*/
134
typedef sph_echo_big_context sph_echo512_context;
135
136
/**
137
* Initialize an ECHO-224 context. This process performs no memory allocation.
138
*
139
* @param cc the ECHO-224 context (pointer to a
140
* <code>sph_echo224_context</code>)
141
*/
142
void sph_echo224_init(void *cc);
143
144
/**
145
* Process some data bytes. It is acceptable that <code>len</code> is zero
146
* (in which case this function does nothing).
147
*
148
* @param cc the ECHO-224 context
149
* @param data the input data
150
* @param len the input data length (in bytes)
151
*/
152
void sph_echo224(void *cc, const void *data, size_t len);
153
154
/**
155
* Terminate the current ECHO-224 computation and output the result into
156
* the provided buffer. The destination buffer must be wide enough to
157
* accomodate the result (28 bytes). The context is automatically
158
* reinitialized.
159
*
160
* @param cc the ECHO-224 context
161
* @param dst the destination buffer
162
*/
163
void sph_echo224_close(void *cc, void *dst);
164
165
/**
166
* Add a few additional bits (0 to 7) to the current computation, then
167
* terminate it and output the result in the provided buffer, which must
168
* be wide enough to accomodate the result (28 bytes). If bit number i
169
* in <code>ub</code> has value 2^i, then the extra bits are those
170
* numbered 7 downto 8-n (this is the big-endian convention at the byte
171
* level). The context is automatically reinitialized.
172
*
173
* @param cc the ECHO-224 context
174
* @param ub the extra bits
175
* @param n the number of extra bits (0 to 7)
176
* @param dst the destination buffer
177
*/
178
void sph_echo224_addbits_and_close(
179
void *cc, unsigned ub, unsigned n, void *dst);
180
181
/**
182
* Initialize an ECHO-256 context. This process performs no memory allocation.
183
*
184
* @param cc the ECHO-256 context (pointer to a
185
* <code>sph_echo256_context</code>)
186
*/
187
void sph_echo256_init(void *cc);
188
189
/**
190
* Process some data bytes. It is acceptable that <code>len</code> is zero
191
* (in which case this function does nothing).
192
*
193
* @param cc the ECHO-256 context
194
* @param data the input data
195
* @param len the input data length (in bytes)
196
*/
197
void sph_echo256(void *cc, const void *data, size_t len);
198
199
/**
200
* Terminate the current ECHO-256 computation and output the result into
201
* the provided buffer. The destination buffer must be wide enough to
202
* accomodate the result (32 bytes). The context is automatically
203
* reinitialized.
204
*
205
* @param cc the ECHO-256 context
206
* @param dst the destination buffer
207
*/
208
void sph_echo256_close(void *cc, void *dst);
209
210
/**
211
* Add a few additional bits (0 to 7) to the current computation, then
212
* terminate it and output the result in the provided buffer, which must
213
* be wide enough to accomodate the result (32 bytes). If bit number i
214
* in <code>ub</code> has value 2^i, then the extra bits are those
215
* numbered 7 downto 8-n (this is the big-endian convention at the byte
216
* level). The context is automatically reinitialized.
217
*
218
* @param cc the ECHO-256 context
219
* @param ub the extra bits
220
* @param n the number of extra bits (0 to 7)
221
* @param dst the destination buffer
222
*/
223
void sph_echo256_addbits_and_close(
224
void *cc, unsigned ub, unsigned n, void *dst);
225
226
/**
227
* Initialize an ECHO-384 context. This process performs no memory allocation.
228
*
229
* @param cc the ECHO-384 context (pointer to a
230
* <code>sph_echo384_context</code>)
231
*/
232
void sph_echo384_init(void *cc);
233
234
/**
235
* Process some data bytes. It is acceptable that <code>len</code> is zero
236
* (in which case this function does nothing).
237
*
238
* @param cc the ECHO-384 context
239
* @param data the input data
240
* @param len the input data length (in bytes)
241
*/
242
void sph_echo384(void *cc, const void *data, size_t len);
243
244
/**
245
* Terminate the current ECHO-384 computation and output the result into
246
* the provided buffer. The destination buffer must be wide enough to
247
* accomodate the result (48 bytes). The context is automatically
248
* reinitialized.
249
*
250
* @param cc the ECHO-384 context
251
* @param dst the destination buffer
252
*/
253
void sph_echo384_close(void *cc, void *dst);
254
255
/**
256
* Add a few additional bits (0 to 7) to the current computation, then
257
* terminate it and output the result in the provided buffer, which must
258
* be wide enough to accomodate the result (48 bytes). If bit number i
259
* in <code>ub</code> has value 2^i, then the extra bits are those
260
* numbered 7 downto 8-n (this is the big-endian convention at the byte
261
* level). The context is automatically reinitialized.
262
*
263
* @param cc the ECHO-384 context
264
* @param ub the extra bits
265
* @param n the number of extra bits (0 to 7)
266
* @param dst the destination buffer
267
*/
268
void sph_echo384_addbits_and_close(
269
void *cc, unsigned ub, unsigned n, void *dst);
270
271
/**
272
* Initialize an ECHO-512 context. This process performs no memory allocation.
273
*
274
* @param cc the ECHO-512 context (pointer to a
275
* <code>sph_echo512_context</code>)
276
*/
277
void sph_echo512_init(void *cc);
278
279
/**
280
* Process some data bytes. It is acceptable that <code>len</code> is zero
281
* (in which case this function does nothing).
282
*
283
* @param cc the ECHO-512 context
284
* @param data the input data
285
* @param len the input data length (in bytes)
286
*/
287
void sph_echo512(void *cc, const void *data, size_t len);
288
289
/**
290
* Terminate the current ECHO-512 computation and output the result into
291
* the provided buffer. The destination buffer must be wide enough to
292
* accomodate the result (64 bytes). The context is automatically
293
* reinitialized.
294
*
295
* @param cc the ECHO-512 context
296
* @param dst the destination buffer
297
*/
298
void sph_echo512_close(void *cc, void *dst);
299
300
/**
301
* Add a few additional bits (0 to 7) to the current computation, then
302
* terminate it and output the result in the provided buffer, which must
303
* be wide enough to accomodate the result (64 bytes). If bit number i
304
* in <code>ub</code> has value 2^i, then the extra bits are those
305
* numbered 7 downto 8-n (this is the big-endian convention at the byte
306
* level). The context is automatically reinitialized.
307
*
308
* @param cc the ECHO-512 context
309
* @param ub the extra bits
310
* @param n the number of extra bits (0 to 7)
311
* @param dst the destination buffer
312
*/
313
void sph_echo512_addbits_and_close(
314
void *cc, unsigned ub, unsigned n, void *dst);
315
316
#ifdef __cplusplus
317
}
318
#endif
319
320
#endif
321
322