Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/sha3/sph_cubehash.h
1201 views
1
/* $Id: sph_cubehash.h 180 2010-05-08 02:29:25Z tp $ */
2
/**
3
* CubeHash interface. CubeHash is a family of functions which differ by
4
* their output size; this implementation defines CubeHash for output
5
* sizes 224, 256, 384 and 512 bits, with the "standard parameters"
6
* (CubeHash16/32 with the CubeHash specification notations).
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_cubehash.h
34
* @author Thomas Pornin <[email protected]>
35
*/
36
37
#ifndef SPH_CUBEHASH_H__
38
#define SPH_CUBEHASH_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 CubeHash-224.
49
*/
50
#define SPH_SIZE_cubehash224 224
51
52
/**
53
* Output size (in bits) for CubeHash-256.
54
*/
55
#define SPH_SIZE_cubehash256 256
56
57
/**
58
* Output size (in bits) for CubeHash-384.
59
*/
60
#define SPH_SIZE_cubehash384 384
61
62
/**
63
* Output size (in bits) for CubeHash-512.
64
*/
65
#define SPH_SIZE_cubehash512 512
66
67
/**
68
* This structure is a context for CubeHash computations: it contains the
69
* intermediate values and some data from the last entered block. Once
70
* a CubeHash computation has been performed, the context can be reused for
71
* another computation.
72
*
73
* The contents of this structure are private. A running CubeHash computation
74
* can be cloned by copying the context (e.g. with a simple
75
* <code>memcpy()</code>).
76
*/
77
typedef struct {
78
#ifndef DOXYGEN_IGNORE
79
unsigned char buf[32]; /* first field, for alignment */
80
size_t ptr;
81
sph_u32 state[32];
82
#endif
83
} sph_cubehash_context;
84
85
/**
86
* Type for a CubeHash-224 context (identical to the common context).
87
*/
88
typedef sph_cubehash_context sph_cubehash224_context;
89
90
/**
91
* Type for a CubeHash-256 context (identical to the common context).
92
*/
93
typedef sph_cubehash_context sph_cubehash256_context;
94
95
/**
96
* Type for a CubeHash-384 context (identical to the common context).
97
*/
98
typedef sph_cubehash_context sph_cubehash384_context;
99
100
/**
101
* Type for a CubeHash-512 context (identical to the common context).
102
*/
103
typedef sph_cubehash_context sph_cubehash512_context;
104
105
/**
106
* Initialize a CubeHash-224 context. This process performs no memory
107
* allocation.
108
*
109
* @param cc the CubeHash-224 context (pointer to a
110
* <code>sph_cubehash224_context</code>)
111
*/
112
void sph_cubehash224_init(void *cc);
113
114
/**
115
* Process some data bytes. It is acceptable that <code>len</code> is zero
116
* (in which case this function does nothing).
117
*
118
* @param cc the CubeHash-224 context
119
* @param data the input data
120
* @param len the input data length (in bytes)
121
*/
122
void sph_cubehash224(void *cc, const void *data, size_t len);
123
124
/**
125
* Terminate the current CubeHash-224 computation and output the result into
126
* the provided buffer. The destination buffer must be wide enough to
127
* accomodate the result (28 bytes). The context is automatically
128
* reinitialized.
129
*
130
* @param cc the CubeHash-224 context
131
* @param dst the destination buffer
132
*/
133
void sph_cubehash224_close(void *cc, void *dst);
134
135
/**
136
* Add a few additional bits (0 to 7) to the current computation, then
137
* terminate it and output the result in the provided buffer, which must
138
* be wide enough to accomodate the result (28 bytes). If bit number i
139
* in <code>ub</code> has value 2^i, then the extra bits are those
140
* numbered 7 downto 8-n (this is the big-endian convention at the byte
141
* level). The context is automatically reinitialized.
142
*
143
* @param cc the CubeHash-224 context
144
* @param ub the extra bits
145
* @param n the number of extra bits (0 to 7)
146
* @param dst the destination buffer
147
*/
148
void sph_cubehash224_addbits_and_close(
149
void *cc, unsigned ub, unsigned n, void *dst);
150
151
/**
152
* Initialize a CubeHash-256 context. This process performs no memory
153
* allocation.
154
*
155
* @param cc the CubeHash-256 context (pointer to a
156
* <code>sph_cubehash256_context</code>)
157
*/
158
void sph_cubehash256_init(void *cc);
159
160
/**
161
* Process some data bytes. It is acceptable that <code>len</code> is zero
162
* (in which case this function does nothing).
163
*
164
* @param cc the CubeHash-256 context
165
* @param data the input data
166
* @param len the input data length (in bytes)
167
*/
168
void sph_cubehash256(void *cc, const void *data, size_t len);
169
170
/**
171
* Terminate the current CubeHash-256 computation and output the result into
172
* the provided buffer. The destination buffer must be wide enough to
173
* accomodate the result (32 bytes). The context is automatically
174
* reinitialized.
175
*
176
* @param cc the CubeHash-256 context
177
* @param dst the destination buffer
178
*/
179
void sph_cubehash256_close(void *cc, void *dst);
180
181
/**
182
* Add a few additional bits (0 to 7) to the current computation, then
183
* terminate it and output the result in the provided buffer, which must
184
* be wide enough to accomodate the result (32 bytes). If bit number i
185
* in <code>ub</code> has value 2^i, then the extra bits are those
186
* numbered 7 downto 8-n (this is the big-endian convention at the byte
187
* level). The context is automatically reinitialized.
188
*
189
* @param cc the CubeHash-256 context
190
* @param ub the extra bits
191
* @param n the number of extra bits (0 to 7)
192
* @param dst the destination buffer
193
*/
194
void sph_cubehash256_addbits_and_close(
195
void *cc, unsigned ub, unsigned n, void *dst);
196
197
/**
198
* Initialize a CubeHash-384 context. This process performs no memory
199
* allocation.
200
*
201
* @param cc the CubeHash-384 context (pointer to a
202
* <code>sph_cubehash384_context</code>)
203
*/
204
void sph_cubehash384_init(void *cc);
205
206
/**
207
* Process some data bytes. It is acceptable that <code>len</code> is zero
208
* (in which case this function does nothing).
209
*
210
* @param cc the CubeHash-384 context
211
* @param data the input data
212
* @param len the input data length (in bytes)
213
*/
214
void sph_cubehash384(void *cc, const void *data, size_t len);
215
216
/**
217
* Terminate the current CubeHash-384 computation and output the result into
218
* the provided buffer. The destination buffer must be wide enough to
219
* accomodate the result (48 bytes). The context is automatically
220
* reinitialized.
221
*
222
* @param cc the CubeHash-384 context
223
* @param dst the destination buffer
224
*/
225
void sph_cubehash384_close(void *cc, void *dst);
226
227
/**
228
* Add a few additional bits (0 to 7) to the current computation, then
229
* terminate it and output the result in the provided buffer, which must
230
* be wide enough to accomodate the result (48 bytes). If bit number i
231
* in <code>ub</code> has value 2^i, then the extra bits are those
232
* numbered 7 downto 8-n (this is the big-endian convention at the byte
233
* level). The context is automatically reinitialized.
234
*
235
* @param cc the CubeHash-384 context
236
* @param ub the extra bits
237
* @param n the number of extra bits (0 to 7)
238
* @param dst the destination buffer
239
*/
240
void sph_cubehash384_addbits_and_close(
241
void *cc, unsigned ub, unsigned n, void *dst);
242
243
/**
244
* Initialize a CubeHash-512 context. This process performs no memory
245
* allocation.
246
*
247
* @param cc the CubeHash-512 context (pointer to a
248
* <code>sph_cubehash512_context</code>)
249
*/
250
void sph_cubehash512_init(void *cc);
251
252
/**
253
* Process some data bytes. It is acceptable that <code>len</code> is zero
254
* (in which case this function does nothing).
255
*
256
* @param cc the CubeHash-512 context
257
* @param data the input data
258
* @param len the input data length (in bytes)
259
*/
260
void sph_cubehash512(void *cc, const void *data, size_t len);
261
262
/**
263
* Terminate the current CubeHash-512 computation and output the result into
264
* the provided buffer. The destination buffer must be wide enough to
265
* accomodate the result (64 bytes). The context is automatically
266
* reinitialized.
267
*
268
* @param cc the CubeHash-512 context
269
* @param dst the destination buffer
270
*/
271
void sph_cubehash512_close(void *cc, void *dst);
272
273
/**
274
* Add a few additional bits (0 to 7) to the current computation, then
275
* terminate it and output the result in the provided buffer, which must
276
* be wide enough to accomodate the result (64 bytes). If bit number i
277
* in <code>ub</code> has value 2^i, then the extra bits are those
278
* numbered 7 downto 8-n (this is the big-endian convention at the byte
279
* level). The context is automatically reinitialized.
280
*
281
* @param cc the CubeHash-512 context
282
* @param ub the extra bits
283
* @param n the number of extra bits (0 to 7)
284
* @param dst the destination buffer
285
*/
286
void sph_cubehash512_addbits_and_close(
287
void *cc, unsigned ub, unsigned n, void *dst);
288
#ifdef __cplusplus
289
}
290
#endif
291
292
#endif
293
294