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