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