]> Git Repo - haraka-avx512.git/blame - haraka.c
fixed aes lol real test
[haraka-avx512.git] / haraka.c
CommitLineData
23e3fea5 1/*\r
2The MIT License (MIT)\r
3\r
4Copyright (c) 2016 kste\r
5\r
6Permission is hereby granted, free of charge, to any person obtaining a copy\r
7of this software and associated documentation files (the "Software"), to deal\r
8in the Software without restriction, including without limitation the rights\r
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
10copies of the Software, and to permit persons to whom the Software is\r
11furnished to do so, subject to the following conditions:\r
12\r
13The above copyright notice and this permission notice shall be included in all\r
14copies or substantial portions of the Software.\r
15\r
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
22SOFTWARE.\r
23\r
24Optimized Implementations for Haraka256 and Haraka512\r
25*/\r
26\r
27#include <stdio.h>\r
28#include "haraka.h"\r
29#include <stdint.h>\r
30u512 rc[10];\r
31u512 rc0[10] = {0};\r
32u512 MIX_4;\r
33void load_constants() {\r
34 MIX_4 = _mm512_set_epi32(3,11,7,15,8,0,12,4,9,1,13,5,2,10,6,14);\r
35\r
36 rc[0] = _mm512_set_epi32(0x0684704c,0xe620c00a,0xb2c5fef0,0x75817b9d,0x8b66b4e1,0x88f3a06b,0x640f6ba4,0x2f08f717,0x3402de2d,0x53f28498,0xcf029d60,0x9f029114,0x0ed6eae6,0x2e7b4f08,0xbbf3bcaf,0xfd5b4f79);\r
37 rc[1] = _mm512_set_epi32(0xcbcfb0cb,0x4872448b,0x79eecd1c,0xbe397044,0x7eeacdee,0x6e9032b7,0x8d5335ed,0x2b8a057b,0x67c28f43,0x5e2e7cd0,0xe2412761,0xda4fef1b,0x2924d9b0,0xafcacc07,0x675ffde2,0x1fc70b3b);\r
38 rc[2] = _mm512_set_epi32(0xab4d63f1,0xe6867fe9,0xecdb8fca,0xb9d465ee,0x1c30bf84,0xd4b7cd64,0x5b2a404f,0xad037e33,0xb2cc0bb9,0x941723bf,0x69028b2e,0x8df69800,0xfa0478a6,0xde6f5572,0x4aaa9ec8,0x5c9d2d8a);\r
39 rc[3] = _mm512_set_epi32(0xdfb49f2b,0x6b772a12,0x0efa4f2e,0x29129fd4,0x1ea10344,0xf449a236,0x32d611ae,0xbb6a12ee,0xaf044988,0x4b050084,0x5f9600c9,0x9ca8eca6,0x21025ed8,0x9d199c4f,0x78a2c7e3,0x27e593ec);\r
40 rc[4] = _mm512_set_epi32(0xbf3aaaf8,0xa759c9b7,0xb9282ecd,0x82d40173,0x6260700d,0x6186b017,0x37f2efd9,0x10307d6b,0x5aca45c2,0x21300443,0x81c29153,0xf6fc9ac6,0x9223973c,0x226b68bb,0x2caf92e8,0x36d1943a);\r
41 rc[5] = _mm512_set_epi32(0xd3bf9238,0x225886eb,0x6cbab958,0xe51071b4,0xdb863ce5,0xaef0c677,0x933dfddd,0x24e1128d,0xbb606268,0xffeba09c,0x83e48de3,0xcb2212b1,0x734bd3dc,0xe2e4d19c,0x2db91a4e,0xc72bf77d);\r
42 rc[6] = _mm512_set_epi32(0x43bb47c3,0x61301b43,0x4b1415c4,0x2cb3924e,0xdba775a8,0xe707eff6,0x03b231dd,0x16eb6899,0x6df3614b,0x3c755977,0x8e5e2302,0x7eca472c,0xcda75a17,0xd6de7d77,0x6d1be5b9,0xb88617f9);\r
43 rc[7] = _mm512_set_epi32(0xec6b43f0,0x6ba8e9aa,0x9d6c069d,0xa946ee5d,0xcb1e6950,0xf957332b,0xa2531159,0x3bf327c1,0x2cee0c75,0x00da619c,0xe4ed0353,0x600ed0d9,0xf0b1a5a1,0x96e90cab,0x80bbbabc,0x63a4a350);\r
44 rc[8] = _mm512_set_epi32(0xae3db102,0x5e962988,0xab0dde30,0x938dca39,0x17bb8f38,0xd554a40b,0x8814f3a8,0x2e75b442,0x34bb8a5b,0x5f427fd7,0xaeb6b779,0x360a16f6,0x26f65241,0xcbe55438,0x43ce5918,0xffbaafde);\r
45 rc[9] = _mm512_set_epi32(0x4ce99a54,0xb9f3026a,0xa2ca9cf7,0x839ec978,0xae51a51a,0x1bdff7be,0x40c06e28,0x22901235,0xa0c1613c,0xba7ed22b,0xc173bc0f,0x48a659cf,0x756acc03,0x02288288,0x4ad6bdfd,0xe9c59da1);\r
46}\r
47\r
48void test_implementations() {\r
49 unsigned char *in = (unsigned char *)calloc(64*8, sizeof(unsigned char));\r
50 unsigned char *out256 = (unsigned char *)calloc(32*8, sizeof(unsigned char));\r
51 unsigned char *out512 = (unsigned char *)calloc(32*8, sizeof(unsigned char));\r
52 unsigned char testvector256[32] = {0x80, 0x27, 0xcc, 0xb8, 0x79, 0x49, 0x77, 0x4b,\r
53 0x78, 0xd0, 0x54, 0x5f, 0xb7, 0x2b, 0xf7, 0x0c,\r
54 0x69, 0x5c, 0x2a, 0x09, 0x23, 0xcb, 0xd4, 0x7b,\r
55 0xba, 0x11, 0x59, 0xef, 0xbf, 0x2b, 0x2c, 0x1c};\r
56\r
57 unsigned char testvector512[32] = {0xbe, 0x7f, 0x72, 0x3b, 0x4e, 0x80, 0xa9, 0x98,\r
58 0x13, 0xb2, 0x92, 0x28, 0x7f, 0x30, 0x6f, 0x62,\r
59 0x5a, 0x6d, 0x57, 0x33, 0x1c, 0xae, 0x5f, 0x34,\r
60 0xdd, 0x92, 0x77, 0xb0, 0x94, 0x5b, 0xe2, 0xaa};\r
61\r
62\r
63\r
64 int i;\r
65\r
66 // Input for testvector\r
67 for(i = 0; i < 512; i++) {\r
68 in[i] = i % 64;\r
69 }\r
70\r
71 load_constants();\r
72 // haraka512_8x(out512, in);\r
73\r
74 // Verify output\r
75 for(i = 0; i < 32; i++) {\r
76 if (out512[i % 32] != testvector512[i]) {\r
77 printf("Error: testvector incorrect.\n");\r
78 return;\r
79 }\r
80 }\r
81\r
82 free(in);\r
83 free(out256);\r
84 free(out512);\r
85}\r
86/*\r
87void haraka256(unsigned char *out, const unsigned char *in) {\r
88 __m128i s[2], tmp;\r
89\r
90 s[0] = LOAD(in);\r
91 s[1] = LOAD(in + 16);\r
92\r
93 AES2(s[0], s[1], 0);\r
94 MIX2(s[0], s[1]);\r
95\r
96 AES2(s[0], s[1], 4);\r
97 MIX2(s[0], s[1]);\r
98\r
99 AES2(s[0], s[1], 8);\r
100 MIX2(s[0], s[1]);\r
101\r
102 AES2(s[0], s[1], 12);\r
103 MIX2(s[0], s[1]);\r
104\r
105 AES2(s[0], s[1], 16);\r
106 MIX2(s[0], s[1]);\r
107\r
108 s[0] = _mm_xor_si128(s[0], LOAD(in));\r
109 s[1] = _mm_xor_si128(s[1], LOAD(in + 16));\r
110\r
111 STORE(out, s[0]);\r
112 STORE(out + 16, s[1]);\r
113}\r
114\r
115void haraka256_keyed(unsigned char *out, const unsigned char *in, const u128 *rc) {\r
116 __m128i s[2], tmp;\r
117\r
118 s[0] = LOAD(in);\r
119 s[1] = LOAD(in + 16);\r
120\r
121\r
122 s[0] = _mm_xor_si128(s[0], LOAD(in));\r
123 s[1] = _mm_xor_si128(s[1], LOAD(in + 16));\r
124\r
125 STORE(out, s[0]);\r
126 STORE(out + 16, s[1]);\r
127}\r
128\r
129void haraka256_4x(unsigned char *out, const unsigned char *in) {\r
130 __m128i s[4][2], tmp;\r
131\r
132 s[0][0] = LOAD(in);\r
133 s[0][1] = LOAD(in + 16);\r
134 s[1][0] = LOAD(in + 32);\r
135 s[1][1] = LOAD(in + 48);\r
136 s[2][0] = LOAD(in + 64);\r
137 s[2][1] = LOAD(in + 80);\r
138 s[3][0] = LOAD(in + 96);\r
139\r
140\r
141 MIX2(s[0][0], s[0][1]);\r
142 MIX2(s[1][0], s[1][1]);\r
143 MIX2(s[2][0], s[2][1]);\r
144 MIX2(s[3][0], s[3][1]);\r
145\r
146 // Feed Forward\r
147 s[0][0] = _mm_xor_si128(s[0][0], LOAD(in));\r
148 s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16));\r
149 s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 32));\r
150 s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 48));\r
151 s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 64));\r
152 s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 80));\r
153 s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 96));\r
154 s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 112));\r
155\r
156 STORE(out, s[0][0]);\r
157 STORE(out + 16, s[0][1]);\r
158 STORE(out + 32, s[1][0]);\r
159 STORE(out + 48, s[1][1]);\r
160 STORE(out + 64, s[2][0]);\r
161 STORE(out + 80, s[2][1]);\r
162 STORE(out + 96, s[3][0]);\r
163 STORE(out + 112, s[3][1]);\r
164}\r
165\r
166void haraka256_8x(unsigned char *out, const unsigned char *in) {\r
167 // This is faster on Skylake, the code below is faster on Haswell.\r
168 haraka256_4x(out, in);\r
169 haraka256_4x(out + 128, in + 128);\r
170 return;\r
171 // __m128i s[8][2], tmp;\r
172 //\r
173 // int i;\r
174 //\r
175 // s[0][0] = LOAD(in);\r
176 // s[0][1] = LOAD(in + 16);\r
177 // s[1][0] = LOAD(in + 32);\r
178 // s[1][1] = LOAD(in + 48);\r
179 // s[2][0] = LOAD(in + 64);\r
180 // s[2][1] = LOAD(in + 80);\r
181 // s[3][0] = LOAD(in + 96);\r
182 // s[3][1] = LOAD(in + 112);\r
183 // s[4][0] = LOAD(in + 128);\r
184 // s[4][1] = LOAD(in + 144);\r
185 // s[5][0] = LOAD(in + 160);\r
186 // s[5][1] = LOAD(in + 176);\r
187 // s[6][0] = LOAD(in + 192);\r
188 // s[6][1] = LOAD(in + 208);\r
189 // s[7][0] = LOAD(in + 224);\r
190 // s[7][1] = LOAD(in + 240);\r
191 //\r
192 // // Round 1\r
193 // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 0);\r
194 //\r
195 // MIX2(s[0][0], s[0][1]);\r
196 // MIX2(s[1][0], s[1][1]);\r
197 // MIX2(s[2][0], s[2][1]);\r
198 // MIX2(s[3][0], s[3][1]);\r
199 // MIX2(s[4][0], s[4][1]);\r
200 // MIX2(s[5][0], s[5][1]);\r
201 // MIX2(s[6][0], s[6][1]);\r
202 // MIX2(s[7][0], s[7][1]);\r
203 //\r
204 //\r
205 // // Round 2\r
206 // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 4);\r
207 //\r
208 // MIX2(s[0][0], s[0][1]);\r
209 // MIX2(s[1][0], s[1][1]);\r
210 // MIX2(s[2][0], s[2][1]);\r
211 // MIX2(s[3][0], s[3][1]);\r
212 // MIX2(s[4][0], s[4][1]);\r
213 // MIX2(s[5][0], s[5][1]);\r
214 // MIX2(s[6][0], s[6][1]);\r
215 // MIX2(s[7][0], s[7][1]);\r
216 //\r
217 // // Round 3\r
218 // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 8);\r
219 //\r
220 // MIX2(s[0][0], s[0][1]);\r
221 // MIX2(s[1][0], s[1][1]);\r
222 // MIX2(s[2][0], s[2][1]);\r
223 // MIX2(s[3][0], s[3][1]);\r
224 // MIX2(s[4][0], s[4][1]);\r
225 // MIX2(s[5][0], s[5][1]);\r
226 // MIX2(s[6][0], s[6][1]);\r
227 // MIX2(s[7][0], s[7][1]);\r
228 //\r
229 // // Round 4\r
230 // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 12);\r
231 //\r
232 // MIX2(s[0][0], s[0][1]);\r
233 // MIX2(s[1][0], s[1][1]);\r
234 // MIX2(s[2][0], s[2][1]);\r
235 // MIX2(s[3][0], s[3][1]);\r
236 // MIX2(s[4][0], s[4][1]);\r
237 // MIX2(s[5][0], s[5][1]);\r
238 // MIX2(s[6][0], s[6][1]);\r
239 // MIX2(s[7][0], s[7][1]);\r
240 //\r
241 // // Round 5\r
242 // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 16);\r
243 //\r
244 // MIX2(s[0][0], s[0][1]);\r
245 // MIX2(s[1][0], s[1][1]);\r
246 // MIX2(s[2][0], s[2][1]);\r
247 // MIX2(s[3][0], s[3][1]);\r
248 // MIX2(s[4][0], s[4][1]);\r
249 // MIX2(s[5][0], s[5][1]);\r
250 // MIX2(s[6][0], s[6][1]);\r
251 // MIX2(s[7][0], s[7][1]);\r
252 //\r
253 // // Feed Forward\r
254 // s[0][0] = _mm_xor_si128(s[0][0], LOAD(in));\r
255 // s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16));\r
256 // s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 32));\r
257 // s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 48));\r
258 // s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 64));\r
259 // s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 80));\r
260 // s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 96));\r
261 // s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 112));\r
262 // s[4][0] = _mm_xor_si128(s[4][0], LOAD(in + 128));\r
263 // s[4][1] = _mm_xor_si128(s[4][1], LOAD(in + 144));\r
264 // s[5][0] = _mm_xor_si128(s[5][0], LOAD(in + 160));\r
265 // s[5][1] = _mm_xor_si128(s[5][1], LOAD(in + 176));\r
266 // s[6][0] = _mm_xor_si128(s[6][0], LOAD(in + 192));\r
267 // s[6][1] = _mm_xor_si128(s[6][1], LOAD(in + 208));\r
268 // s[7][0] = _mm_xor_si128(s[7][0], LOAD(in + 224));\r
269 // s[7][1] = _mm_xor_si128(s[7][1], LOAD(in + 240));\r
270 //\r
271 // STORE(out, s[0][0]);\r
272 // STORE(out + 16, s[0][1]);\r
273 // STORE(out + 32, s[1][0]);\r
274 // STORE(out + 48, s[1][1]);\r
275 // STORE(out + 64, s[2][0]);\r
276 // STORE(out + 80, s[2][1]);\r
277 // STORE(out + 96, s[3][0]);\r
278 // STORE(out + 112, s[3][1]);\r
279 // STORE(out + 128, s[4][0]);\r
280 // STORE(out + 144, s[4][1]);\r
281 // STORE(out + 160, s[5][0]);\r
282 // STORE(out + 176, s[5][1]);\r
283 // STORE(out + 192, s[6][0]);\r
284 // STORE(out + 208, s[6][1]);\r
285 // STORE(out + 224, s[7][0]);\r
286 // STORE(out + 240, s[7][1]);\r
287}\r
288*/\r
73b6698e
MB
289static void phex(uint8_t* str)\r
290{\r
291 uint8_t len = 64;\r
292\r
293 unsigned char i;\r
294 for (i = 0; i < len; ++i)\r
295 printf("%lx, ", str[i]);\r
296 printf("\n");\r
297}\r
23e3fea5 298void haraka512(unsigned char *out, const unsigned char *in) {\r
299 u512 s,i;\r
300 s = LOAD (in);\r
301 i = s;\r
b44a5e9b 302\r
afb82921 303 AES4(s, 0);\r
23e3fea5 304 MIX4(s);\r
305\r
306 AES4(s, 2);\r
307 MIX4(s);\r
308\r
309 AES4(s, 4);\r
310 MIX4(s);\r
311\r
312 AES4(s, 6);\r
313 MIX4(s);\r
314\r
315 AES4(s, 8);\r
316 MIX4(s);\r
317\r
318 s = _mm512_xor_si512(s, i);\r
319 STORE(out,s);\r
320\r
2733a776 321 TRUNCSTORE(out, s);\r
23e3fea5 322}\r
323\r
324void haraka512_zero(unsigned char *out, const unsigned char *in) {\r
325 u512 s,i;\r
326 s = LOAD (in);\r
73b6698e
MB
327 STORE(out,s);\r
328 phex(out);\r
23e3fea5 329 i = s;\r
330 AES4_zero(s, 0);\r
331 MIX4(s);\r
332\r
333 AES4_zero(s, 2);\r
334 MIX4(s);\r
335\r
336 AES4_zero(s, 4);\r
337 MIX4(s);\r
338\r
339 AES4_zero(s, 6);\r
340 MIX4(s);\r
341\r
342 AES4_zero(s, 8);\r
343 MIX4(s);\r
344\r
345 s = _mm512_xor_si512(s, i);\r
346 STORE(out,s);\r
347\r
348\r
349\r
2733a776 350 TRUNCSTORE(out, s);\r
23e3fea5 351}\r
352/*\r
353void haraka512_keyed(unsigned char *out, const unsigned char *in, const u128 *rc) {\r
354 u128 s[4], tmp;\r
355\r
356 s[0] = LOAD(in);\r
357 s[1] = LOAD(in + 16);\r
358 s[2] = LOAD(in + 32);\r
359 s[3] = LOAD(in + 48);\r
360\r
361 AES4(s[0], s[1], s[2], s[3], 0);\r
362 MIX4(s[0], s[1], s[2], s[3]);\r
363\r
364 AES4(s[0], s[1], s[2], s[3], 8);\r
365 MIX4(s[0], s[1], s[2], s[3]);\r
366\r
367 AES4(s[0], s[1], s[2], s[3], 16);\r
368 MIX4(s[0], s[1], s[2], s[3]);\r
369\r
370 AES4(s[0], s[1], s[2], s[3], 24);\r
371 MIX4_LAST(s[0], s[1], s[2], s[3]);\r
372\r
373 AES4_LAST(s[0], s[1], s[2], s[3], 32);\r
374\r
375\r
376 // s[0] = _mm_xor_si128(s[0], LOAD(in));\r
377 // s[1] = _mm_xor_si128(s[1], LOAD(in + 16));\r
378 // s[2] = _mm_xor_si128(s[2], LOAD(in + 32));\r
379 // s[3] = _mm_xor_si128(s[0], LOAD(in + 48));\r
380 ((uint32_t*)&out[0])[7] = ((uint32_t*)&s[0])[10] ^ ((uint32_t*)&in[52])[0];\r
381\r
382 //TRUNCSTORE(out, s[0],s[1], s[2], s[3]);\r
383}\r
384\r
385void haraka512_4x(unsigned char *out, const unsigned char *in) {\r
386 u128 s[4][4], tmp;\r
387\r
388 s[0][0] = LOAD(in);\r
389 s[0][1] = LOAD(in + 16);\r
390 s[0][2] = LOAD(in + 32);\r
391 s[0][3] = LOAD(in + 48);\r
392 s[1][0] = LOAD(in + 64);\r
393 s[1][1] = LOAD(in + 80);\r
394 s[1][2] = LOAD(in + 96);\r
395 s[1][3] = LOAD(in + 112);\r
396 s[2][0] = LOAD(in + 128);\r
397 s[2][1] = LOAD(in + 144);\r
398 s[2][2] = LOAD(in + 160);\r
399 s[2][3] = LOAD(in + 176);\r
400 s[3][0] = LOAD(in + 192);\r
401 s[3][1] = LOAD(in + 208);\r
402 s[3][2] = LOAD(in + 224);\r
403 s[3][3] = LOAD(in + 240);\r
404\r
405 AES4_4x(s[0], s[1], s[2], s[3], 0);\r
406 MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
407 MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
408 MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
409 MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
410\r
411 AES4_4x(s[0], s[1], s[2], s[3], 8);\r
412 MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
413 MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
414 MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
415 MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
416\r
417 AES4_4x(s[0], s[1], s[2], s[3], 16);\r
418 MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
419 MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
420 MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
421 MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
422\r
423 AES4_4x(s[0], s[1], s[2], s[3], 24);\r
424 MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
425 MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
426 MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
427 MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
428\r
429 AES4_4x(s[0], s[1], s[2], s[3], 32);\r
430 MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
431 MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
432 MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
433 MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
434\r
435\r
436 s[0][0] = _mm_xor_si128(s[0][0], LOAD(in));\r
437 s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16));\r
438 s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32));\r
439 s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48));\r
440 s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64));\r
441 s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80));\r
442 s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96));\r
443 s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112));\r
444 s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128));\r
445 s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144));\r
446 s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160));\r
447 s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176));\r
448 s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192));\r
449 s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208));\r
450 s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224));\r
451 s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240));\r
452\r
453 TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]);\r
454 TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]);\r
455 TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]);\r
456 TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]);\r
457}\r
458\r
459void haraka512_8x(unsigned char *out, const unsigned char *in) {\r
460 // This is faster on Skylake, the code below is faster on Haswell.\r
461 haraka512_4x(out, in);\r
462 haraka512_4x(out + 128, in + 256);\r
463\r
464 // u128 s[8][4], tmp;\r
465 //\r
466 // s[0][0] = LOAD(in);\r
467 // s[0][1] = LOAD(in + 16);\r
468 // s[0][2] = LOAD(in + 32);\r
469 // s[0][3] = LOAD(in + 48);\r
470 // s[1][0] = LOAD(in + 64);\r
471 // s[1][1] = LOAD(in + 80);\r
472 // s[1][2] = LOAD(in + 96);\r
473 // s[1][3] = LOAD(in + 112);\r
474 // s[2][0] = LOAD(in + 128);\r
475 // s[2][1] = LOAD(in + 144);\r
476 // s[2][2] = LOAD(in + 160);\r
477 // s[2][3] = LOAD(in + 176);\r
478 // s[3][0] = LOAD(in + 192);\r
479 // s[3][1] = LOAD(in + 208);\r
480 // s[3][2] = LOAD(in + 224);\r
481 // s[3][3] = LOAD(in + 240);\r
482 // s[4][0] = LOAD(in + 256);\r
483 // s[4][1] = LOAD(in + 272);\r
484 // s[4][2] = LOAD(in + 288);\r
485 // s[4][3] = LOAD(in + 304);\r
486 // s[5][0] = LOAD(in + 320);\r
487 // s[5][1] = LOAD(in + 336);\r
488 // s[5][2] = LOAD(in + 352);\r
489 // s[5][3] = LOAD(in + 368);\r
490 // s[6][0] = LOAD(in + 384);\r
491 // s[6][1] = LOAD(in + 400);\r
492 // s[6][2] = LOAD(in + 416);\r
493 // s[6][3] = LOAD(in + 432);\r
494 // s[7][0] = LOAD(in + 448);\r
495 // s[7][1] = LOAD(in + 464);\r
496 // s[7][2] = LOAD(in + 480);\r
497 // s[7][3] = LOAD(in + 496);\r
498 //\r
499 // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 0);\r
500 // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
501 // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
502 // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
503 // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
504 // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]);\r
505 // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]);\r
506 // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]);\r
507 // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]);\r
508 //\r
509 // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 8);\r
510 // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
511 // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
512 // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
513 // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
514 // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]);\r
515 // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]);\r
516 // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]);\r
517 // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]);\r
518 //\r
519 // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 16);\r
520 // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
521 // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
522 // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
523 // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
524 // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]);\r
525 // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]);\r
526 // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]);\r
527 // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]);\r
528 //\r
529 // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 24);\r
530 // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
531 // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
532 // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
533 // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
534 // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]);\r
535 // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]);\r
536 // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]);\r
537 // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]);\r
538 //\r
539 // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 32);\r
540 // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
541 // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
542 // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
543 // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
544 // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]);\r
545 // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]);\r
546 // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]);\r
547 // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]);\r
548 //\r
549 //\r
550 // s[0][0] = _mm_xor_si128(s[0][0], LOAD(in));\r
551 // s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16));\r
552 // s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32));\r
553 // s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48));\r
554 // s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64));\r
555 // s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80));\r
556 // s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96));\r
557 // s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112));\r
558 // s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128));\r
559 // s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144));\r
560 // s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160));\r
561 // s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176));\r
562 // s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192));\r
563 // s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208));\r
564 // s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224));\r
565 // s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240));\r
566 // s[4][0] = _mm_xor_si128(s[4][0], LOAD(in + 256));\r
567 // s[4][1] = _mm_xor_si128(s[4][1], LOAD(in + 272));\r
568 // s[4][2] = _mm_xor_si128(s[4][2], LOAD(in + 288));\r
569 // s[4][3] = _mm_xor_si128(s[4][3], LOAD(in + 304));\r
570 // s[5][0] = _mm_xor_si128(s[5][0], LOAD(in + 320));\r
571 // s[5][1] = _mm_xor_si128(s[5][1], LOAD(in + 336));\r
572 // s[5][2] = _mm_xor_si128(s[5][2], LOAD(in + 352));\r
573 // s[5][3] = _mm_xor_si128(s[5][3], LOAD(in + 368));\r
574 // s[6][0] = _mm_xor_si128(s[6][0], LOAD(in + 384));\r
575 // s[6][1] = _mm_xor_si128(s[6][1], LOAD(in + 400));\r
576 // s[6][2] = _mm_xor_si128(s[6][2], LOAD(in + 416));\r
577 // s[6][3] = _mm_xor_si128(s[6][3], LOAD(in + 432));\r
578 // s[7][0] = _mm_xor_si128(s[7][0], LOAD(in + 448));\r
579 // s[7][1] = _mm_xor_si128(s[7][1], LOAD(in + 464));\r
580 // s[7][2] = _mm_xor_si128(s[7][2], LOAD(in + 480));\r
581 // s[7][3] = _mm_xor_si128(s[7][3], LOAD(in + 496));\r
582 //\r
583 // TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]);\r
584 // TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]);\r
585 // TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]);\r
586 // TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]);\r
587 // TRUNCSTORE(out + 128, s[4][0], s[4][1], s[4][2], s[4][3]);\r
588 // TRUNCSTORE(out + 160, s[5][0], s[5][1], s[5][2], s[5][3]);\r
589 // TRUNCSTORE(out + 192, s[6][0], s[6][1], s[6][2], s[6][3]);\r
590 // TRUNCSTORE(out + 224, s[7][0], s[7][1], s[7][2], s[7][3]);\r
591}*/\r
This page took 0.085148 seconds and 4 git commands to generate.