Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

bmw.c
Go to the documentation of this file.
1 /* $Id: bmw.c 227 2010-06-16 17:28:38Z tp $ */
2 /*
3  * BMW implementation.
4  *
5  * ==========================(LICENSE BEGIN)============================
6  *
7  * Copyright (c) 2007-2010 Projet RNRT SAPHIR
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * ===========================(LICENSE END)=============================
29  *
30  * @author Thomas Pornin <thomas.pornin@cryptolog.com>
31  */
32 
33 #include <stddef.h>
34 #include <string.h>
35 #include <limits.h>
36 
37 #ifdef __cplusplus
38 extern "C"{
39 #endif
40 
41 #include "sph_bmw.h"
42 
43 #if SPH_SMALL_FOOTPRINT && !defined SPH_SMALL_FOOTPRINT_BMW
44 #define SPH_SMALL_FOOTPRINT_BMW 1
45 #endif
46 
47 #ifdef _MSC_VER
48 #pragma warning (disable: 4146)
49 #endif
50 
51 static const sph_u32 IV224[] = {
52  SPH_C32(0x00010203), SPH_C32(0x04050607),
53  SPH_C32(0x08090A0B), SPH_C32(0x0C0D0E0F),
54  SPH_C32(0x10111213), SPH_C32(0x14151617),
55  SPH_C32(0x18191A1B), SPH_C32(0x1C1D1E1F),
56  SPH_C32(0x20212223), SPH_C32(0x24252627),
57  SPH_C32(0x28292A2B), SPH_C32(0x2C2D2E2F),
58  SPH_C32(0x30313233), SPH_C32(0x34353637),
59  SPH_C32(0x38393A3B), SPH_C32(0x3C3D3E3F)
60 };
61 
62 static const sph_u32 IV256[] = {
63  SPH_C32(0x40414243), SPH_C32(0x44454647),
64  SPH_C32(0x48494A4B), SPH_C32(0x4C4D4E4F),
65  SPH_C32(0x50515253), SPH_C32(0x54555657),
66  SPH_C32(0x58595A5B), SPH_C32(0x5C5D5E5F),
67  SPH_C32(0x60616263), SPH_C32(0x64656667),
68  SPH_C32(0x68696A6B), SPH_C32(0x6C6D6E6F),
69  SPH_C32(0x70717273), SPH_C32(0x74757677),
70  SPH_C32(0x78797A7B), SPH_C32(0x7C7D7E7F)
71 };
72 
73 #if SPH_64
74 
75 static const sph_u64 IV384[] = {
76  SPH_C64(0x0001020304050607), SPH_C64(0x08090A0B0C0D0E0F),
77  SPH_C64(0x1011121314151617), SPH_C64(0x18191A1B1C1D1E1F),
78  SPH_C64(0x2021222324252627), SPH_C64(0x28292A2B2C2D2E2F),
79  SPH_C64(0x3031323334353637), SPH_C64(0x38393A3B3C3D3E3F),
80  SPH_C64(0x4041424344454647), SPH_C64(0x48494A4B4C4D4E4F),
81  SPH_C64(0x5051525354555657), SPH_C64(0x58595A5B5C5D5E5F),
82  SPH_C64(0x6061626364656667), SPH_C64(0x68696A6B6C6D6E6F),
83  SPH_C64(0x7071727374757677), SPH_C64(0x78797A7B7C7D7E7F)
84 };
85 
86 static const sph_u64 IV512[] = {
87  SPH_C64(0x8081828384858687), SPH_C64(0x88898A8B8C8D8E8F),
88  SPH_C64(0x9091929394959697), SPH_C64(0x98999A9B9C9D9E9F),
89  SPH_C64(0xA0A1A2A3A4A5A6A7), SPH_C64(0xA8A9AAABACADAEAF),
90  SPH_C64(0xB0B1B2B3B4B5B6B7), SPH_C64(0xB8B9BABBBCBDBEBF),
91  SPH_C64(0xC0C1C2C3C4C5C6C7), SPH_C64(0xC8C9CACBCCCDCECF),
92  SPH_C64(0xD0D1D2D3D4D5D6D7), SPH_C64(0xD8D9DADBDCDDDEDF),
93  SPH_C64(0xE0E1E2E3E4E5E6E7), SPH_C64(0xE8E9EAEBECEDEEEF),
94  SPH_C64(0xF0F1F2F3F4F5F6F7), SPH_C64(0xF8F9FAFBFCFDFEFF)
95 };
96 
97 #endif
98 
99 #define XCAT(x, y) XCAT_(x, y)
100 #define XCAT_(x, y) x ## y
101 
102 #define LPAR (
103 
104 #define I16_16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
105 #define I16_17 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
106 #define I16_18 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
107 #define I16_19 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
108 #define I16_20 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
109 #define I16_21 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
110 #define I16_22 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
111 #define I16_23 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
112 #define I16_24 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
113 #define I16_25 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
114 #define I16_26 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
115 #define I16_27 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
116 #define I16_28 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
117 #define I16_29 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
118 #define I16_30 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
119 #define I16_31 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
120 
121 #define M16_16 0, 1, 3, 4, 7, 10, 11
122 #define M16_17 1, 2, 4, 5, 8, 11, 12
123 #define M16_18 2, 3, 5, 6, 9, 12, 13
124 #define M16_19 3, 4, 6, 7, 10, 13, 14
125 #define M16_20 4, 5, 7, 8, 11, 14, 15
126 #define M16_21 5, 6, 8, 9, 12, 15, 16
127 #define M16_22 6, 7, 9, 10, 13, 0, 1
128 #define M16_23 7, 8, 10, 11, 14, 1, 2
129 #define M16_24 8, 9, 11, 12, 15, 2, 3
130 #define M16_25 9, 10, 12, 13, 0, 3, 4
131 #define M16_26 10, 11, 13, 14, 1, 4, 5
132 #define M16_27 11, 12, 14, 15, 2, 5, 6
133 #define M16_28 12, 13, 15, 16, 3, 6, 7
134 #define M16_29 13, 14, 0, 1, 4, 7, 8
135 #define M16_30 14, 15, 1, 2, 5, 8, 9
136 #define M16_31 15, 16, 2, 3, 6, 9, 10
137 
138 #define ss0(x) (((x) >> 1) ^ SPH_T32((x) << 3) \
139  ^ SPH_ROTL32(x, 4) ^ SPH_ROTL32(x, 19))
140 #define ss1(x) (((x) >> 1) ^ SPH_T32((x) << 2) \
141  ^ SPH_ROTL32(x, 8) ^ SPH_ROTL32(x, 23))
142 #define ss2(x) (((x) >> 2) ^ SPH_T32((x) << 1) \
143  ^ SPH_ROTL32(x, 12) ^ SPH_ROTL32(x, 25))
144 #define ss3(x) (((x) >> 2) ^ SPH_T32((x) << 2) \
145  ^ SPH_ROTL32(x, 15) ^ SPH_ROTL32(x, 29))
146 #define ss4(x) (((x) >> 1) ^ (x))
147 #define ss5(x) (((x) >> 2) ^ (x))
148 #define rs1(x) SPH_ROTL32(x, 3)
149 #define rs2(x) SPH_ROTL32(x, 7)
150 #define rs3(x) SPH_ROTL32(x, 13)
151 #define rs4(x) SPH_ROTL32(x, 16)
152 #define rs5(x) SPH_ROTL32(x, 19)
153 #define rs6(x) SPH_ROTL32(x, 23)
154 #define rs7(x) SPH_ROTL32(x, 27)
155 
156 #define Ks(j) SPH_T32((sph_u32)(j) * SPH_C32(0x05555555))
157 
158 #define add_elt_s(mf, hf, j0m, j1m, j3m, j4m, j7m, j10m, j11m, j16) \
159  (SPH_T32(SPH_ROTL32(mf(j0m), j1m) + SPH_ROTL32(mf(j3m), j4m) \
160  - SPH_ROTL32(mf(j10m), j11m) + Ks(j16)) ^ hf(j7m))
161 
162 #define expand1s_inner(qf, mf, hf, i16, \
163  i0, i1, i2, i3, i4, i5, i6, i7, i8, \
164  i9, i10, i11, i12, i13, i14, i15, \
165  i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
166  SPH_T32(ss1(qf(i0)) + ss2(qf(i1)) + ss3(qf(i2)) + ss0(qf(i3)) \
167  + ss1(qf(i4)) + ss2(qf(i5)) + ss3(qf(i6)) + ss0(qf(i7)) \
168  + ss1(qf(i8)) + ss2(qf(i9)) + ss3(qf(i10)) + ss0(qf(i11)) \
169  + ss1(qf(i12)) + ss2(qf(i13)) + ss3(qf(i14)) + ss0(qf(i15)) \
170  + add_elt_s(mf, hf, i0m, i1m, i3m, i4m, i7m, i10m, i11m, i16))
171 
172 #define expand1s(qf, mf, hf, i16) \
173  expand1s_(qf, mf, hf, i16, I16_ ## i16, M16_ ## i16)
174 #define expand1s_(qf, mf, hf, i16, ix, iy) \
175  expand1s_inner LPAR qf, mf, hf, i16, ix, iy)
176 
177 #define expand2s_inner(qf, mf, hf, i16, \
178  i0, i1, i2, i3, i4, i5, i6, i7, i8, \
179  i9, i10, i11, i12, i13, i14, i15, \
180  i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
181  SPH_T32(qf(i0) + rs1(qf(i1)) + qf(i2) + rs2(qf(i3)) \
182  + qf(i4) + rs3(qf(i5)) + qf(i6) + rs4(qf(i7)) \
183  + qf(i8) + rs5(qf(i9)) + qf(i10) + rs6(qf(i11)) \
184  + qf(i12) + rs7(qf(i13)) + ss4(qf(i14)) + ss5(qf(i15)) \
185  + add_elt_s(mf, hf, i0m, i1m, i3m, i4m, i7m, i10m, i11m, i16))
186 
187 #define expand2s(qf, mf, hf, i16) \
188  expand2s_(qf, mf, hf, i16, I16_ ## i16, M16_ ## i16)
189 #define expand2s_(qf, mf, hf, i16, ix, iy) \
190  expand2s_inner LPAR qf, mf, hf, i16, ix, iy)
191 
192 #if SPH_64
193 
194 #define sb0(x) (((x) >> 1) ^ SPH_T64((x) << 3) \
195  ^ SPH_ROTL64(x, 4) ^ SPH_ROTL64(x, 37))
196 #define sb1(x) (((x) >> 1) ^ SPH_T64((x) << 2) \
197  ^ SPH_ROTL64(x, 13) ^ SPH_ROTL64(x, 43))
198 #define sb2(x) (((x) >> 2) ^ SPH_T64((x) << 1) \
199  ^ SPH_ROTL64(x, 19) ^ SPH_ROTL64(x, 53))
200 #define sb3(x) (((x) >> 2) ^ SPH_T64((x) << 2) \
201  ^ SPH_ROTL64(x, 28) ^ SPH_ROTL64(x, 59))
202 #define sb4(x) (((x) >> 1) ^ (x))
203 #define sb5(x) (((x) >> 2) ^ (x))
204 #define rb1(x) SPH_ROTL64(x, 5)
205 #define rb2(x) SPH_ROTL64(x, 11)
206 #define rb3(x) SPH_ROTL64(x, 27)
207 #define rb4(x) SPH_ROTL64(x, 32)
208 #define rb5(x) SPH_ROTL64(x, 37)
209 #define rb6(x) SPH_ROTL64(x, 43)
210 #define rb7(x) SPH_ROTL64(x, 53)
211 
212 #define Kb(j) SPH_T64((sph_u64)(j) * SPH_C64(0x0555555555555555))
213 
214 #if SPH_SMALL_FOOTPRINT_BMW
215 
216 static const sph_u64 Kb_tab[] = {
217  Kb(16), Kb(17), Kb(18), Kb(19), Kb(20), Kb(21), Kb(22), Kb(23),
218  Kb(24), Kb(25), Kb(26), Kb(27), Kb(28), Kb(29), Kb(30), Kb(31)
219 };
220 
221 #define rol_off(mf, j, off) \
222  SPH_ROTL64(mf(((j) + (off)) & 15), (((j) + (off)) & 15) + 1)
223 
224 #define add_elt_b(mf, hf, j) \
225  (SPH_T64(rol_off(mf, j, 0) + rol_off(mf, j, 3) \
226  - rol_off(mf, j, 10) + Kb_tab[j]) ^ hf(((j) + 7) & 15))
227 
228 #define expand1b(qf, mf, hf, i) \
229  SPH_T64(sb1(qf((i) - 16)) + sb2(qf((i) - 15)) \
230  + sb3(qf((i) - 14)) + sb0(qf((i) - 13)) \
231  + sb1(qf((i) - 12)) + sb2(qf((i) - 11)) \
232  + sb3(qf((i) - 10)) + sb0(qf((i) - 9)) \
233  + sb1(qf((i) - 8)) + sb2(qf((i) - 7)) \
234  + sb3(qf((i) - 6)) + sb0(qf((i) - 5)) \
235  + sb1(qf((i) - 4)) + sb2(qf((i) - 3)) \
236  + sb3(qf((i) - 2)) + sb0(qf((i) - 1)) \
237  + add_elt_b(mf, hf, (i) - 16))
238 
239 #define expand2b(qf, mf, hf, i) \
240  SPH_T64(qf((i) - 16) + rb1(qf((i) - 15)) \
241  + qf((i) - 14) + rb2(qf((i) - 13)) \
242  + qf((i) - 12) + rb3(qf((i) - 11)) \
243  + qf((i) - 10) + rb4(qf((i) - 9)) \
244  + qf((i) - 8) + rb5(qf((i) - 7)) \
245  + qf((i) - 6) + rb6(qf((i) - 5)) \
246  + qf((i) - 4) + rb7(qf((i) - 3)) \
247  + sb4(qf((i) - 2)) + sb5(qf((i) - 1)) \
248  + add_elt_b(mf, hf, (i) - 16))
249 
250 #else
251 
252 #define add_elt_b(mf, hf, j0m, j1m, j3m, j4m, j7m, j10m, j11m, j16) \
253  (SPH_T64(SPH_ROTL64(mf(j0m), j1m) + SPH_ROTL64(mf(j3m), j4m) \
254  - SPH_ROTL64(mf(j10m), j11m) + Kb(j16)) ^ hf(j7m))
255 
256 #define expand1b_inner(qf, mf, hf, i16, \
257  i0, i1, i2, i3, i4, i5, i6, i7, i8, \
258  i9, i10, i11, i12, i13, i14, i15, \
259  i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
260  SPH_T64(sb1(qf(i0)) + sb2(qf(i1)) + sb3(qf(i2)) + sb0(qf(i3)) \
261  + sb1(qf(i4)) + sb2(qf(i5)) + sb3(qf(i6)) + sb0(qf(i7)) \
262  + sb1(qf(i8)) + sb2(qf(i9)) + sb3(qf(i10)) + sb0(qf(i11)) \
263  + sb1(qf(i12)) + sb2(qf(i13)) + sb3(qf(i14)) + sb0(qf(i15)) \
264  + add_elt_b(mf, hf, i0m, i1m, i3m, i4m, i7m, i10m, i11m, i16))
265 
266 #define expand1b(qf, mf, hf, i16) \
267  expand1b_(qf, mf, hf, i16, I16_ ## i16, M16_ ## i16)
268 #define expand1b_(qf, mf, hf, i16, ix, iy) \
269  expand1b_inner LPAR qf, mf, hf, i16, ix, iy)
270 
271 #define expand2b_inner(qf, mf, hf, i16, \
272  i0, i1, i2, i3, i4, i5, i6, i7, i8, \
273  i9, i10, i11, i12, i13, i14, i15, \
274  i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
275  SPH_T64(qf(i0) + rb1(qf(i1)) + qf(i2) + rb2(qf(i3)) \
276  + qf(i4) + rb3(qf(i5)) + qf(i6) + rb4(qf(i7)) \
277  + qf(i8) + rb5(qf(i9)) + qf(i10) + rb6(qf(i11)) \
278  + qf(i12) + rb7(qf(i13)) + sb4(qf(i14)) + sb5(qf(i15)) \
279  + add_elt_b(mf, hf, i0m, i1m, i3m, i4m, i7m, i10m, i11m, i16))
280 
281 #define expand2b(qf, mf, hf, i16) \
282  expand2b_(qf, mf, hf, i16, I16_ ## i16, M16_ ## i16)
283 #define expand2b_(qf, mf, hf, i16, ix, iy) \
284  expand2b_inner LPAR qf, mf, hf, i16, ix, iy)
285 
286 #endif
287 
288 #endif
289 
290 #define MAKE_W(tt, i0, op01, i1, op12, i2, op23, i3, op34, i4) \
291  tt((M(i0) ^ H(i0)) op01 (M(i1) ^ H(i1)) op12 (M(i2) ^ H(i2)) \
292  op23 (M(i3) ^ H(i3)) op34 (M(i4) ^ H(i4)))
293 
294 #define Ws0 MAKE_W(SPH_T32, 5, -, 7, +, 10, +, 13, +, 14)
295 #define Ws1 MAKE_W(SPH_T32, 6, -, 8, +, 11, +, 14, -, 15)
296 #define Ws2 MAKE_W(SPH_T32, 0, +, 7, +, 9, -, 12, +, 15)
297 #define Ws3 MAKE_W(SPH_T32, 0, -, 1, +, 8, -, 10, +, 13)
298 #define Ws4 MAKE_W(SPH_T32, 1, +, 2, +, 9, -, 11, -, 14)
299 #define Ws5 MAKE_W(SPH_T32, 3, -, 2, +, 10, -, 12, +, 15)
300 #define Ws6 MAKE_W(SPH_T32, 4, -, 0, -, 3, -, 11, +, 13)
301 #define Ws7 MAKE_W(SPH_T32, 1, -, 4, -, 5, -, 12, -, 14)
302 #define Ws8 MAKE_W(SPH_T32, 2, -, 5, -, 6, +, 13, -, 15)
303 #define Ws9 MAKE_W(SPH_T32, 0, -, 3, +, 6, -, 7, +, 14)
304 #define Ws10 MAKE_W(SPH_T32, 8, -, 1, -, 4, -, 7, +, 15)
305 #define Ws11 MAKE_W(SPH_T32, 8, -, 0, -, 2, -, 5, +, 9)
306 #define Ws12 MAKE_W(SPH_T32, 1, +, 3, -, 6, -, 9, +, 10)
307 #define Ws13 MAKE_W(SPH_T32, 2, +, 4, +, 7, +, 10, +, 11)
308 #define Ws14 MAKE_W(SPH_T32, 3, -, 5, +, 8, -, 11, -, 12)
309 #define Ws15 MAKE_W(SPH_T32, 12, -, 4, -, 6, -, 9, +, 13)
310 
311 #if SPH_SMALL_FOOTPRINT_BMW
312 
313 #define MAKE_Qas do { \
314  unsigned u; \
315  sph_u32 Ws[16]; \
316  Ws[ 0] = Ws0; \
317  Ws[ 1] = Ws1; \
318  Ws[ 2] = Ws2; \
319  Ws[ 3] = Ws3; \
320  Ws[ 4] = Ws4; \
321  Ws[ 5] = Ws5; \
322  Ws[ 6] = Ws6; \
323  Ws[ 7] = Ws7; \
324  Ws[ 8] = Ws8; \
325  Ws[ 9] = Ws9; \
326  Ws[10] = Ws10; \
327  Ws[11] = Ws11; \
328  Ws[12] = Ws12; \
329  Ws[13] = Ws13; \
330  Ws[14] = Ws14; \
331  Ws[15] = Ws15; \
332  for (u = 0; u < 15; u += 5) { \
333  qt[u + 0] = SPH_T32(ss0(Ws[u + 0]) + H(u + 1)); \
334  qt[u + 1] = SPH_T32(ss1(Ws[u + 1]) + H(u + 2)); \
335  qt[u + 2] = SPH_T32(ss2(Ws[u + 2]) + H(u + 3)); \
336  qt[u + 3] = SPH_T32(ss3(Ws[u + 3]) + H(u + 4)); \
337  qt[u + 4] = SPH_T32(ss4(Ws[u + 4]) + H(u + 5)); \
338  } \
339  qt[15] = SPH_T32(ss0(Ws[15]) + H(0)); \
340  } while (0)
341 
342 #define MAKE_Qbs do { \
343  qt[16] = expand1s(Qs, M, H, 16); \
344  qt[17] = expand1s(Qs, M, H, 17); \
345  qt[18] = expand2s(Qs, M, H, 18); \
346  qt[19] = expand2s(Qs, M, H, 19); \
347  qt[20] = expand2s(Qs, M, H, 20); \
348  qt[21] = expand2s(Qs, M, H, 21); \
349  qt[22] = expand2s(Qs, M, H, 22); \
350  qt[23] = expand2s(Qs, M, H, 23); \
351  qt[24] = expand2s(Qs, M, H, 24); \
352  qt[25] = expand2s(Qs, M, H, 25); \
353  qt[26] = expand2s(Qs, M, H, 26); \
354  qt[27] = expand2s(Qs, M, H, 27); \
355  qt[28] = expand2s(Qs, M, H, 28); \
356  qt[29] = expand2s(Qs, M, H, 29); \
357  qt[30] = expand2s(Qs, M, H, 30); \
358  qt[31] = expand2s(Qs, M, H, 31); \
359  } while (0)
360 
361 #else
362 
363 #define MAKE_Qas do { \
364  qt[ 0] = SPH_T32(ss0(Ws0 ) + H( 1)); \
365  qt[ 1] = SPH_T32(ss1(Ws1 ) + H( 2)); \
366  qt[ 2] = SPH_T32(ss2(Ws2 ) + H( 3)); \
367  qt[ 3] = SPH_T32(ss3(Ws3 ) + H( 4)); \
368  qt[ 4] = SPH_T32(ss4(Ws4 ) + H( 5)); \
369  qt[ 5] = SPH_T32(ss0(Ws5 ) + H( 6)); \
370  qt[ 6] = SPH_T32(ss1(Ws6 ) + H( 7)); \
371  qt[ 7] = SPH_T32(ss2(Ws7 ) + H( 8)); \
372  qt[ 8] = SPH_T32(ss3(Ws8 ) + H( 9)); \
373  qt[ 9] = SPH_T32(ss4(Ws9 ) + H(10)); \
374  qt[10] = SPH_T32(ss0(Ws10) + H(11)); \
375  qt[11] = SPH_T32(ss1(Ws11) + H(12)); \
376  qt[12] = SPH_T32(ss2(Ws12) + H(13)); \
377  qt[13] = SPH_T32(ss3(Ws13) + H(14)); \
378  qt[14] = SPH_T32(ss4(Ws14) + H(15)); \
379  qt[15] = SPH_T32(ss0(Ws15) + H( 0)); \
380  } while (0)
381 
382 #define MAKE_Qbs do { \
383  qt[16] = expand1s(Qs, M, H, 16); \
384  qt[17] = expand1s(Qs, M, H, 17); \
385  qt[18] = expand2s(Qs, M, H, 18); \
386  qt[19] = expand2s(Qs, M, H, 19); \
387  qt[20] = expand2s(Qs, M, H, 20); \
388  qt[21] = expand2s(Qs, M, H, 21); \
389  qt[22] = expand2s(Qs, M, H, 22); \
390  qt[23] = expand2s(Qs, M, H, 23); \
391  qt[24] = expand2s(Qs, M, H, 24); \
392  qt[25] = expand2s(Qs, M, H, 25); \
393  qt[26] = expand2s(Qs, M, H, 26); \
394  qt[27] = expand2s(Qs, M, H, 27); \
395  qt[28] = expand2s(Qs, M, H, 28); \
396  qt[29] = expand2s(Qs, M, H, 29); \
397  qt[30] = expand2s(Qs, M, H, 30); \
398  qt[31] = expand2s(Qs, M, H, 31); \
399  } while (0)
400 
401 #endif
402 
403 #define MAKE_Qs do { \
404  MAKE_Qas; \
405  MAKE_Qbs; \
406  } while (0)
407 
408 #define Qs(j) (qt[j])
409 
410 #if SPH_64
411 
412 #define Wb0 MAKE_W(SPH_T64, 5, -, 7, +, 10, +, 13, +, 14)
413 #define Wb1 MAKE_W(SPH_T64, 6, -, 8, +, 11, +, 14, -, 15)
414 #define Wb2 MAKE_W(SPH_T64, 0, +, 7, +, 9, -, 12, +, 15)
415 #define Wb3 MAKE_W(SPH_T64, 0, -, 1, +, 8, -, 10, +, 13)
416 #define Wb4 MAKE_W(SPH_T64, 1, +, 2, +, 9, -, 11, -, 14)
417 #define Wb5 MAKE_W(SPH_T64, 3, -, 2, +, 10, -, 12, +, 15)
418 #define Wb6 MAKE_W(SPH_T64, 4, -, 0, -, 3, -, 11, +, 13)
419 #define Wb7 MAKE_W(SPH_T64, 1, -, 4, -, 5, -, 12, -, 14)
420 #define Wb8 MAKE_W(SPH_T64, 2, -, 5, -, 6, +, 13, -, 15)
421 #define Wb9 MAKE_W(SPH_T64, 0, -, 3, +, 6, -, 7, +, 14)
422 #define Wb10 MAKE_W(SPH_T64, 8, -, 1, -, 4, -, 7, +, 15)
423 #define Wb11 MAKE_W(SPH_T64, 8, -, 0, -, 2, -, 5, +, 9)
424 #define Wb12 MAKE_W(SPH_T64, 1, +, 3, -, 6, -, 9, +, 10)
425 #define Wb13 MAKE_W(SPH_T64, 2, +, 4, +, 7, +, 10, +, 11)
426 #define Wb14 MAKE_W(SPH_T64, 3, -, 5, +, 8, -, 11, -, 12)
427 #define Wb15 MAKE_W(SPH_T64, 12, -, 4, -, 6, -, 9, +, 13)
428 
429 #if SPH_SMALL_FOOTPRINT_BMW
430 
431 #define MAKE_Qab do { \
432  unsigned u; \
433  sph_u64 Wb[16]; \
434  Wb[ 0] = Wb0; \
435  Wb[ 1] = Wb1; \
436  Wb[ 2] = Wb2; \
437  Wb[ 3] = Wb3; \
438  Wb[ 4] = Wb4; \
439  Wb[ 5] = Wb5; \
440  Wb[ 6] = Wb6; \
441  Wb[ 7] = Wb7; \
442  Wb[ 8] = Wb8; \
443  Wb[ 9] = Wb9; \
444  Wb[10] = Wb10; \
445  Wb[11] = Wb11; \
446  Wb[12] = Wb12; \
447  Wb[13] = Wb13; \
448  Wb[14] = Wb14; \
449  Wb[15] = Wb15; \
450  for (u = 0; u < 15; u += 5) { \
451  qt[u + 0] = SPH_T64(sb0(Wb[u + 0]) + H(u + 1)); \
452  qt[u + 1] = SPH_T64(sb1(Wb[u + 1]) + H(u + 2)); \
453  qt[u + 2] = SPH_T64(sb2(Wb[u + 2]) + H(u + 3)); \
454  qt[u + 3] = SPH_T64(sb3(Wb[u + 3]) + H(u + 4)); \
455  qt[u + 4] = SPH_T64(sb4(Wb[u + 4]) + H(u + 5)); \
456  } \
457  qt[15] = SPH_T64(sb0(Wb[15]) + H(0)); \
458  } while (0)
459 
460 #define MAKE_Qbb do { \
461  unsigned u; \
462  for (u = 16; u < 18; u ++) \
463  qt[u] = expand1b(Qb, M, H, u); \
464  for (u = 18; u < 32; u ++) \
465  qt[u] = expand2b(Qb, M, H, u); \
466  } while (0)
467 
468 #else
469 
470 #define MAKE_Qab do { \
471  qt[ 0] = SPH_T64(sb0(Wb0 ) + H( 1)); \
472  qt[ 1] = SPH_T64(sb1(Wb1 ) + H( 2)); \
473  qt[ 2] = SPH_T64(sb2(Wb2 ) + H( 3)); \
474  qt[ 3] = SPH_T64(sb3(Wb3 ) + H( 4)); \
475  qt[ 4] = SPH_T64(sb4(Wb4 ) + H( 5)); \
476  qt[ 5] = SPH_T64(sb0(Wb5 ) + H( 6)); \
477  qt[ 6] = SPH_T64(sb1(Wb6 ) + H( 7)); \
478  qt[ 7] = SPH_T64(sb2(Wb7 ) + H( 8)); \
479  qt[ 8] = SPH_T64(sb3(Wb8 ) + H( 9)); \
480  qt[ 9] = SPH_T64(sb4(Wb9 ) + H(10)); \
481  qt[10] = SPH_T64(sb0(Wb10) + H(11)); \
482  qt[11] = SPH_T64(sb1(Wb11) + H(12)); \
483  qt[12] = SPH_T64(sb2(Wb12) + H(13)); \
484  qt[13] = SPH_T64(sb3(Wb13) + H(14)); \
485  qt[14] = SPH_T64(sb4(Wb14) + H(15)); \
486  qt[15] = SPH_T64(sb0(Wb15) + H( 0)); \
487  } while (0)
488 
489 #define MAKE_Qbb do { \
490  qt[16] = expand1b(Qb, M, H, 16); \
491  qt[17] = expand1b(Qb, M, H, 17); \
492  qt[18] = expand2b(Qb, M, H, 18); \
493  qt[19] = expand2b(Qb, M, H, 19); \
494  qt[20] = expand2b(Qb, M, H, 20); \
495  qt[21] = expand2b(Qb, M, H, 21); \
496  qt[22] = expand2b(Qb, M, H, 22); \
497  qt[23] = expand2b(Qb, M, H, 23); \
498  qt[24] = expand2b(Qb, M, H, 24); \
499  qt[25] = expand2b(Qb, M, H, 25); \
500  qt[26] = expand2b(Qb, M, H, 26); \
501  qt[27] = expand2b(Qb, M, H, 27); \
502  qt[28] = expand2b(Qb, M, H, 28); \
503  qt[29] = expand2b(Qb, M, H, 29); \
504  qt[30] = expand2b(Qb, M, H, 30); \
505  qt[31] = expand2b(Qb, M, H, 31); \
506  } while (0)
507 
508 #endif
509 
510 #define MAKE_Qb do { \
511  MAKE_Qab; \
512  MAKE_Qbb; \
513  } while (0)
514 
515 #define Qb(j) (qt[j])
516 
517 #endif
518 
519 #define FOLD(type, mkQ, tt, rol, mf, qf, dhf) do { \
520  type qt[32], xl, xh; \
521  mkQ; \
522  xl = qf(16) ^ qf(17) ^ qf(18) ^ qf(19) \
523  ^ qf(20) ^ qf(21) ^ qf(22) ^ qf(23); \
524  xh = xl ^ qf(24) ^ qf(25) ^ qf(26) ^ qf(27) \
525  ^ qf(28) ^ qf(29) ^ qf(30) ^ qf(31); \
526  dhf( 0) = tt(((xh << 5) ^ (qf(16) >> 5) ^ mf( 0)) \
527  + (xl ^ qf(24) ^ qf( 0))); \
528  dhf( 1) = tt(((xh >> 7) ^ (qf(17) << 8) ^ mf( 1)) \
529  + (xl ^ qf(25) ^ qf( 1))); \
530  dhf( 2) = tt(((xh >> 5) ^ (qf(18) << 5) ^ mf( 2)) \
531  + (xl ^ qf(26) ^ qf( 2))); \
532  dhf( 3) = tt(((xh >> 1) ^ (qf(19) << 5) ^ mf( 3)) \
533  + (xl ^ qf(27) ^ qf( 3))); \
534  dhf( 4) = tt(((xh >> 3) ^ (qf(20) << 0) ^ mf( 4)) \
535  + (xl ^ qf(28) ^ qf( 4))); \
536  dhf( 5) = tt(((xh << 6) ^ (qf(21) >> 6) ^ mf( 5)) \
537  + (xl ^ qf(29) ^ qf( 5))); \
538  dhf( 6) = tt(((xh >> 4) ^ (qf(22) << 6) ^ mf( 6)) \
539  + (xl ^ qf(30) ^ qf( 6))); \
540  dhf( 7) = tt(((xh >> 11) ^ (qf(23) << 2) ^ mf( 7)) \
541  + (xl ^ qf(31) ^ qf( 7))); \
542  dhf( 8) = tt(rol(dhf(4), 9) + (xh ^ qf(24) ^ mf( 8)) \
543  + ((xl << 8) ^ qf(23) ^ qf( 8))); \
544  dhf( 9) = tt(rol(dhf(5), 10) + (xh ^ qf(25) ^ mf( 9)) \
545  + ((xl >> 6) ^ qf(16) ^ qf( 9))); \
546  dhf(10) = tt(rol(dhf(6), 11) + (xh ^ qf(26) ^ mf(10)) \
547  + ((xl << 6) ^ qf(17) ^ qf(10))); \
548  dhf(11) = tt(rol(dhf(7), 12) + (xh ^ qf(27) ^ mf(11)) \
549  + ((xl << 4) ^ qf(18) ^ qf(11))); \
550  dhf(12) = tt(rol(dhf(0), 13) + (xh ^ qf(28) ^ mf(12)) \
551  + ((xl >> 3) ^ qf(19) ^ qf(12))); \
552  dhf(13) = tt(rol(dhf(1), 14) + (xh ^ qf(29) ^ mf(13)) \
553  + ((xl >> 4) ^ qf(20) ^ qf(13))); \
554  dhf(14) = tt(rol(dhf(2), 15) + (xh ^ qf(30) ^ mf(14)) \
555  + ((xl >> 7) ^ qf(21) ^ qf(14))); \
556  dhf(15) = tt(rol(dhf(3), 16) + (xh ^ qf(31) ^ mf(15)) \
557  + ((xl >> 2) ^ qf(22) ^ qf(15))); \
558  } while (0)
559 
560 #define FOLDs FOLD(sph_u32, MAKE_Qs, SPH_T32, SPH_ROTL32, M, Qs, dH)
561 
562 #if SPH_64
563 
564 #define FOLDb FOLD(sph_u64, MAKE_Qb, SPH_T64, SPH_ROTL64, M, Qb, dH)
565 
566 #endif
567 
568 static void
569 compress_small(const unsigned char *data, const sph_u32 h[16], sph_u32 dh[16])
570 {
571 #if SPH_LITTLE_FAST
572 #define M(x) sph_dec32le_aligned(data + 4 * (x))
573 #else
574  sph_u32 mv[16];
575 
576  mv[ 0] = sph_dec32le_aligned(data + 0);
577  mv[ 1] = sph_dec32le_aligned(data + 4);
578  mv[ 2] = sph_dec32le_aligned(data + 8);
579  mv[ 3] = sph_dec32le_aligned(data + 12);
580  mv[ 4] = sph_dec32le_aligned(data + 16);
581  mv[ 5] = sph_dec32le_aligned(data + 20);
582  mv[ 6] = sph_dec32le_aligned(data + 24);
583  mv[ 7] = sph_dec32le_aligned(data + 28);
584  mv[ 8] = sph_dec32le_aligned(data + 32);
585  mv[ 9] = sph_dec32le_aligned(data + 36);
586  mv[10] = sph_dec32le_aligned(data + 40);
587  mv[11] = sph_dec32le_aligned(data + 44);
588  mv[12] = sph_dec32le_aligned(data + 48);
589  mv[13] = sph_dec32le_aligned(data + 52);
590  mv[14] = sph_dec32le_aligned(data + 56);
591  mv[15] = sph_dec32le_aligned(data + 60);
592 #define M(x) (mv[x])
593 #endif
594 #define H(x) (h[x])
595 #define dH(x) (dh[x])
596 
597  FOLDs;
598 
599 #undef M
600 #undef H
601 #undef dH
602 }
603 
604 static const sph_u32 final_s[16] = {
605  SPH_C32(0xaaaaaaa0), SPH_C32(0xaaaaaaa1), SPH_C32(0xaaaaaaa2),
606  SPH_C32(0xaaaaaaa3), SPH_C32(0xaaaaaaa4), SPH_C32(0xaaaaaaa5),
607  SPH_C32(0xaaaaaaa6), SPH_C32(0xaaaaaaa7), SPH_C32(0xaaaaaaa8),
608  SPH_C32(0xaaaaaaa9), SPH_C32(0xaaaaaaaa), SPH_C32(0xaaaaaaab),
609  SPH_C32(0xaaaaaaac), SPH_C32(0xaaaaaaad), SPH_C32(0xaaaaaaae),
610  SPH_C32(0xaaaaaaaf)
611 };
612 
613 static void
615 {
616  memcpy(sc->H, iv, sizeof sc->H);
617  sc->ptr = 0;
618 #if SPH_64
619  sc->bit_count = 0;
620 #else
621  sc->bit_count_high = 0;
622  sc->bit_count_low = 0;
623 #endif
624 }
625 
626 static void
627 bmw32(sph_bmw_small_context *sc, const void *data, size_t len)
628 {
629  unsigned char *buf;
630  size_t ptr;
631  sph_u32 htmp[16];
632  sph_u32 *h1, *h2;
633 #if !SPH_64
634  sph_u32 tmp;
635 #endif
636 
637 #if SPH_64
638  sc->bit_count += (sph_u64)len << 3;
639 #else
640  tmp = sc->bit_count_low;
641  sc->bit_count_low = SPH_T32(tmp + ((sph_u32)len << 3));
642  if (sc->bit_count_low < tmp)
643  sc->bit_count_high ++;
644  sc->bit_count_high += len >> 29;
645 #endif
646  buf = sc->buf;
647  ptr = sc->ptr;
648  h1 = sc->H;
649  h2 = htmp;
650  while (len > 0) {
651  size_t clen;
652 
653  clen = (sizeof sc->buf) - ptr;
654  if (clen > len)
655  clen = len;
656  memcpy(buf + ptr, data, clen);
657  data = (const unsigned char *)data + clen;
658  len -= clen;
659  ptr += clen;
660  if (ptr == sizeof sc->buf) {
661  sph_u32 *ht;
662 
663  compress_small(buf, h1, h2);
664  ht = h1;
665  h1 = h2;
666  h2 = ht;
667  ptr = 0;
668  }
669  }
670  sc->ptr = ptr;
671  if (h1 != sc->H)
672  memcpy(sc->H, h1, sizeof sc->H);
673 }
674 
675 static void
676 bmw32_close(sph_bmw_small_context *sc, unsigned ub, unsigned n,
677  void *dst, size_t out_size_w32)
678 {
679  unsigned char *buf, *out;
680  size_t ptr, u, v;
681  unsigned z;
682  sph_u32 h1[16], h2[16], *h;
683 
684  buf = sc->buf;
685  ptr = sc->ptr;
686  z = 0x80 >> n;
687  buf[ptr ++] = ((ub & -z) | z) & 0xFF;
688  h = sc->H;
689  if (ptr > (sizeof sc->buf) - 8) {
690  memset(buf + ptr, 0, (sizeof sc->buf) - ptr);
691  compress_small(buf, h, h1);
692  ptr = 0;
693  h = h1;
694  }
695  memset(buf + ptr, 0, (sizeof sc->buf) - 8 - ptr);
696 #if SPH_64
697  sph_enc64le_aligned(buf + (sizeof sc->buf) - 8,
698  SPH_T64(sc->bit_count + n));
699 #else
700  sph_enc32le_aligned(buf + (sizeof sc->buf) - 8,
701  sc->bit_count_low + n);
702  sph_enc32le_aligned(buf + (sizeof sc->buf) - 4,
703  SPH_T32(sc->bit_count_high));
704 #endif
705  compress_small(buf, h, h2);
706  for (u = 0; u < 16; u ++)
707  sph_enc32le_aligned(buf + 4 * u, h2[u]);
708  compress_small(buf, final_s, h1);
709  out = dst;
710  for (u = 0, v = 16 - out_size_w32; u < out_size_w32; u ++, v ++)
711  sph_enc32le(out + 4 * u, h1[v]);
712 }
713 
714 #if SPH_64
715 
716 static void
717 compress_big(const unsigned char *data, const sph_u64 h[16], sph_u64 dh[16])
718 {
719 #if SPH_LITTLE_FAST
720 #define M(x) sph_dec64le_aligned(data + 8 * (x))
721 #else
722  sph_u64 mv[16];
723 
724  mv[ 0] = sph_dec64le_aligned(data + 0);
725  mv[ 1] = sph_dec64le_aligned(data + 8);
726  mv[ 2] = sph_dec64le_aligned(data + 16);
727  mv[ 3] = sph_dec64le_aligned(data + 24);
728  mv[ 4] = sph_dec64le_aligned(data + 32);
729  mv[ 5] = sph_dec64le_aligned(data + 40);
730  mv[ 6] = sph_dec64le_aligned(data + 48);
731  mv[ 7] = sph_dec64le_aligned(data + 56);
732  mv[ 8] = sph_dec64le_aligned(data + 64);
733  mv[ 9] = sph_dec64le_aligned(data + 72);
734  mv[10] = sph_dec64le_aligned(data + 80);
735  mv[11] = sph_dec64le_aligned(data + 88);
736  mv[12] = sph_dec64le_aligned(data + 96);
737  mv[13] = sph_dec64le_aligned(data + 104);
738  mv[14] = sph_dec64le_aligned(data + 112);
739  mv[15] = sph_dec64le_aligned(data + 120);
740 #define M(x) (mv[x])
741 #endif
742 #define H(x) (h[x])
743 #define dH(x) (dh[x])
744 
745  FOLDb;
746 
747 #undef M
748 #undef H
749 #undef dH
750 }
751 
752 static const sph_u64 final_b[16] = {
753  SPH_C64(0xaaaaaaaaaaaaaaa0), SPH_C64(0xaaaaaaaaaaaaaaa1),
754  SPH_C64(0xaaaaaaaaaaaaaaa2), SPH_C64(0xaaaaaaaaaaaaaaa3),
755  SPH_C64(0xaaaaaaaaaaaaaaa4), SPH_C64(0xaaaaaaaaaaaaaaa5),
756  SPH_C64(0xaaaaaaaaaaaaaaa6), SPH_C64(0xaaaaaaaaaaaaaaa7),
757  SPH_C64(0xaaaaaaaaaaaaaaa8), SPH_C64(0xaaaaaaaaaaaaaaa9),
758  SPH_C64(0xaaaaaaaaaaaaaaaa), SPH_C64(0xaaaaaaaaaaaaaaab),
759  SPH_C64(0xaaaaaaaaaaaaaaac), SPH_C64(0xaaaaaaaaaaaaaaad),
760  SPH_C64(0xaaaaaaaaaaaaaaae), SPH_C64(0xaaaaaaaaaaaaaaaf)
761 };
762 
763 static void
764 bmw64_init(sph_bmw_big_context *sc, const sph_u64 *iv)
765 {
766  memcpy(sc->H, iv, sizeof sc->H);
767  sc->ptr = 0;
768  sc->bit_count = 0;
769 }
770 
771 static void
772 bmw64(sph_bmw_big_context *sc, const void *data, size_t len)
773 {
774  unsigned char *buf;
775  size_t ptr;
776  sph_u64 htmp[16];
777  sph_u64 *h1, *h2;
778 
779  sc->bit_count += (sph_u64)len << 3;
780  buf = sc->buf;
781  ptr = sc->ptr;
782  h1 = sc->H;
783  h2 = htmp;
784  while (len > 0) {
785  size_t clen;
786 
787  clen = (sizeof sc->buf) - ptr;
788  if (clen > len)
789  clen = len;
790  memcpy(buf + ptr, data, clen);
791  data = (const unsigned char *)data + clen;
792  len -= clen;
793  ptr += clen;
794  if (ptr == sizeof sc->buf) {
795  sph_u64 *ht;
796 
797  compress_big(buf, h1, h2);
798  ht = h1;
799  h1 = h2;
800  h2 = ht;
801  ptr = 0;
802  }
803  }
804  sc->ptr = ptr;
805  if (h1 != sc->H)
806  memcpy(sc->H, h1, sizeof sc->H);
807 }
808 
809 static void
810 bmw64_close(sph_bmw_big_context *sc, unsigned ub, unsigned n,
811  void *dst, size_t out_size_w64)
812 {
813  unsigned char *buf, *out;
814  size_t ptr, u, v;
815  unsigned z;
816  sph_u64 h1[16], h2[16], *h;
817 
818  buf = sc->buf;
819  ptr = sc->ptr;
820  z = 0x80 >> n;
821  buf[ptr ++] = ((ub & -z) | z) & 0xFF;
822  h = sc->H;
823  if (ptr > (sizeof sc->buf) - 8) {
824  memset(buf + ptr, 0, (sizeof sc->buf) - ptr);
825  compress_big(buf, h, h1);
826  ptr = 0;
827  h = h1;
828  }
829  memset(buf + ptr, 0, (sizeof sc->buf) - 8 - ptr);
830  sph_enc64le_aligned(buf + (sizeof sc->buf) - 8,
831  SPH_T64(sc->bit_count + n));
832  compress_big(buf, h, h2);
833  for (u = 0; u < 16; u ++)
834  sph_enc64le_aligned(buf + 8 * u, h2[u]);
835  compress_big(buf, final_b, h1);
836  out = dst;
837  for (u = 0, v = 16 - out_size_w64; u < out_size_w64; u ++, v ++)
838  sph_enc64le(out + 8 * u, h1[v]);
839 }
840 
841 #endif
842 
843 /* see sph_bmw.h */
844 void
846 {
847  bmw32_init(cc, IV224);
848 }
849 
850 /* see sph_bmw.h */
851 void
852 sph_bmw224(void *cc, const void *data, size_t len)
853 {
854  bmw32(cc, data, len);
855 }
856 
857 /* see sph_bmw.h */
858 void
859 sph_bmw224_close(void *cc, void *dst)
860 {
861  sph_bmw224_addbits_and_close(cc, 0, 0, dst);
862 }
863 
864 /* see sph_bmw.h */
865 void
866 sph_bmw224_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
867 {
868  bmw32_close(cc, ub, n, dst, 7);
869  sph_bmw224_init(cc);
870 }
871 
872 /* see sph_bmw.h */
873 void
875 {
876  bmw32_init(cc, IV256);
877 }
878 
879 /* see sph_bmw.h */
880 void
881 sph_bmw256(void *cc, const void *data, size_t len)
882 {
883  bmw32(cc, data, len);
884 }
885 
886 /* see sph_bmw.h */
887 void
888 sph_bmw256_close(void *cc, void *dst)
889 {
890  sph_bmw256_addbits_and_close(cc, 0, 0, dst);
891 }
892 
893 /* see sph_bmw.h */
894 void
895 sph_bmw256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
896 {
897  bmw32_close(cc, ub, n, dst, 8);
898  sph_bmw256_init(cc);
899 }
900 
901 #if SPH_64
902 
903 /* see sph_bmw.h */
904 void
905 sph_bmw384_init(void *cc)
906 {
907  bmw64_init(cc, IV384);
908 }
909 
910 /* see sph_bmw.h */
911 void
912 sph_bmw384(void *cc, const void *data, size_t len)
913 {
914  bmw64(cc, data, len);
915 }
916 
917 /* see sph_bmw.h */
918 void
919 sph_bmw384_close(void *cc, void *dst)
920 {
921  sph_bmw384_addbits_and_close(cc, 0, 0, dst);
922 }
923 
924 /* see sph_bmw.h */
925 void
926 sph_bmw384_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
927 {
928  bmw64_close(cc, ub, n, dst, 6);
929  sph_bmw384_init(cc);
930 }
931 
932 /* see sph_bmw.h */
933 void
934 sph_bmw512_init(void *cc)
935 {
936  bmw64_init(cc, IV512);
937 }
938 
939 /* see sph_bmw.h */
940 void
941 sph_bmw512(void *cc, const void *data, size_t len)
942 {
943  bmw64(cc, data, len);
944 }
945 
946 /* see sph_bmw.h */
947 void
948 sph_bmw512_close(void *cc, void *dst)
949 {
950  sph_bmw512_addbits_and_close(cc, 0, 0, dst);
951 }
952 
953 /* see sph_bmw.h */
954 void
955 sph_bmw512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
956 {
957  bmw64_close(cc, ub, n, dst, 8);
958  sph_bmw512_init(cc);
959 }
960 
961 #endif
962 
963 #ifdef __cplusplus
964 }
965 #endif
void sph_bmw256(void *cc, const void *data, size_t len)
Process some data bytes.
Definition: bmw.c:881
static const sph_u32 IV384[]
Definition: cubehash.c:106
static SPH_INLINE void sph_enc32le_aligned(void *dst, sph_u32 val)
Encode a 32-bit value into the provided buffer (little endian convention).
Definition: sph_types.h:1522
#define FOLDs
Definition: bmw.c:560
static SPH_INLINE sph_u32 sph_dec32le_aligned(const void *src)
Decode a 32-bit value from the provided buffer (little endian convention).
Definition: sph_types.h:1615
#define SPH_T32(x)
Definition: sph_types.h:932
static const sph_u32 final_s[16]
Definition: bmw.c:604
static void bmw32(sph_bmw_small_context *sc, const void *data, size_t len)
Definition: bmw.c:627
#define SPH_C32(x)
Definition: sph_types.h:873
static void compress_big(sph_simd_big_context *sc, int last)
Definition: simd.c:1374
static void compress_small(const unsigned char *data, const sph_u32 h[16], sph_u32 dh[16])
Definition: bmw.c:569
void sph_bmw224(void *cc, const void *data, size_t len)
Process some data bytes.
Definition: bmw.c:852
void sph_bmw224_init(void *cc)
Initialize a BMW-224 context.
Definition: bmw.c:845
static void bmw32_init(sph_bmw_small_context *sc, const sph_u32 *iv)
Definition: bmw.c:614
void sph_bmw256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
Add a few additional bits (0 to 7) to the current computation, then terminate it and output the resul...
Definition: bmw.c:895
static SPH_INLINE void sph_enc32le(void *dst, sph_u32 val)
Encode a 32-bit value into the provided buffer (little endian convention).
Definition: sph_types.h:1485
static void bmw32_close(sph_bmw_small_context *sc, unsigned ub, unsigned n, void *dst, size_t out_size_w32)
Definition: bmw.c:676
void sph_bmw224_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
Add a few additional bits (0 to 7) to the current computation, then terminate it and output the resul...
Definition: bmw.c:866
void sph_bmw256_init(void *cc)
Initialize a BMW-256 context.
Definition: bmw.c:874
void sph_bmw224_close(void *cc, void *dst)
Terminate the current BMW-224 computation and output the result into the provided buffer...
Definition: bmw.c:859
static const sph_u32 IV512[]
Definition: cubehash.c:120
static const sph_u32 IV256[]
Definition: bmw.c:62
void sph_bmw256_close(void *cc, void *dst)
Terminate the current BMW-256 computation and output the result into the provided buffer...
Definition: bmw.c:888
BMW interface.
sph_u32 bit_count_high
Definition: sph_bmw.h:88
void * memcpy(void *a, const void *b, size_t c)
unsigned long sph_u32
Definition: sph_types.h:870
sph_u32 H[16]
Definition: sph_bmw.h:84
static const sph_u32 IV224[]
Definition: bmw.c:51
This structure is a context for BMW-224 and BMW-256 computations: it contains the intermediate values...
Definition: sph_bmw.h:80
sph_u32 bit_count_low
Definition: sph_bmw.h:88
unsigned char buf[64]
Definition: sph_bmw.h:82
Released under the MIT license