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