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