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