33 #if (defined(__aarch32__) || defined(__aarch64__)) && defined(CRYPTOPP_SLOW_ARMV8_SHIFT)
34 # undef CRYPTOPP_ARM_NEON_AVAILABLE
39 #if defined(__xlC__) && (__xlC__ < 0x0d01)
40 # define CRYPTOPP_DISABLE_ALTIVEC 1
41 # undef CRYPTOPP_POWER7_AVAILABLE
42 # undef CRYPTOPP_POWER8_AVAILABLE
43 # undef CRYPTOPP_ALTIVEC_AVAILABLE
46 #if (CRYPTOPP_SSE41_AVAILABLE)
47 # include <emmintrin.h>
48 # include <tmmintrin.h>
49 # include <smmintrin.h>
53 #if (CRYPTOPP_ARM_NEON_AVAILABLE) && !defined(_M_ARM64)
54 # include <arm_neon.h>
57 #if (CRYPTOPP_ARM_ACLE_AVAILABLE)
59 # include <arm_acle.h>
62 #if (CRYPTOPP_ALTIVEC_AVAILABLE)
67 extern const char BLAKE2S_SIMD_FNAME[] = __FILE__;
72 extern const word32 BLAKE2S_IV[8];
73 extern const word64 BLAKE2B_IV[8];
75 #if CRYPTOPP_SSE41_AVAILABLE
77 #define LOADU(p) _mm_loadu_si128((const __m128i *)(const void*)(p))
78 #define STOREU(p,r) _mm_storeu_si128((__m128i *)(void*)(p), r)
79 #define TOF(reg) _mm_castsi128_ps((reg))
80 #define TOI(reg) _mm_castps_si128((reg))
82 void BLAKE2_Compress32_SSE4(
const byte* input,
BLAKE2s_State& state)
84 #define BLAKE2S_LOAD_MSG_0_1(buf) \
85 buf = TOI(_mm_shuffle_ps(TOF(m0), TOF(m1), _MM_SHUFFLE(2,0,2,0)));
87 #define BLAKE2S_LOAD_MSG_0_2(buf) \
88 buf = TOI(_mm_shuffle_ps(TOF(m0), TOF(m1), _MM_SHUFFLE(3,1,3,1)));
90 #define BLAKE2S_LOAD_MSG_0_3(buf) \
91 buf = TOI(_mm_shuffle_ps(TOF(m2), TOF(m3), _MM_SHUFFLE(2,0,2,0)));
93 #define BLAKE2S_LOAD_MSG_0_4(buf) \
94 buf = TOI(_mm_shuffle_ps(TOF(m2), TOF(m3), _MM_SHUFFLE(3,1,3,1)));
96 #define BLAKE2S_LOAD_MSG_1_1(buf) \
97 t0 = _mm_blend_epi16(m1, m2, 0x0C); \
98 t1 = _mm_slli_si128(m3, 4); \
99 t2 = _mm_blend_epi16(t0, t1, 0xF0); \
100 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,1,0,3));
102 #define BLAKE2S_LOAD_MSG_1_2(buf) \
103 t0 = _mm_shuffle_epi32(m2,_MM_SHUFFLE(0,0,2,0)); \
104 t1 = _mm_blend_epi16(m1,m3,0xC0); \
105 t2 = _mm_blend_epi16(t0, t1, 0xF0); \
106 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1));
108 #define BLAKE2S_LOAD_MSG_1_3(buf) \
109 t0 = _mm_slli_si128(m1, 4); \
110 t1 = _mm_blend_epi16(m2, t0, 0x30); \
111 t2 = _mm_blend_epi16(m0, t1, 0xF0); \
112 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1));
114 #define BLAKE2S_LOAD_MSG_1_4(buf) \
115 t0 = _mm_unpackhi_epi32(m0,m1); \
116 t1 = _mm_slli_si128(m3, 4); \
117 t2 = _mm_blend_epi16(t0, t1, 0x0C); \
118 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1));
120 #define BLAKE2S_LOAD_MSG_2_1(buf) \
121 t0 = _mm_unpackhi_epi32(m2,m3); \
122 t1 = _mm_blend_epi16(m3,m1,0x0C); \
123 t2 = _mm_blend_epi16(t0, t1, 0x0F); \
124 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(3,1,0,2));
126 #define BLAKE2S_LOAD_MSG_2_2(buf) \
127 t0 = _mm_unpacklo_epi32(m2,m0); \
128 t1 = _mm_blend_epi16(t0, m0, 0xF0); \
129 t2 = _mm_slli_si128(m3, 8); \
130 buf = _mm_blend_epi16(t1, t2, 0xC0);
132 #define BLAKE2S_LOAD_MSG_2_3(buf) \
133 t0 = _mm_blend_epi16(m0, m2, 0x3C); \
134 t1 = _mm_srli_si128(m1, 12); \
135 t2 = _mm_blend_epi16(t0,t1,0x03); \
136 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,0,3,2));
138 #define BLAKE2S_LOAD_MSG_2_4(buf) \
139 t0 = _mm_slli_si128(m3, 4); \
140 t1 = _mm_blend_epi16(m0, m1, 0x33); \
141 t2 = _mm_blend_epi16(t1, t0, 0xC0); \
142 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(0,1,2,3));
144 #define BLAKE2S_LOAD_MSG_3_1(buf) \
145 t0 = _mm_unpackhi_epi32(m0,m1); \
146 t1 = _mm_unpackhi_epi32(t0, m2); \
147 t2 = _mm_blend_epi16(t1, m3, 0x0C); \
148 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(3,1,0,2));
150 #define BLAKE2S_LOAD_MSG_3_2(buf) \
151 t0 = _mm_slli_si128(m2, 8); \
152 t1 = _mm_blend_epi16(m3,m0,0x0C); \
153 t2 = _mm_blend_epi16(t1, t0, 0xC0); \
154 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,0,1,3));
156 #define BLAKE2S_LOAD_MSG_3_3(buf) \
157 t0 = _mm_blend_epi16(m0,m1,0x0F); \
158 t1 = _mm_blend_epi16(t0, m3, 0xC0); \
159 buf = _mm_shuffle_epi32(t1, _MM_SHUFFLE(3,0,1,2));
161 #define BLAKE2S_LOAD_MSG_3_4(buf) \
162 t0 = _mm_unpacklo_epi32(m0,m2); \
163 t1 = _mm_unpackhi_epi32(m1,m2); \
164 buf = _mm_unpacklo_epi64(t1,t0);
166 #define BLAKE2S_LOAD_MSG_4_1(buf) \
167 t0 = _mm_unpacklo_epi64(m1,m2); \
168 t1 = _mm_unpackhi_epi64(m0,m2); \
169 t2 = _mm_blend_epi16(t0,t1,0x33); \
170 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,0,1,3));
172 #define BLAKE2S_LOAD_MSG_4_2(buf) \
173 t0 = _mm_unpackhi_epi64(m1,m3); \
174 t1 = _mm_unpacklo_epi64(m0,m1); \
175 buf = _mm_blend_epi16(t0,t1,0x33);
177 #define BLAKE2S_LOAD_MSG_4_3(buf) \
178 t0 = _mm_unpackhi_epi64(m3,m1); \
179 t1 = _mm_unpackhi_epi64(m2,m0); \
180 buf = _mm_blend_epi16(t1,t0,0x33);
182 #define BLAKE2S_LOAD_MSG_4_4(buf) \
183 t0 = _mm_blend_epi16(m0,m2,0x03); \
184 t1 = _mm_slli_si128(t0, 8); \
185 t2 = _mm_blend_epi16(t1,m3,0x0F); \
186 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,2,0,3));
188 #define BLAKE2S_LOAD_MSG_5_1(buf) \
189 t0 = _mm_unpackhi_epi32(m0,m1); \
190 t1 = _mm_unpacklo_epi32(m0,m2); \
191 buf = _mm_unpacklo_epi64(t0,t1);
193 #define BLAKE2S_LOAD_MSG_5_2(buf) \
194 t0 = _mm_srli_si128(m2, 4); \
195 t1 = _mm_blend_epi16(m0,m3,0x03); \
196 buf = _mm_blend_epi16(t1,t0,0x3C);
198 #define BLAKE2S_LOAD_MSG_5_3(buf) \
199 t0 = _mm_blend_epi16(m1,m0,0x0C); \
200 t1 = _mm_srli_si128(m3, 4); \
201 t2 = _mm_blend_epi16(t0,t1,0x30); \
202 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,2,3,0));
204 #define BLAKE2S_LOAD_MSG_5_4(buf) \
205 t0 = _mm_unpacklo_epi64(m1,m2); \
206 t1= _mm_shuffle_epi32(m3, _MM_SHUFFLE(0,2,0,1)); \
207 buf = _mm_blend_epi16(t0,t1,0x33);
209 #define BLAKE2S_LOAD_MSG_6_1(buf) \
210 t0 = _mm_slli_si128(m1, 12); \
211 t1 = _mm_blend_epi16(m0,m3,0x33); \
212 buf = _mm_blend_epi16(t1,t0,0xC0);
214 #define BLAKE2S_LOAD_MSG_6_2(buf) \
215 t0 = _mm_blend_epi16(m3,m2,0x30); \
216 t1 = _mm_srli_si128(m1, 4); \
217 t2 = _mm_blend_epi16(t0,t1,0x03); \
218 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,1,3,0));
220 #define BLAKE2S_LOAD_MSG_6_3(buf) \
221 t0 = _mm_unpacklo_epi64(m0,m2); \
222 t1 = _mm_srli_si128(m1, 4); \
223 buf = _mm_shuffle_epi32(_mm_blend_epi16(t0,t1,0x0C), _MM_SHUFFLE(2,3,1,0));
225 #define BLAKE2S_LOAD_MSG_6_4(buf) \
226 t0 = _mm_unpackhi_epi32(m1,m2); \
227 t1 = _mm_unpackhi_epi64(m0,t0); \
228 buf = _mm_shuffle_epi32(t1, _MM_SHUFFLE(3,0,1,2));
230 #define BLAKE2S_LOAD_MSG_7_1(buf) \
231 t0 = _mm_unpackhi_epi32(m0,m1); \
232 t1 = _mm_blend_epi16(t0,m3,0x0F); \
233 buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(2,0,3,1));
235 #define BLAKE2S_LOAD_MSG_7_2(buf) \
236 t0 = _mm_blend_epi16(m2,m3,0x30); \
237 t1 = _mm_srli_si128(m0,4); \
238 t2 = _mm_blend_epi16(t0,t1,0x03); \
239 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,0,2,3));
241 #define BLAKE2S_LOAD_MSG_7_3(buf) \
242 t0 = _mm_unpackhi_epi64(m0,m3); \
243 t1 = _mm_unpacklo_epi64(m1,m2); \
244 t2 = _mm_blend_epi16(t0,t1,0x3C); \
245 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(0,2,3,1));
247 #define BLAKE2S_LOAD_MSG_7_4(buf) \
248 t0 = _mm_unpacklo_epi32(m0,m1); \
249 t1 = _mm_unpackhi_epi32(m1,m2); \
250 buf = _mm_unpacklo_epi64(t0,t1);
252 #define BLAKE2S_LOAD_MSG_8_1(buf) \
253 t0 = _mm_unpackhi_epi32(m1,m3); \
254 t1 = _mm_unpacklo_epi64(t0,m0); \
255 t2 = _mm_blend_epi16(t1,m2,0xC0); \
256 buf = _mm_shufflehi_epi16(t2,_MM_SHUFFLE(1,0,3,2));
258 #define BLAKE2S_LOAD_MSG_8_2(buf) \
259 t0 = _mm_unpackhi_epi32(m0,m3); \
260 t1 = _mm_blend_epi16(m2,t0,0xF0); \
261 buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(0,2,1,3));
263 #define BLAKE2S_LOAD_MSG_8_3(buf) \
264 t0 = _mm_blend_epi16(m2,m0,0x0C); \
265 t1 = _mm_slli_si128(t0,4); \
266 buf = _mm_blend_epi16(t1,m3,0x0F);
268 #define BLAKE2S_LOAD_MSG_8_4(buf) \
269 t0 = _mm_blend_epi16(m1,m0,0x30); \
270 buf = _mm_shuffle_epi32(t0,_MM_SHUFFLE(1,0,3,2));
272 #define BLAKE2S_LOAD_MSG_9_1(buf) \
273 t0 = _mm_blend_epi16(m0,m2,0x03); \
274 t1 = _mm_blend_epi16(m1,m2,0x30); \
275 t2 = _mm_blend_epi16(t1,t0,0x0F); \
276 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(1,3,0,2));
278 #define BLAKE2S_LOAD_MSG_9_2(buf) \
279 t0 = _mm_slli_si128(m0,4); \
280 t1 = _mm_blend_epi16(m1,t0,0xC0); \
281 buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(1,2,0,3));
283 #define BLAKE2S_LOAD_MSG_9_3(buf) \
284 t0 = _mm_unpackhi_epi32(m0,m3); \
285 t1 = _mm_unpacklo_epi32(m2,m3); \
286 t2 = _mm_unpackhi_epi64(t0,t1); \
287 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(3,0,2,1));
289 #define BLAKE2S_LOAD_MSG_9_4(buf) \
290 t0 = _mm_blend_epi16(m3,m2,0xC0); \
291 t1 = _mm_unpacklo_epi32(m0,m3); \
292 t2 = _mm_blend_epi16(t0,t1,0x0F); \
293 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(0,1,2,3));
296 # define MM_ROTI_EPI32(r, c) \
299 # define MM_ROTI_EPI32(r, c) ( \
300 (8==-(c)) ? _mm_shuffle_epi8(r,r8) \
301 : (16==-(c)) ? _mm_shuffle_epi8(r,r16) \
302 : _mm_xor_si128(_mm_srli_epi32((r), -(c)), \
303 _mm_slli_epi32((r), 32-(-(c)))))
306 #define BLAKE2S_G1(row1,row2,row3,row4,buf) \
307 row1 = _mm_add_epi32(_mm_add_epi32(row1, buf), row2); \
308 row4 = _mm_xor_si128(row4, row1); \
309 row4 = MM_ROTI_EPI32(row4, -16); \
310 row3 = _mm_add_epi32(row3, row4); \
311 row2 = _mm_xor_si128(row2, row3); \
312 row2 = MM_ROTI_EPI32(row2, -12);
314 #define BLAKE2S_G2(row1,row2,row3,row4,buf) \
315 row1 = _mm_add_epi32(_mm_add_epi32(row1, buf), row2); \
316 row4 = _mm_xor_si128(row4, row1); \
317 row4 = MM_ROTI_EPI32(row4, -8); \
318 row3 = _mm_add_epi32(row3, row4); \
319 row2 = _mm_xor_si128(row2, row3); \
320 row2 = MM_ROTI_EPI32(row2, -7);
322 #define DIAGONALIZE(row1,row2,row3,row4) \
323 row4 = _mm_shuffle_epi32(row4, _MM_SHUFFLE(2,1,0,3)); \
324 row3 = _mm_shuffle_epi32(row3, _MM_SHUFFLE(1,0,3,2)); \
325 row2 = _mm_shuffle_epi32(row2, _MM_SHUFFLE(0,3,2,1));
327 #define UNDIAGONALIZE(row1,row2,row3,row4) \
328 row4 = _mm_shuffle_epi32(row4, _MM_SHUFFLE(0,3,2,1)); \
329 row3 = _mm_shuffle_epi32(row3, _MM_SHUFFLE(1,0,3,2)); \
330 row2 = _mm_shuffle_epi32(row2, _MM_SHUFFLE(2,1,0,3));
332 #define BLAKE2S_ROUND(r) \
333 BLAKE2S_LOAD_MSG_ ##r ##_1(buf1); \
334 BLAKE2S_G1(row1,row2,row3,row4,buf1); \
335 BLAKE2S_LOAD_MSG_ ##r ##_2(buf2); \
336 BLAKE2S_G2(row1,row2,row3,row4,buf2); \
337 DIAGONALIZE(row1,row2,row3,row4); \
338 BLAKE2S_LOAD_MSG_ ##r ##_3(buf3); \
339 BLAKE2S_G1(row1,row2,row3,row4,buf3); \
340 BLAKE2S_LOAD_MSG_ ##r ##_4(buf4); \
341 BLAKE2S_G2(row1,row2,row3,row4,buf4); \
342 UNDIAGONALIZE(row1,row2,row3,row4);
344 __m128i row1, row2, row3, row4;
345 __m128i buf1, buf2, buf3, buf4;
346 __m128i t0, t1, t2, ff0, ff1;
348 const __m128i r8 = _mm_set_epi8(12, 15, 14, 13, 8, 11, 10, 9, 4, 7, 6, 5, 0, 3, 2, 1);
349 const __m128i r16 = _mm_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);
351 const __m128i m0 = LOADU(input + 00);
352 const __m128i m1 = LOADU(input + 16);
353 const __m128i m2 = LOADU(input + 32);
354 const __m128i m3 = LOADU(input + 48);
356 row1 = ff0 = LOADU(state.h()+0);
357 row2 = ff1 = LOADU(state.h()+4);
358 row3 = LOADU(BLAKE2S_IV+0);
359 row4 = _mm_xor_si128(LOADU(BLAKE2S_IV+4), LOADU(state.t()+0));
372 STOREU(state.h()+0, _mm_xor_si128(ff0, _mm_xor_si128(row1, row3)));
373 STOREU(state.h()+4, _mm_xor_si128(ff1, _mm_xor_si128(row2, row4)));
377 #if CRYPTOPP_ARM_NEON_AVAILABLE
378 void BLAKE2_Compress32_NEON(
const byte* input,
BLAKE2s_State& state)
380 #define BLAKE2S_LOAD_MSG_0_1(buf) \
381 do { uint32x2_t t0, t1; \
382 t0 = vzip_u32(vget_low_u32(m0), vget_high_u32(m0)).val[0]; \
383 t1 = vzip_u32(vget_low_u32(m1), vget_high_u32(m1)).val[0]; \
384 buf = vcombine_u32(t0, t1); } while(0)
386 #define BLAKE2S_LOAD_MSG_0_2(buf) \
387 do { uint32x2_t t0, t1; \
388 t0 = vzip_u32(vget_low_u32(m0), vget_high_u32(m0)).val[1]; \
389 t1 = vzip_u32(vget_low_u32(m1), vget_high_u32(m1)).val[1]; \
390 buf = vcombine_u32(t0, t1); } while(0)
392 #define BLAKE2S_LOAD_MSG_0_3(buf) \
393 do { uint32x2_t t0, t1; \
394 t0 = vzip_u32(vget_low_u32(m2), vget_high_u32(m2)).val[0]; \
395 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m3)).val[0]; \
396 buf = vcombine_u32(t0, t1); } while(0)
398 #define BLAKE2S_LOAD_MSG_0_4(buf) \
399 do { uint32x2_t t0, t1; \
400 t0 = vzip_u32(vget_low_u32(m2), vget_high_u32(m2)).val[1]; \
401 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m3)).val[1]; \
402 buf = vcombine_u32(t0, t1); } while(0)
404 #define BLAKE2S_LOAD_MSG_1_1(buf) \
405 do { uint32x2_t t0, t1; \
406 t0 = vzip_u32(vget_high_u32(m3), vget_low_u32(m1)).val[0]; \
407 t1 = vzip_u32(vget_low_u32(m2), vget_low_u32(m3)).val[1]; \
408 buf = vcombine_u32(t0, t1); } while(0)
410 #define BLAKE2S_LOAD_MSG_1_2(buf) \
411 do { uint32x2_t t0, t1; \
412 t0 = vzip_u32(vget_high_u32(m2), vget_low_u32(m2)).val[0]; \
413 t1 = vext_u32(vget_high_u32(m3), vget_high_u32(m1), 1); \
414 buf = vcombine_u32(t0, t1); } while(0)
416 #define BLAKE2S_LOAD_MSG_1_3(buf) \
417 do { uint32x2_t t0, t1; \
418 t0 = vext_u32(vget_low_u32(m0), vget_low_u32(m0), 1); \
419 t1 = vzip_u32(vget_high_u32(m2), vget_low_u32(m1)).val[1]; \
420 buf = vcombine_u32(t0, t1); } while(0)
422 #define BLAKE2S_LOAD_MSG_1_4(buf) \
423 do { uint32x2_t t0, t1; \
424 t0 = vzip_u32(vget_low_u32(m3), vget_high_u32(m0)).val[0]; \
425 t1 = vzip_u32(vget_high_u32(m1), vget_high_u32(m0)).val[1]; \
426 buf = vcombine_u32(t0, t1); } while(0)
428 #define BLAKE2S_LOAD_MSG_2_1(buf) \
429 do { uint32x2_t t0, t1; \
430 t0 = vext_u32(vget_high_u32(m2), vget_low_u32(m3), 1); \
431 t1 = vzip_u32(vget_low_u32(m1), vget_high_u32(m3)).val[1]; \
432 buf = vcombine_u32(t0, t1); } while(0)
434 #define BLAKE2S_LOAD_MSG_2_2(buf) \
435 do { uint32x2_t t0, t1; \
436 t0 = vzip_u32(vget_low_u32(m2), vget_low_u32(m0)).val[0]; \
437 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_low_u32(m3)); \
438 buf = vcombine_u32(t0, t1); } while(0)
440 #define BLAKE2S_LOAD_MSG_2_3(buf) \
441 do { uint32x2_t t0, t1; \
442 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m2), vget_high_u32(m0)); \
443 t1 = vzip_u32(vget_high_u32(m1), vget_low_u32(m2)).val[1]; \
444 buf = vcombine_u32(t0, t1); } while(0)
446 #define BLAKE2S_LOAD_MSG_2_4(buf) \
447 do { uint32x2_t t0, t1; \
448 t0 = vzip_u32(vget_high_u32(m3), vget_high_u32(m1)).val[0]; \
449 t1 = vext_u32(vget_low_u32(m0), vget_low_u32(m1), 1); \
450 buf = vcombine_u32(t0, t1); } while(0)
452 #define BLAKE2S_LOAD_MSG_3_1(buf) \
453 do { uint32x2_t t0, t1; \
454 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m0)).val[1]; \
455 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m2)).val[1]; \
456 buf = vcombine_u32(t0, t1); } while(0)
458 #define BLAKE2S_LOAD_MSG_3_2(buf) \
459 do { uint32x2_t t0, t1; \
460 t0 = vzip_u32(vget_low_u32(m2), vget_low_u32(m0)).val[1]; \
461 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m3)).val[0]; \
462 buf = vcombine_u32(t0, t1); } while(0)
464 #define BLAKE2S_LOAD_MSG_3_3(buf) \
465 do { uint32x2_t t0, t1; \
466 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_low_u32(m1)); \
467 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_high_u32(m3)); \
468 buf = vcombine_u32(t0, t1); } while(0)
470 #define BLAKE2S_LOAD_MSG_3_4(buf) \
471 do { uint32x2_t t0, t1; \
472 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m2)).val[0]; \
473 t1 = vzip_u32(vget_low_u32(m0), vget_low_u32(m2)).val[0]; \
474 buf = vcombine_u32(t0, t1); } while(0)
476 #define BLAKE2S_LOAD_MSG_4_1(buf) \
477 do { uint32x2_t t0, t1; \
478 t0 = vzip_u32(vget_low_u32(m2), vget_low_u32(m1)).val[1]; \
479 t1 = vzip_u32((vget_high_u32(m0)), vget_high_u32(m2)).val[0]; \
480 buf = vcombine_u32(t0, t1); } while(0)
482 #define BLAKE2S_LOAD_MSG_4_2(buf) \
483 do { uint32x2_t t0, t1; \
484 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m0), vget_high_u32(m1)); \
485 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_high_u32(m3)); \
486 buf = vcombine_u32(t0, t1); } while(0)
488 #define BLAKE2S_LOAD_MSG_4_3(buf) \
489 do { uint32x2_t t0, t1; \
490 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m3), vget_high_u32(m2)); \
491 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m1), vget_high_u32(m0)); \
492 buf = vcombine_u32(t0, t1); } while(0)
494 #define BLAKE2S_LOAD_MSG_4_4(buf) \
495 do { uint32x2_t t0, t1; \
496 t0 = vext_u32(vget_low_u32(m0), vget_low_u32(m3), 1); \
497 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m2), vget_low_u32(m3)); \
498 buf = vcombine_u32(t0, t1); } while(0)
500 #define BLAKE2S_LOAD_MSG_5_1(buf) \
501 do { uint32x2_t t0, t1; \
502 t0 = vzip_u32((vget_high_u32(m0)), vget_high_u32(m1)).val[0]; \
503 t1 = vzip_u32(vget_low_u32(m0), vget_low_u32(m2)).val[0]; \
504 buf = vcombine_u32(t0, t1); } while(0)
506 #define BLAKE2S_LOAD_MSG_5_2(buf) \
507 do { uint32x2_t t0, t1; \
508 t0 = vzip_u32(vget_low_u32(m3), vget_high_u32(m2)).val[0]; \
509 t1 = vzip_u32(vget_high_u32(m2), vget_high_u32(m0)).val[1]; \
510 buf = vcombine_u32(t0, t1); } while(0)
512 #define BLAKE2S_LOAD_MSG_5_3(buf) \
513 do { uint32x2_t t0, t1; \
514 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_high_u32(m1)); \
515 t1 = vzip_u32(vget_high_u32(m3), vget_low_u32(m0)).val[1]; \
516 buf = vcombine_u32(t0, t1); } while(0)
518 #define BLAKE2S_LOAD_MSG_5_4(buf) \
519 do { uint32x2_t t0, t1; \
520 t0 = vzip_u32(vget_low_u32(m3), vget_low_u32(m1)).val[1]; \
521 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m3), vget_low_u32(m2)); \
522 buf = vcombine_u32(t0, t1); } while(0)
524 #define BLAKE2S_LOAD_MSG_6_1(buf) \
525 do { uint32x2_t t0, t1; \
526 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m3), vget_low_u32(m0)); \
527 t1 = vzip_u32(vget_high_u32(m3), vget_low_u32(m1)).val[0]; \
528 buf = vcombine_u32(t0, t1); } while(0)
530 #define BLAKE2S_LOAD_MSG_6_2(buf) \
531 do { uint32x2_t t0, t1; \
532 t0 = vzip_u32(vget_low_u32(m1), vget_high_u32(m3)).val[1]; \
533 t1 = vext_u32(vget_low_u32(m3), vget_high_u32(m2), 1); \
534 buf = vcombine_u32(t0, t1); } while(0)
536 #define BLAKE2S_LOAD_MSG_6_3(buf) \
537 do { uint32x2_t t0, t1; \
538 t0 = vzip_u32(vget_low_u32(m0), vget_high_u32(m1)).val[0]; \
539 t1 = vext_u32(vget_low_u32(m2), vget_low_u32(m2), 1); \
540 buf = vcombine_u32(t0, t1); } while(0)
542 #define BLAKE2S_LOAD_MSG_6_4(buf) \
543 do { uint32x2_t t0, t1; \
544 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m0)).val[1]; \
545 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_high_u32(m2)); \
546 buf = vcombine_u32(t0, t1); } while(0)
548 #define BLAKE2S_LOAD_MSG_7_1(buf) \
549 do { uint32x2_t t0, t1; \
550 t0 = vzip_u32(vget_low_u32(m3), vget_high_u32(m1)).val[1]; \
551 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m3), vget_high_u32(m0)); \
552 buf = vcombine_u32(t0, t1); } while(0)
554 #define BLAKE2S_LOAD_MSG_7_2(buf) \
555 do { uint32x2_t t0, t1; \
556 t0 = vext_u32(vget_high_u32(m2), vget_high_u32(m3), 1); \
557 t1 = vzip_u32(vget_low_u32(m0), vget_low_u32(m2)).val[1]; \
558 buf = vcombine_u32(t0, t1); } while(0)
560 #define BLAKE2S_LOAD_MSG_7_3(buf) \
561 do { uint32x2_t t0, t1; \
562 t0 = vzip_u32(vget_low_u32(m1), vget_high_u32(m3)).val[1]; \
563 t1 = vzip_u32(vget_low_u32(m2), vget_high_u32(m0)).val[0]; \
564 buf = vcombine_u32(t0, t1); } while(0)
566 #define BLAKE2S_LOAD_MSG_7_4(buf) \
567 do { uint32x2_t t0, t1; \
568 t0 = vzip_u32(vget_low_u32(m0), vget_low_u32(m1)).val[0]; \
569 t1 = vzip_u32(vget_high_u32(m1), vget_high_u32(m2)).val[0]; \
570 buf = vcombine_u32(t0, t1); } while(0)
572 #define BLAKE2S_LOAD_MSG_8_1(buf) \
573 do { uint32x2_t t0, t1; \
574 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m3)).val[0]; \
575 t1 = vext_u32(vget_high_u32(m2), vget_low_u32(m0), 1); \
576 buf = vcombine_u32(t0, t1); } while(0)
578 #define BLAKE2S_LOAD_MSG_8_2(buf) \
579 do { uint32x2_t t0, t1; \
580 t0 = vzip_u32(vget_high_u32(m3), vget_low_u32(m2)).val[1]; \
581 t1 = vext_u32(vget_high_u32(m0), vget_low_u32(m2), 1); \
582 buf = vcombine_u32(t0, t1); } while(0)
584 #define BLAKE2S_LOAD_MSG_8_3(buf) \
585 do { uint32x2_t t0, t1; \
586 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m3), vget_low_u32(m3)); \
587 t1 = vext_u32(vget_low_u32(m0), vget_high_u32(m2), 1); \
588 buf = vcombine_u32(t0, t1); } while(0)
590 #define BLAKE2S_LOAD_MSG_8_4(buf) \
591 do { uint32x2_t t0, t1; \
592 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_high_u32(m1)); \
593 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_low_u32(m1)); \
594 buf = vcombine_u32(t0, t1); } while(0)
596 #define BLAKE2S_LOAD_MSG_9_1(buf) \
597 do { uint32x2_t t0, t1; \
598 t0 = vzip_u32(vget_high_u32(m2), vget_low_u32(m2)).val[0]; \
599 t1 = vzip_u32(vget_high_u32(m1), vget_low_u32(m0)).val[1]; \
600 buf = vcombine_u32(t0, t1); } while(0)
602 #define BLAKE2S_LOAD_MSG_9_2(buf) \
603 do { uint32x2_t t0, t1; \
604 t0 = vzip_u32((vget_high_u32(m0)), vget_low_u32(m1)).val[0]; \
605 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m1), vget_low_u32(m1)); \
606 buf = vcombine_u32(t0, t1); } while(0)
608 #define BLAKE2S_LOAD_MSG_9_3(buf) \
609 do { uint32x2_t t0, t1; \
610 t0 = vzip_u32(vget_high_u32(m3), vget_low_u32(m2)).val[1]; \
611 t1 = vzip_u32((vget_high_u32(m0)), vget_low_u32(m3)).val[1]; \
612 buf = vcombine_u32(t0, t1); } while(0)
614 #define BLAKE2S_LOAD_MSG_9_4(buf) \
615 do { uint32x2_t t0, t1; \
616 t0 = vext_u32(vget_high_u32(m2), vget_high_u32(m3), 1); \
617 t1 = vzip_u32(vget_low_u32(m3), vget_low_u32(m0)).val[0]; \
618 buf = vcombine_u32(t0, t1); } while(0)
620 #define vrorq_n_u32_16(x) vreinterpretq_u32_u16(vrev32q_u16(vreinterpretq_u16_u32(x)))
622 #define vrorq_n_u32_8(x) vsriq_n_u32(vshlq_n_u32((x), 24), (x), 8)
624 #define vrorq_n_u32(x, c) vsriq_n_u32(vshlq_n_u32((x), 32-(c)), (x), (c))
626 #define BLAKE2S_G1(row1,row2,row3,row4,buf) \
628 row1 = vaddq_u32(vaddq_u32(row1, buf), row2); row4 = veorq_u32(row4, row1); \
629 row4 = vrorq_n_u32_16(row4); row3 = vaddq_u32(row3, row4); \
630 row2 = veorq_u32(row2, row3); row2 = vrorq_n_u32(row2, 12); \
633 #define BLAKE2S_G2(row1,row2,row3,row4,buf) \
635 row1 = vaddq_u32(vaddq_u32(row1, buf), row2); row4 = veorq_u32(row4, row1); \
636 row4 = vrorq_n_u32_8(row4); row3 = vaddq_u32(row3, row4); \
637 row2 = veorq_u32(row2, row3); row2 = vrorq_n_u32(row2, 7); \
640 #define BLAKE2S_DIAGONALIZE(row1,row2,row3,row4) \
642 row4 = vextq_u32(row4, row4, 3); row3 = vextq_u32(row3, row3, 2); row2 = vextq_u32(row2, row2, 1); \
645 #define BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4) \
647 row4 = vextq_u32(row4, row4, 1); \
648 row3 = vextq_u32(row3, row3, 2); \
649 row2 = vextq_u32(row2, row2, 3); \
652 #define BLAKE2S_ROUND(r) \
654 uint32x4_t buf1, buf2, buf3, buf4; \
655 BLAKE2S_LOAD_MSG_ ##r ##_1(buf1); \
656 BLAKE2S_G1(row1,row2,row3,row4,buf1); \
657 BLAKE2S_LOAD_MSG_ ##r ##_2(buf2); \
658 BLAKE2S_G2(row1,row2,row3,row4,buf2); \
659 BLAKE2S_DIAGONALIZE(row1,row2,row3,row4); \
660 BLAKE2S_LOAD_MSG_ ##r ##_3(buf3); \
661 BLAKE2S_G1(row1,row2,row3,row4,buf3); \
662 BLAKE2S_LOAD_MSG_ ##r ##_4(buf4); \
663 BLAKE2S_G2(row1,row2,row3,row4,buf4); \
664 BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4); \
667 const uint32x4_t m0 = vreinterpretq_u32_u8(vld1q_u8(input + 00));
668 const uint32x4_t m1 = vreinterpretq_u32_u8(vld1q_u8(input + 16));
669 const uint32x4_t m2 = vreinterpretq_u32_u8(vld1q_u8(input + 32));
670 const uint32x4_t m3 = vreinterpretq_u32_u8(vld1q_u8(input + 48));
672 uint32x4_t row1, row2, row3, row4;
674 const uint32x4_t f0 = row1 = vld1q_u32(state.h()+0);
675 const uint32x4_t f1 = row2 = vld1q_u32(state.h()+4);
676 row3 = vld1q_u32(BLAKE2S_IV+0);
677 row4 = veorq_u32(vld1q_u32(BLAKE2S_IV+4), vld1q_u32(state.t()+0));
690 vst1q_u32(state.h()+0, veorq_u32(f0, veorq_u32(row1, row3)));
691 vst1q_u32(state.h()+4, veorq_u32(f1, veorq_u32(row2, row4)));
695 #if (CRYPTOPP_POWER8_AVAILABLE || CRYPTOPP_ALTIVEC_AVAILABLE)
699 return VecLoad((
const word32*)p);
705 const uint8x16_p m = {3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12};
709 return VecLoad((
const word32*)p);
713 inline void VecStore32(
void* p,
const uint32x4_p x)
718 inline void VecStore32LE(
void* p,
const uint32x4_p x)
721 const uint8x16_p m = {3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12};
728 template <
unsigned int E1,
unsigned int E2>
734 enum {X=E1&3, Y=E2&3};
737 const unsigned int DC = 31;
740 if (X == 0 && Y == 0)
742 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
745 else if (X == 0 && Y == 1)
747 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
748 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
750 else if (X == 0 && Y == 2)
752 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
753 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
755 else if (X == 0 && Y == 3)
757 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
758 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
762 else if (X == 1 && Y == 0)
764 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
767 else if (X == 1 && Y == 1)
769 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
770 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
772 else if (X == 1 && Y == 2)
774 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
775 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
777 else if (X == 1 && Y == 3)
779 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
780 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
784 else if (X == 2 && Y == 0)
786 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
789 else if (X == 2 && Y == 1)
791 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
792 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
794 else if (X == 2 && Y == 2)
796 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
797 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
799 else if (X == 2 && Y == 3)
801 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
802 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
806 else if (X == 3 && Y == 0)
808 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
811 else if (X == 3 && Y == 1)
813 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
814 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
816 else if (X == 3 && Y == 2)
818 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
819 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
821 else if (X == 3 && Y == 3)
823 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
824 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
831 template <
unsigned int E1,
unsigned int E2,
unsigned int E3,
unsigned int E4>
836 enum {W=E1&3, X=E2&3, Y=E3&3, Z=E4&3};
842 const uint8x16_p mask = {20,21,22,23, 16,17,18,19, 4,5,6,7, 0,1,2,3};
851 CRYPTOPP_UNUSED(b); CRYPTOPP_UNUSED(d);
852 const uint8x16_p mask = {16,17,18,19, 24,25,26,27, 0,1,2,3, 8,9,10,11};
861 CRYPTOPP_UNUSED(b); CRYPTOPP_UNUSED(d);
862 const uint8x16_p mask = {20,21,22,23, 28,29,30,31, 4,5,6,7, 12,13,14,15};
871 void BLAKE2_Compress32_CORE(
const byte* input,
BLAKE2s_State& state)
890 #define BLAKE2S_LOAD_MSG_0_1(buf) buf = VectorSet32<2,0,2,0>(m6,m4,m2,m0);
892 #define BLAKE2S_LOAD_MSG_0_2(buf) buf = VectorSet32<3,1,3,1>(m7,m5,m3,m1);
894 #define BLAKE2S_LOAD_MSG_0_3(buf) buf = VectorSet32<2,0,2,0>(m14,m12,m10,m8);
896 #define BLAKE2S_LOAD_MSG_0_4(buf) buf = VectorSet32<3,1,3,1>(m15,m13,m11,m9);
898 #define BLAKE2S_LOAD_MSG_1_1(buf) buf = VectorSet32<13,9,4,14>(m13,m9,m4,m14);
899 #define BLAKE2S_LOAD_MSG_1_2(buf) buf = VectorSet32<6,15,8,10>(m6,m15,m8,m10)
900 #define BLAKE2S_LOAD_MSG_1_3(buf) buf = VectorSet32<5,11,0,1>(m5,m11,m0,m1)
901 #define BLAKE2S_LOAD_MSG_1_4(buf) buf = VectorSet32<3,7,2,12>(m3,m7,m2,m12)
903 #define BLAKE2S_LOAD_MSG_2_1(buf) buf = VectorSet32<15,5,12,11>(m15,m5,m12,m11)
904 #define BLAKE2S_LOAD_MSG_2_2(buf) buf = VectorSet32<13,2,0,8>(m13,m2,m0,m8)
905 #define BLAKE2S_LOAD_MSG_2_3(buf) buf = VectorSet32<9,7,3,10>(m9,m7,m3,m10)
906 #define BLAKE2S_LOAD_MSG_2_4(buf) buf = VectorSet32<4,1,6,14>(m4,m1,m6,m14)
908 #define BLAKE2S_LOAD_MSG_3_1(buf) buf = VectorSet32<11,13,3,7>(m11,m13,m3,m7)
909 #define BLAKE2S_LOAD_MSG_3_2(buf) buf = VectorSet32<14,12,1,9>(m14,m12,m1,m9)
910 #define BLAKE2S_LOAD_MSG_3_3(buf) buf = VectorSet32<15,4,5,2>(m15,m4,m5,m2)
911 #define BLAKE2S_LOAD_MSG_3_4(buf) buf = VectorSet32<8,0,10,6>(m8,m0,m10,m6)
913 #define BLAKE2S_LOAD_MSG_4_1(buf) buf = VectorSet32<10,2,5,9>(m10,m2,m5,m9)
914 #define BLAKE2S_LOAD_MSG_4_2(buf) buf = VectorSet32<15,4,7,0>(m15,m4,m7,m0)
915 #define BLAKE2S_LOAD_MSG_4_3(buf) buf = VectorSet32<3,6,11,14>(m3,m6,m11,m14)
916 #define BLAKE2S_LOAD_MSG_4_4(buf) buf = VectorSet32<13,8,12,1>(m13,m8,m12,m1)
918 #define BLAKE2S_LOAD_MSG_5_1(buf) buf = VectorSet32<8,0,6,2>(m8,m0,m6,m2)
919 #define BLAKE2S_LOAD_MSG_5_2(buf) buf = VectorSet32<3,11,10,12>(m3,m11,m10,m12)
920 #define BLAKE2S_LOAD_MSG_5_3(buf) buf = VectorSet32<1,15,7,4>(m1,m15,m7,m4)
921 #define BLAKE2S_LOAD_MSG_5_4(buf) buf = VectorSet32<9,14,5,13>(m9,m14,m5,m13)
923 #define BLAKE2S_LOAD_MSG_6_1(buf) buf = VectorSet32<4,14,1,12>(m4,m14,m1,m12)
924 #define BLAKE2S_LOAD_MSG_6_2(buf) buf = VectorSet32<10,13,15,5>(m10,m13,m15,m5)
925 #define BLAKE2S_LOAD_MSG_6_3(buf) buf = VectorSet32<8,9,6,0>(m8,m9,m6,m0)
926 #define BLAKE2S_LOAD_MSG_6_4(buf) buf = VectorSet32<11,2,3,7>(m11,m2,m3,m7)
928 #define BLAKE2S_LOAD_MSG_7_1(buf) buf = VectorSet32<3,12,7,13>(m3,m12,m7,m13)
929 #define BLAKE2S_LOAD_MSG_7_2(buf) buf = VectorSet32<9,1,14,11>(m9,m1,m14,m11)
930 #define BLAKE2S_LOAD_MSG_7_3(buf) buf = VectorSet32<2,8,15,5>(m2,m8,m15,m5)
931 #define BLAKE2S_LOAD_MSG_7_4(buf) buf = VectorSet32<10,6,4,0>(m10,m6,m4,m0)
933 #define BLAKE2S_LOAD_MSG_8_1(buf) buf = VectorSet32<0,11,14,6>(m0,m11,m14,m6)
934 #define BLAKE2S_LOAD_MSG_8_2(buf) buf = VectorSet32<8,3,9,15>(m8,m3,m9,m15)
935 #define BLAKE2S_LOAD_MSG_8_3(buf) buf = VectorSet32<10,1,13,12>(m10,m1,m13,m12)
936 #define BLAKE2S_LOAD_MSG_8_4(buf) buf = VectorSet32<5,4,7,2>(m5,m4,m7,m2)
938 #define BLAKE2S_LOAD_MSG_9_1(buf) buf = VectorSet32<1,7,8,10>(m1,m7,m8,m10)
939 #define BLAKE2S_LOAD_MSG_9_2(buf) buf = VectorSet32<5,6,4,2>(m5,m6,m4,m2)
940 #define BLAKE2S_LOAD_MSG_9_3(buf) buf = VectorSet32<13,3,9,15>(m13,m3,m9,m15)
941 #define BLAKE2S_LOAD_MSG_9_4(buf) buf = VectorSet32<0,12,14,11>(m0,m12,m14,m11)
943 #define vec_ror_16(x) VecRotateRight<16>(x)
944 #define vec_ror_12(x) VecRotateRight<12>(x)
945 #define vec_ror_8(x) VecRotateRight<8>(x)
946 #define vec_ror_7(x) VecRotateRight<7>(x)
948 #define BLAKE2S_G1(row1,row2,row3,row4,buf) \
949 row1 = VecAdd(VecAdd(row1, buf), row2); \
950 row4 = VecXor(row4, row1); \
951 row4 = vec_ror_16(row4); \
952 row3 = VecAdd(row3, row4); \
953 row2 = VecXor(row2, row3); \
954 row2 = vec_ror_12(row2);
956 #define BLAKE2S_G2(row1,row2,row3,row4,buf) \
957 row1 = VecAdd(VecAdd(row1, buf), row2); \
958 row4 = VecXor(row4, row1); \
959 row4 = vec_ror_8(row4); \
960 row3 = VecAdd(row3, row4); \
961 row2 = VecXor(row2, row3); \
962 row2 = vec_ror_7(row2);
964 const uint8x16_p D2103_MASK = {12,13,14,15, 0,1,2,3, 4,5,6,7, 8,9,10,11};
965 const uint8x16_p D1032_MASK = {8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7};
966 const uint8x16_p D0321_MASK = {4,5,6,7, 8,9,10,11, 12,13,14,15, 0,1,2,3};
968 #define BLAKE2S_DIAGONALIZE(row1,row2,row3,row4) \
969 row4 = VecPermute(row4, row4, D2103_MASK); \
970 row3 = VecPermute(row3, row3, D1032_MASK); \
971 row2 = VecPermute(row2, row2, D0321_MASK);
973 #define BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4) \
974 row4 = VecPermute(row4, row4, D0321_MASK); \
975 row3 = VecPermute(row3, row3, D1032_MASK); \
976 row2 = VecPermute(row2, row2, D2103_MASK);
978 #define BLAKE2S_ROUND(r) \
979 BLAKE2S_LOAD_MSG_ ##r ##_1(buf1); \
980 BLAKE2S_G1(row1,row2,row3,row4,buf1); \
981 BLAKE2S_LOAD_MSG_ ##r ##_2(buf2); \
982 BLAKE2S_G2(row1,row2,row3,row4,buf2); \
983 BLAKE2S_DIAGONALIZE(row1,row2,row3,row4); \
984 BLAKE2S_LOAD_MSG_ ##r ##_3(buf3); \
985 BLAKE2S_G1(row1,row2,row3,row4,buf3); \
986 BLAKE2S_LOAD_MSG_ ##r ##_4(buf4); \
987 BLAKE2S_G2(row1,row2,row3,row4,buf4); \
988 BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4);
995 const uint32x4_p m4 = VecLoad32LE(input + 16);
996 const uint32x4_p m8 = VecLoad32LE(input + 32);
997 const uint32x4_p m12 = VecLoad32LE(input + 48);
999 row1 = ff0 = VecLoad32LE(state.h()+0);
1000 row2 = ff1 = VecLoad32LE(state.h()+4);
1001 row3 = VecLoad32(BLAKE2S_IV+0);
1002 row4 =
VecXor(VecLoad32(BLAKE2S_IV+4), VecLoad32(state.t()+0));
1015 VecStore32LE(state.h()+0,
VecXor(ff0,
VecXor(row1, row3)));
1016 VecStore32LE(state.h()+4,
VecXor(ff1,
VecXor(row2, row4)));
1020 #if (CRYPTOPP_POWER8_AVAILABLE)
1022 void BLAKE2_Compress32_POWER8(
const byte* input,
BLAKE2s_State& state)
1024 BLAKE2_Compress32_CORE(input, state);
1027 #elif (CRYPTOPP_ALTIVEC_AVAILABLE)
1029 void BLAKE2_Compress32_ALTIVEC(
const byte* input,
BLAKE2s_State& state)
1031 BLAKE2_Compress32_CORE(input, state);
Classes for BLAKE2b and BLAKE2s message digests and keyed message digests.
Library configuration file.
Utility functions for the Crypto++ library.
Crypto++ library namespace.
Support functions for PowerPC and vector operations.
__vector unsigned int uint32x4_p
Vector of 32-bit elements.
T1 VecPermute(const T1 vec, const T2 mask)
Permutes a vector.
__vector unsigned char uint8x16_p
Vector of 8-bit elements.
T1 VecXor(const T1 vec1, const T2 vec2)
XOR two vectors.
void VecStore(const T data, byte dest[16])
Stores a vector to a byte array.
uint32x4_p VecLoad(const byte src[16])
Loads a vector from a byte array.
BLAKE2s state information.