Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/sha3/sph_shabal.h
1201 views
1
/* $Id: sph_shabal.h 175 2010-05-07 16:03:20Z tp $ */
2
/**
3
* Shabal interface. Shabal is a family of functions which differ by
4
* their output size; this implementation defines Shabal for output
5
* sizes 192, 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_shabal.h
33
* @author Thomas Pornin <[email protected]>
34
*/
35
36
#ifndef SPH_SHABAL_H__
37
#define SPH_SHABAL_H__
38
39
#include <stddef.h>
40
#include "sph_types.h"
41
#ifdef __cplusplus
42
extern "C"{
43
#endif
44
45
/**
46
* Output size (in bits) for Shabal-192.
47
*/
48
#define SPH_SIZE_shabal192 192
49
50
/**
51
* Output size (in bits) for Shabal-224.
52
*/
53
#define SPH_SIZE_shabal224 224
54
55
/**
56
* Output size (in bits) for Shabal-256.
57
*/
58
#define SPH_SIZE_shabal256 256
59
60
/**
61
* Output size (in bits) for Shabal-384.
62
*/
63
#define SPH_SIZE_shabal384 384
64
65
/**
66
* Output size (in bits) for Shabal-512.
67
*/
68
#define SPH_SIZE_shabal512 512
69
70
/**
71
* This structure is a context for Shabal computations: it contains the
72
* intermediate values and some data from the last entered block. Once
73
* a Shabal computation has been performed, the context can be reused for
74
* another computation.
75
*
76
* The contents of this structure are private. A running Shabal computation
77
* can be cloned by copying the context (e.g. with a simple
78
* <code>memcpy()</code>).
79
*/
80
typedef struct {
81
#ifndef DOXYGEN_IGNORE
82
unsigned char buf[64]; /* first field, for alignment */
83
size_t ptr;
84
sph_u32 A[12], B[16], C[16];
85
sph_u32 Whigh, Wlow;
86
#endif
87
} sph_shabal_context;
88
89
/**
90
* Type for a Shabal-192 context (identical to the common context).
91
*/
92
typedef sph_shabal_context sph_shabal192_context;
93
94
/**
95
* Type for a Shabal-224 context (identical to the common context).
96
*/
97
typedef sph_shabal_context sph_shabal224_context;
98
99
/**
100
* Type for a Shabal-256 context (identical to the common context).
101
*/
102
typedef sph_shabal_context sph_shabal256_context;
103
104
/**
105
* Type for a Shabal-384 context (identical to the common context).
106
*/
107
typedef sph_shabal_context sph_shabal384_context;
108
109
/**
110
* Type for a Shabal-512 context (identical to the common context).
111
*/
112
typedef sph_shabal_context sph_shabal512_context;
113
114
/**
115
* Initialize a Shabal-192 context. This process performs no memory allocation.
116
*
117
* @param cc the Shabal-192 context (pointer to a
118
* <code>sph_shabal192_context</code>)
119
*/
120
void sph_shabal192_init(void *cc);
121
122
/**
123
* Process some data bytes. It is acceptable that <code>len</code> is zero
124
* (in which case this function does nothing).
125
*
126
* @param cc the Shabal-192 context
127
* @param data the input data
128
* @param len the input data length (in bytes)
129
*/
130
void sph_shabal192(void *cc, const void *data, size_t len);
131
132
/**
133
* Terminate the current Shabal-192 computation and output the result into
134
* the provided buffer. The destination buffer must be wide enough to
135
* accomodate the result (24 bytes). The context is automatically
136
* reinitialized.
137
*
138
* @param cc the Shabal-192 context
139
* @param dst the destination buffer
140
*/
141
void sph_shabal192_close(void *cc, void *dst);
142
143
/**
144
* Add a few additional bits (0 to 7) to the current computation, then
145
* terminate it and output the result in the provided buffer, which must
146
* be wide enough to accomodate the result (24 bytes). If bit number i
147
* in <code>ub</code> has value 2^i, then the extra bits are those
148
* numbered 7 downto 8-n (this is the big-endian convention at the byte
149
* level). The context is automatically reinitialized.
150
*
151
* @param cc the Shabal-192 context
152
* @param ub the extra bits
153
* @param n the number of extra bits (0 to 7)
154
* @param dst the destination buffer
155
*/
156
void sph_shabal192_addbits_and_close(
157
void *cc, unsigned ub, unsigned n, void *dst);
158
159
/**
160
* Initialize a Shabal-224 context. This process performs no memory allocation.
161
*
162
* @param cc the Shabal-224 context (pointer to a
163
* <code>sph_shabal224_context</code>)
164
*/
165
void sph_shabal224_init(void *cc);
166
167
/**
168
* Process some data bytes. It is acceptable that <code>len</code> is zero
169
* (in which case this function does nothing).
170
*
171
* @param cc the Shabal-224 context
172
* @param data the input data
173
* @param len the input data length (in bytes)
174
*/
175
void sph_shabal224(void *cc, const void *data, size_t len);
176
177
/**
178
* Terminate the current Shabal-224 computation and output the result into
179
* the provided buffer. The destination buffer must be wide enough to
180
* accomodate the result (28 bytes). The context is automatically
181
* reinitialized.
182
*
183
* @param cc the Shabal-224 context
184
* @param dst the destination buffer
185
*/
186
void sph_shabal224_close(void *cc, void *dst);
187
188
/**
189
* Add a few additional bits (0 to 7) to the current computation, then
190
* terminate it and output the result in the provided buffer, which must
191
* be wide enough to accomodate the result (28 bytes). If bit number i
192
* in <code>ub</code> has value 2^i, then the extra bits are those
193
* numbered 7 downto 8-n (this is the big-endian convention at the byte
194
* level). The context is automatically reinitialized.
195
*
196
* @param cc the Shabal-224 context
197
* @param ub the extra bits
198
* @param n the number of extra bits (0 to 7)
199
* @param dst the destination buffer
200
*/
201
void sph_shabal224_addbits_and_close(
202
void *cc, unsigned ub, unsigned n, void *dst);
203
204
/**
205
* Initialize a Shabal-256 context. This process performs no memory allocation.
206
*
207
* @param cc the Shabal-256 context (pointer to a
208
* <code>sph_shabal256_context</code>)
209
*/
210
void sph_shabal256_init(void *cc);
211
212
/**
213
* Process some data bytes. It is acceptable that <code>len</code> is zero
214
* (in which case this function does nothing).
215
*
216
* @param cc the Shabal-256 context
217
* @param data the input data
218
* @param len the input data length (in bytes)
219
*/
220
void sph_shabal256(void *cc, const void *data, size_t len);
221
222
/**
223
* Terminate the current Shabal-256 computation and output the result into
224
* the provided buffer. The destination buffer must be wide enough to
225
* accomodate the result (32 bytes). The context is automatically
226
* reinitialized.
227
*
228
* @param cc the Shabal-256 context
229
* @param dst the destination buffer
230
*/
231
void sph_shabal256_close(void *cc, void *dst);
232
233
/**
234
* Add a few additional bits (0 to 7) to the current computation, then
235
* terminate it and output the result in the provided buffer, which must
236
* be wide enough to accomodate the result (32 bytes). If bit number i
237
* in <code>ub</code> has value 2^i, then the extra bits are those
238
* numbered 7 downto 8-n (this is the big-endian convention at the byte
239
* level). The context is automatically reinitialized.
240
*
241
* @param cc the Shabal-256 context
242
* @param ub the extra bits
243
* @param n the number of extra bits (0 to 7)
244
* @param dst the destination buffer
245
*/
246
void sph_shabal256_addbits_and_close(
247
void *cc, unsigned ub, unsigned n, void *dst);
248
249
/**
250
* Initialize a Shabal-384 context. This process performs no memory allocation.
251
*
252
* @param cc the Shabal-384 context (pointer to a
253
* <code>sph_shabal384_context</code>)
254
*/
255
void sph_shabal384_init(void *cc);
256
257
/**
258
* Process some data bytes. It is acceptable that <code>len</code> is zero
259
* (in which case this function does nothing).
260
*
261
* @param cc the Shabal-384 context
262
* @param data the input data
263
* @param len the input data length (in bytes)
264
*/
265
void sph_shabal384(void *cc, const void *data, size_t len);
266
267
/**
268
* Terminate the current Shabal-384 computation and output the result into
269
* the provided buffer. The destination buffer must be wide enough to
270
* accomodate the result (48 bytes). The context is automatically
271
* reinitialized.
272
*
273
* @param cc the Shabal-384 context
274
* @param dst the destination buffer
275
*/
276
void sph_shabal384_close(void *cc, void *dst);
277
278
/**
279
* Add a few additional bits (0 to 7) to the current computation, then
280
* terminate it and output the result in the provided buffer, which must
281
* be wide enough to accomodate the result (48 bytes). If bit number i
282
* in <code>ub</code> has value 2^i, then the extra bits are those
283
* numbered 7 downto 8-n (this is the big-endian convention at the byte
284
* level). The context is automatically reinitialized.
285
*
286
* @param cc the Shabal-384 context
287
* @param ub the extra bits
288
* @param n the number of extra bits (0 to 7)
289
* @param dst the destination buffer
290
*/
291
void sph_shabal384_addbits_and_close(
292
void *cc, unsigned ub, unsigned n, void *dst);
293
294
/**
295
* Initialize a Shabal-512 context. This process performs no memory allocation.
296
*
297
* @param cc the Shabal-512 context (pointer to a
298
* <code>sph_shabal512_context</code>)
299
*/
300
void sph_shabal512_init(void *cc);
301
302
/**
303
* Process some data bytes. It is acceptable that <code>len</code> is zero
304
* (in which case this function does nothing).
305
*
306
* @param cc the Shabal-512 context
307
* @param data the input data
308
* @param len the input data length (in bytes)
309
*/
310
void sph_shabal512(void *cc, const void *data, size_t len);
311
312
/**
313
* Terminate the current Shabal-512 computation and output the result into
314
* the provided buffer. The destination buffer must be wide enough to
315
* accomodate the result (64 bytes). The context is automatically
316
* reinitialized.
317
*
318
* @param cc the Shabal-512 context
319
* @param dst the destination buffer
320
*/
321
void sph_shabal512_close(void *cc, void *dst);
322
323
/**
324
* Add a few additional bits (0 to 7) to the current computation, then
325
* terminate it and output the result in the provided buffer, which must
326
* be wide enough to accomodate the result (64 bytes). If bit number i
327
* in <code>ub</code> has value 2^i, then the extra bits are those
328
* numbered 7 downto 8-n (this is the big-endian convention at the byte
329
* level). The context is automatically reinitialized.
330
*
331
* @param cc the Shabal-512 context
332
* @param ub the extra bits
333
* @param n the number of extra bits (0 to 7)
334
* @param dst the destination buffer
335
*/
336
void sph_shabal512_addbits_and_close(
337
void *cc, unsigned ub, unsigned n, void *dst);
338
339
#ifdef __cplusplus
340
}
341
#endif
342
343
#endif
344
345