Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/sha3/sph_hamsi.h
1201 views
1
/* $Id: sph_hamsi.h 216 2010-06-08 09:46:57Z tp $ */
2
/**
3
* Hamsi interface. This code implements Hamsi 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_hamsi.h
32
* @author Thomas Pornin <[email protected]>
33
*/
34
35
#ifndef SPH_HAMSI_H__
36
#define SPH_HAMSI_H__
37
38
#include <stddef.h>
39
#include "sph_types.h"
40
41
#ifdef __cplusplus
42
extern "C"{
43
#endif
44
45
/**
46
* Output size (in bits) for Hamsi-224.
47
*/
48
#define SPH_SIZE_hamsi224 224
49
50
/**
51
* Output size (in bits) for Hamsi-256.
52
*/
53
#define SPH_SIZE_hamsi256 256
54
55
/**
56
* Output size (in bits) for Hamsi-384.
57
*/
58
#define SPH_SIZE_hamsi384 384
59
60
/**
61
* Output size (in bits) for Hamsi-512.
62
*/
63
#define SPH_SIZE_hamsi512 512
64
65
/**
66
* This structure is a context for Hamsi-224 and Hamsi-256 computations:
67
* it contains the intermediate values and some data from the last
68
* entered block. Once a Hamsi computation has been performed, the
69
* context can be reused for another computation.
70
*
71
* The contents of this structure are private. A running Hamsi
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 partial[4];
78
size_t partial_len;
79
sph_u32 h[8];
80
#if SPH_64
81
sph_u64 count;
82
#else
83
sph_u32 count_high, count_low;
84
#endif
85
#endif
86
} sph_hamsi_small_context;
87
88
/**
89
* This structure is a context for Hamsi-224 computations. It is
90
* identical to the common <code>sph_hamsi_small_context</code>.
91
*/
92
typedef sph_hamsi_small_context sph_hamsi224_context;
93
94
/**
95
* This structure is a context for Hamsi-256 computations. It is
96
* identical to the common <code>sph_hamsi_small_context</code>.
97
*/
98
typedef sph_hamsi_small_context sph_hamsi256_context;
99
100
/**
101
* This structure is a context for Hamsi-384 and Hamsi-512 computations:
102
* it contains the intermediate values and some data from the last
103
* entered block. Once a Hamsi computation has been performed, the
104
* context can be reused for another computation.
105
*
106
* The contents of this structure are private. A running Hamsi
107
* computation can be cloned by copying the context (e.g. with a simple
108
* <code>memcpy()</code>).
109
*/
110
typedef struct {
111
#ifndef DOXYGEN_IGNORE
112
unsigned char partial[8];
113
size_t partial_len;
114
sph_u32 h[16];
115
#if SPH_64
116
sph_u64 count;
117
#else
118
sph_u32 count_high, count_low;
119
#endif
120
#endif
121
} sph_hamsi_big_context;
122
123
/**
124
* This structure is a context for Hamsi-384 computations. It is
125
* identical to the common <code>sph_hamsi_small_context</code>.
126
*/
127
typedef sph_hamsi_big_context sph_hamsi384_context;
128
129
/**
130
* This structure is a context for Hamsi-512 computations. It is
131
* identical to the common <code>sph_hamsi_small_context</code>.
132
*/
133
typedef sph_hamsi_big_context sph_hamsi512_context;
134
135
/**
136
* Initialize a Hamsi-224 context. This process performs no memory allocation.
137
*
138
* @param cc the Hamsi-224 context (pointer to a
139
* <code>sph_hamsi224_context</code>)
140
*/
141
void sph_hamsi224_init(void *cc);
142
143
/**
144
* Process some data bytes. It is acceptable that <code>len</code> is zero
145
* (in which case this function does nothing).
146
*
147
* @param cc the Hamsi-224 context
148
* @param data the input data
149
* @param len the input data length (in bytes)
150
*/
151
void sph_hamsi224(void *cc, const void *data, size_t len);
152
153
/**
154
* Terminate the current Hamsi-224 computation and output the result into
155
* the provided buffer. The destination buffer must be wide enough to
156
* accomodate the result (28 bytes). The context is automatically
157
* reinitialized.
158
*
159
* @param cc the Hamsi-224 context
160
* @param dst the destination buffer
161
*/
162
void sph_hamsi224_close(void *cc, void *dst);
163
164
/**
165
* Add a few additional bits (0 to 7) to the current computation, then
166
* terminate it and output the result in the provided buffer, which must
167
* be wide enough to accomodate the result (28 bytes). If bit number i
168
* in <code>ub</code> has value 2^i, then the extra bits are those
169
* numbered 7 downto 8-n (this is the big-endian convention at the byte
170
* level). The context is automatically reinitialized.
171
*
172
* @param cc the Hamsi-224 context
173
* @param ub the extra bits
174
* @param n the number of extra bits (0 to 7)
175
* @param dst the destination buffer
176
*/
177
void sph_hamsi224_addbits_and_close(
178
void *cc, unsigned ub, unsigned n, void *dst);
179
180
/**
181
* Initialize a Hamsi-256 context. This process performs no memory allocation.
182
*
183
* @param cc the Hamsi-256 context (pointer to a
184
* <code>sph_hamsi256_context</code>)
185
*/
186
void sph_hamsi256_init(void *cc);
187
188
/**
189
* Process some data bytes. It is acceptable that <code>len</code> is zero
190
* (in which case this function does nothing).
191
*
192
* @param cc the Hamsi-256 context
193
* @param data the input data
194
* @param len the input data length (in bytes)
195
*/
196
void sph_hamsi256(void *cc, const void *data, size_t len);
197
198
/**
199
* Terminate the current Hamsi-256 computation and output the result into
200
* the provided buffer. The destination buffer must be wide enough to
201
* accomodate the result (32 bytes). The context is automatically
202
* reinitialized.
203
*
204
* @param cc the Hamsi-256 context
205
* @param dst the destination buffer
206
*/
207
void sph_hamsi256_close(void *cc, void *dst);
208
209
/**
210
* Add a few additional bits (0 to 7) to the current computation, then
211
* terminate it and output the result in the provided buffer, which must
212
* be wide enough to accomodate the result (32 bytes). If bit number i
213
* in <code>ub</code> has value 2^i, then the extra bits are those
214
* numbered 7 downto 8-n (this is the big-endian convention at the byte
215
* level). The context is automatically reinitialized.
216
*
217
* @param cc the Hamsi-256 context
218
* @param ub the extra bits
219
* @param n the number of extra bits (0 to 7)
220
* @param dst the destination buffer
221
*/
222
void sph_hamsi256_addbits_and_close(
223
void *cc, unsigned ub, unsigned n, void *dst);
224
225
/**
226
* Initialize a Hamsi-384 context. This process performs no memory allocation.
227
*
228
* @param cc the Hamsi-384 context (pointer to a
229
* <code>sph_hamsi384_context</code>)
230
*/
231
void sph_hamsi384_init(void *cc);
232
233
/**
234
* Process some data bytes. It is acceptable that <code>len</code> is zero
235
* (in which case this function does nothing).
236
*
237
* @param cc the Hamsi-384 context
238
* @param data the input data
239
* @param len the input data length (in bytes)
240
*/
241
void sph_hamsi384(void *cc, const void *data, size_t len);
242
243
/**
244
* Terminate the current Hamsi-384 computation and output the result into
245
* the provided buffer. The destination buffer must be wide enough to
246
* accomodate the result (48 bytes). The context is automatically
247
* reinitialized.
248
*
249
* @param cc the Hamsi-384 context
250
* @param dst the destination buffer
251
*/
252
void sph_hamsi384_close(void *cc, void *dst);
253
254
/**
255
* Add a few additional bits (0 to 7) to the current computation, then
256
* terminate it and output the result in the provided buffer, which must
257
* be wide enough to accomodate the result (48 bytes). If bit number i
258
* in <code>ub</code> has value 2^i, then the extra bits are those
259
* numbered 7 downto 8-n (this is the big-endian convention at the byte
260
* level). The context is automatically reinitialized.
261
*
262
* @param cc the Hamsi-384 context
263
* @param ub the extra bits
264
* @param n the number of extra bits (0 to 7)
265
* @param dst the destination buffer
266
*/
267
void sph_hamsi384_addbits_and_close(
268
void *cc, unsigned ub, unsigned n, void *dst);
269
270
/**
271
* Initialize a Hamsi-512 context. This process performs no memory allocation.
272
*
273
* @param cc the Hamsi-512 context (pointer to a
274
* <code>sph_hamsi512_context</code>)
275
*/
276
void sph_hamsi512_init(void *cc);
277
278
/**
279
* Process some data bytes. It is acceptable that <code>len</code> is zero
280
* (in which case this function does nothing).
281
*
282
* @param cc the Hamsi-512 context
283
* @param data the input data
284
* @param len the input data length (in bytes)
285
*/
286
void sph_hamsi512(void *cc, const void *data, size_t len);
287
288
/**
289
* Terminate the current Hamsi-512 computation and output the result into
290
* the provided buffer. The destination buffer must be wide enough to
291
* accomodate the result (64 bytes). The context is automatically
292
* reinitialized.
293
*
294
* @param cc the Hamsi-512 context
295
* @param dst the destination buffer
296
*/
297
void sph_hamsi512_close(void *cc, void *dst);
298
299
/**
300
* Add a few additional bits (0 to 7) to the current computation, then
301
* terminate it and output the result in the provided buffer, which must
302
* be wide enough to accomodate the result (64 bytes). If bit number i
303
* in <code>ub</code> has value 2^i, then the extra bits are those
304
* numbered 7 downto 8-n (this is the big-endian convention at the byte
305
* level). The context is automatically reinitialized.
306
*
307
* @param cc the Hamsi-512 context
308
* @param ub the extra bits
309
* @param n the number of extra bits (0 to 7)
310
* @param dst the destination buffer
311
*/
312
void sph_hamsi512_addbits_and_close(
313
void *cc, unsigned ub, unsigned n, void *dst);
314
315
316
317
#ifdef __cplusplus
318
}
319
#endif
320
321
#endif
322