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 # define CRYPTOPP_POWER7_ALTIVEC 1 42 # undef CRYPTOPP_POWER7_AVAILABLE 43 # undef CRYPTOPP_ALTIVEC_AVAILABLE 46 #if (CRYPTOPP_SSE41_AVAILABLE) 47 # include <emmintrin.h> 48 # include <tmmintrin.h> 49 # include <smmintrin.h> 52 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 53 # include <arm_neon.h> 58 #if (CRYPTOPP_ARM_ACLE_AVAILABLE) 60 # include <arm_acle.h> 63 #if (CRYPTOPP_ALTIVEC_AVAILABLE) 68 extern const char BLAKE2S_SIMD_FNAME[] = __FILE__;
73 extern const word32 BLAKE2S_IV[8];
74 extern const word64 BLAKE2B_IV[8];
76 #if CRYPTOPP_SSE41_AVAILABLE 78 #define LOADU(p) _mm_loadu_si128((const __m128i *)(const void*)(p)) 79 #define STOREU(p,r) _mm_storeu_si128((__m128i *)(void*)(p), r) 80 #define TOF(reg) _mm_castsi128_ps((reg)) 81 #define TOI(reg) _mm_castps_si128((reg)) 83 void BLAKE2_Compress32_SSE4(
const byte* input,
BLAKE2s_State& state)
85 #define BLAKE2S_LOAD_MSG_0_1(buf) \ 86 buf = TOI(_mm_shuffle_ps(TOF(m0), TOF(m1), _MM_SHUFFLE(2,0,2,0))); 88 #define BLAKE2S_LOAD_MSG_0_2(buf) \ 89 buf = TOI(_mm_shuffle_ps(TOF(m0), TOF(m1), _MM_SHUFFLE(3,1,3,1))); 91 #define BLAKE2S_LOAD_MSG_0_3(buf) \ 92 buf = TOI(_mm_shuffle_ps(TOF(m2), TOF(m3), _MM_SHUFFLE(2,0,2,0))); 94 #define BLAKE2S_LOAD_MSG_0_4(buf) \ 95 buf = TOI(_mm_shuffle_ps(TOF(m2), TOF(m3), _MM_SHUFFLE(3,1,3,1))); 97 #define BLAKE2S_LOAD_MSG_1_1(buf) \ 98 t0 = _mm_blend_epi16(m1, m2, 0x0C); \ 99 t1 = _mm_slli_si128(m3, 4); \ 100 t2 = _mm_blend_epi16(t0, t1, 0xF0); \ 101 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,1,0,3)); 103 #define BLAKE2S_LOAD_MSG_1_2(buf) \ 104 t0 = _mm_shuffle_epi32(m2,_MM_SHUFFLE(0,0,2,0)); \ 105 t1 = _mm_blend_epi16(m1,m3,0xC0); \ 106 t2 = _mm_blend_epi16(t0, t1, 0xF0); \ 107 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1)); 109 #define BLAKE2S_LOAD_MSG_1_3(buf) \ 110 t0 = _mm_slli_si128(m1, 4); \ 111 t1 = _mm_blend_epi16(m2, t0, 0x30); \ 112 t2 = _mm_blend_epi16(m0, t1, 0xF0); \ 113 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1)); 115 #define BLAKE2S_LOAD_MSG_1_4(buf) \ 116 t0 = _mm_unpackhi_epi32(m0,m1); \ 117 t1 = _mm_slli_si128(m3, 4); \ 118 t2 = _mm_blend_epi16(t0, t1, 0x0C); \ 119 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,3,0,1)); 121 #define BLAKE2S_LOAD_MSG_2_1(buf) \ 122 t0 = _mm_unpackhi_epi32(m2,m3); \ 123 t1 = _mm_blend_epi16(m3,m1,0x0C); \ 124 t2 = _mm_blend_epi16(t0, t1, 0x0F); \ 125 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(3,1,0,2)); 127 #define BLAKE2S_LOAD_MSG_2_2(buf) \ 128 t0 = _mm_unpacklo_epi32(m2,m0); \ 129 t1 = _mm_blend_epi16(t0, m0, 0xF0); \ 130 t2 = _mm_slli_si128(m3, 8); \ 131 buf = _mm_blend_epi16(t1, t2, 0xC0); 133 #define BLAKE2S_LOAD_MSG_2_3(buf) \ 134 t0 = _mm_blend_epi16(m0, m2, 0x3C); \ 135 t1 = _mm_srli_si128(m1, 12); \ 136 t2 = _mm_blend_epi16(t0,t1,0x03); \ 137 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,0,3,2)); 139 #define BLAKE2S_LOAD_MSG_2_4(buf) \ 140 t0 = _mm_slli_si128(m3, 4); \ 141 t1 = _mm_blend_epi16(m0, m1, 0x33); \ 142 t2 = _mm_blend_epi16(t1, t0, 0xC0); \ 143 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(0,1,2,3)); 145 #define BLAKE2S_LOAD_MSG_3_1(buf) \ 146 t0 = _mm_unpackhi_epi32(m0,m1); \ 147 t1 = _mm_unpackhi_epi32(t0, m2); \ 148 t2 = _mm_blend_epi16(t1, m3, 0x0C); \ 149 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(3,1,0,2)); 151 #define BLAKE2S_LOAD_MSG_3_2(buf) \ 152 t0 = _mm_slli_si128(m2, 8); \ 153 t1 = _mm_blend_epi16(m3,m0,0x0C); \ 154 t2 = _mm_blend_epi16(t1, t0, 0xC0); \ 155 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,0,1,3)); 157 #define BLAKE2S_LOAD_MSG_3_3(buf) \ 158 t0 = _mm_blend_epi16(m0,m1,0x0F); \ 159 t1 = _mm_blend_epi16(t0, m3, 0xC0); \ 160 buf = _mm_shuffle_epi32(t1, _MM_SHUFFLE(3,0,1,2)); 162 #define BLAKE2S_LOAD_MSG_3_4(buf) \ 163 t0 = _mm_unpacklo_epi32(m0,m2); \ 164 t1 = _mm_unpackhi_epi32(m1,m2); \ 165 buf = _mm_unpacklo_epi64(t1,t0); 167 #define BLAKE2S_LOAD_MSG_4_1(buf) \ 168 t0 = _mm_unpacklo_epi64(m1,m2); \ 169 t1 = _mm_unpackhi_epi64(m0,m2); \ 170 t2 = _mm_blend_epi16(t0,t1,0x33); \ 171 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,0,1,3)); 173 #define BLAKE2S_LOAD_MSG_4_2(buf) \ 174 t0 = _mm_unpackhi_epi64(m1,m3); \ 175 t1 = _mm_unpacklo_epi64(m0,m1); \ 176 buf = _mm_blend_epi16(t0,t1,0x33); 178 #define BLAKE2S_LOAD_MSG_4_3(buf) \ 179 t0 = _mm_unpackhi_epi64(m3,m1); \ 180 t1 = _mm_unpackhi_epi64(m2,m0); \ 181 buf = _mm_blend_epi16(t1,t0,0x33); 183 #define BLAKE2S_LOAD_MSG_4_4(buf) \ 184 t0 = _mm_blend_epi16(m0,m2,0x03); \ 185 t1 = _mm_slli_si128(t0, 8); \ 186 t2 = _mm_blend_epi16(t1,m3,0x0F); \ 187 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,2,0,3)); 189 #define BLAKE2S_LOAD_MSG_5_1(buf) \ 190 t0 = _mm_unpackhi_epi32(m0,m1); \ 191 t1 = _mm_unpacklo_epi32(m0,m2); \ 192 buf = _mm_unpacklo_epi64(t0,t1); 194 #define BLAKE2S_LOAD_MSG_5_2(buf) \ 195 t0 = _mm_srli_si128(m2, 4); \ 196 t1 = _mm_blend_epi16(m0,m3,0x03); \ 197 buf = _mm_blend_epi16(t1,t0,0x3C); 199 #define BLAKE2S_LOAD_MSG_5_3(buf) \ 200 t0 = _mm_blend_epi16(m1,m0,0x0C); \ 201 t1 = _mm_srli_si128(m3, 4); \ 202 t2 = _mm_blend_epi16(t0,t1,0x30); \ 203 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,2,3,0)); 205 #define BLAKE2S_LOAD_MSG_5_4(buf) \ 206 t0 = _mm_unpacklo_epi64(m1,m2); \ 207 t1= _mm_shuffle_epi32(m3, _MM_SHUFFLE(0,2,0,1)); \ 208 buf = _mm_blend_epi16(t0,t1,0x33); 210 #define BLAKE2S_LOAD_MSG_6_1(buf) \ 211 t0 = _mm_slli_si128(m1, 12); \ 212 t1 = _mm_blend_epi16(m0,m3,0x33); \ 213 buf = _mm_blend_epi16(t1,t0,0xC0); 215 #define BLAKE2S_LOAD_MSG_6_2(buf) \ 216 t0 = _mm_blend_epi16(m3,m2,0x30); \ 217 t1 = _mm_srli_si128(m1, 4); \ 218 t2 = _mm_blend_epi16(t0,t1,0x03); \ 219 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(2,1,3,0)); 221 #define BLAKE2S_LOAD_MSG_6_3(buf) \ 222 t0 = _mm_unpacklo_epi64(m0,m2); \ 223 t1 = _mm_srli_si128(m1, 4); \ 224 buf = _mm_shuffle_epi32(_mm_blend_epi16(t0,t1,0x0C), _MM_SHUFFLE(2,3,1,0)); 226 #define BLAKE2S_LOAD_MSG_6_4(buf) \ 227 t0 = _mm_unpackhi_epi32(m1,m2); \ 228 t1 = _mm_unpackhi_epi64(m0,t0); \ 229 buf = _mm_shuffle_epi32(t1, _MM_SHUFFLE(3,0,1,2)); 231 #define BLAKE2S_LOAD_MSG_7_1(buf) \ 232 t0 = _mm_unpackhi_epi32(m0,m1); \ 233 t1 = _mm_blend_epi16(t0,m3,0x0F); \ 234 buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(2,0,3,1)); 236 #define BLAKE2S_LOAD_MSG_7_2(buf) \ 237 t0 = _mm_blend_epi16(m2,m3,0x30); \ 238 t1 = _mm_srli_si128(m0,4); \ 239 t2 = _mm_blend_epi16(t0,t1,0x03); \ 240 buf = _mm_shuffle_epi32(t2, _MM_SHUFFLE(1,0,2,3)); 242 #define BLAKE2S_LOAD_MSG_7_3(buf) \ 243 t0 = _mm_unpackhi_epi64(m0,m3); \ 244 t1 = _mm_unpacklo_epi64(m1,m2); \ 245 t2 = _mm_blend_epi16(t0,t1,0x3C); \ 246 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(0,2,3,1)); 248 #define BLAKE2S_LOAD_MSG_7_4(buf) \ 249 t0 = _mm_unpacklo_epi32(m0,m1); \ 250 t1 = _mm_unpackhi_epi32(m1,m2); \ 251 buf = _mm_unpacklo_epi64(t0,t1); 253 #define BLAKE2S_LOAD_MSG_8_1(buf) \ 254 t0 = _mm_unpackhi_epi32(m1,m3); \ 255 t1 = _mm_unpacklo_epi64(t0,m0); \ 256 t2 = _mm_blend_epi16(t1,m2,0xC0); \ 257 buf = _mm_shufflehi_epi16(t2,_MM_SHUFFLE(1,0,3,2)); 259 #define BLAKE2S_LOAD_MSG_8_2(buf) \ 260 t0 = _mm_unpackhi_epi32(m0,m3); \ 261 t1 = _mm_blend_epi16(m2,t0,0xF0); \ 262 buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(0,2,1,3)); 264 #define BLAKE2S_LOAD_MSG_8_3(buf) \ 265 t0 = _mm_blend_epi16(m2,m0,0x0C); \ 266 t1 = _mm_slli_si128(t0,4); \ 267 buf = _mm_blend_epi16(t1,m3,0x0F); 269 #define BLAKE2S_LOAD_MSG_8_4(buf) \ 270 t0 = _mm_blend_epi16(m1,m0,0x30); \ 271 buf = _mm_shuffle_epi32(t0,_MM_SHUFFLE(1,0,3,2)); 273 #define BLAKE2S_LOAD_MSG_9_1(buf) \ 274 t0 = _mm_blend_epi16(m0,m2,0x03); \ 275 t1 = _mm_blend_epi16(m1,m2,0x30); \ 276 t2 = _mm_blend_epi16(t1,t0,0x0F); \ 277 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(1,3,0,2)); 279 #define BLAKE2S_LOAD_MSG_9_2(buf) \ 280 t0 = _mm_slli_si128(m0,4); \ 281 t1 = _mm_blend_epi16(m1,t0,0xC0); \ 282 buf = _mm_shuffle_epi32(t1,_MM_SHUFFLE(1,2,0,3)); 284 #define BLAKE2S_LOAD_MSG_9_3(buf) \ 285 t0 = _mm_unpackhi_epi32(m0,m3); \ 286 t1 = _mm_unpacklo_epi32(m2,m3); \ 287 t2 = _mm_unpackhi_epi64(t0,t1); \ 288 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(3,0,2,1)); 290 #define BLAKE2S_LOAD_MSG_9_4(buf) \ 291 t0 = _mm_blend_epi16(m3,m2,0xC0); \ 292 t1 = _mm_unpacklo_epi32(m0,m3); \ 293 t2 = _mm_blend_epi16(t0,t1,0x0F); \ 294 buf = _mm_shuffle_epi32(t2,_MM_SHUFFLE(0,1,2,3)); 297 # define MM_ROTI_EPI32(r, c) \ 300 # define MM_ROTI_EPI32(r, c) ( \ 301 (8==-(c)) ? _mm_shuffle_epi8(r,r8) \ 302 : (16==-(c)) ? _mm_shuffle_epi8(r,r16) \ 303 : _mm_xor_si128(_mm_srli_epi32((r), -(c)), \ 304 _mm_slli_epi32((r), 32-(-(c))))) 307 #define BLAKE2S_G1(row1,row2,row3,row4,buf) \ 308 row1 = _mm_add_epi32(_mm_add_epi32(row1, buf), row2); \ 309 row4 = _mm_xor_si128(row4, row1); \ 310 row4 = MM_ROTI_EPI32(row4, -16); \ 311 row3 = _mm_add_epi32(row3, row4); \ 312 row2 = _mm_xor_si128(row2, row3); \ 313 row2 = MM_ROTI_EPI32(row2, -12); 315 #define BLAKE2S_G2(row1,row2,row3,row4,buf) \ 316 row1 = _mm_add_epi32(_mm_add_epi32(row1, buf), row2); \ 317 row4 = _mm_xor_si128(row4, row1); \ 318 row4 = MM_ROTI_EPI32(row4, -8); \ 319 row3 = _mm_add_epi32(row3, row4); \ 320 row2 = _mm_xor_si128(row2, row3); \ 321 row2 = MM_ROTI_EPI32(row2, -7); 323 #define DIAGONALIZE(row1,row2,row3,row4) \ 324 row4 = _mm_shuffle_epi32(row4, _MM_SHUFFLE(2,1,0,3)); \ 325 row3 = _mm_shuffle_epi32(row3, _MM_SHUFFLE(1,0,3,2)); \ 326 row2 = _mm_shuffle_epi32(row2, _MM_SHUFFLE(0,3,2,1)); 328 #define UNDIAGONALIZE(row1,row2,row3,row4) \ 329 row4 = _mm_shuffle_epi32(row4, _MM_SHUFFLE(0,3,2,1)); \ 330 row3 = _mm_shuffle_epi32(row3, _MM_SHUFFLE(1,0,3,2)); \ 331 row2 = _mm_shuffle_epi32(row2, _MM_SHUFFLE(2,1,0,3)); 333 #define BLAKE2S_ROUND(r) \ 334 BLAKE2S_LOAD_MSG_ ##r ##_1(buf1); \ 335 BLAKE2S_G1(row1,row2,row3,row4,buf1); \ 336 BLAKE2S_LOAD_MSG_ ##r ##_2(buf2); \ 337 BLAKE2S_G2(row1,row2,row3,row4,buf2); \ 338 DIAGONALIZE(row1,row2,row3,row4); \ 339 BLAKE2S_LOAD_MSG_ ##r ##_3(buf3); \ 340 BLAKE2S_G1(row1,row2,row3,row4,buf3); \ 341 BLAKE2S_LOAD_MSG_ ##r ##_4(buf4); \ 342 BLAKE2S_G2(row1,row2,row3,row4,buf4); \ 343 UNDIAGONALIZE(row1,row2,row3,row4); 345 __m128i row1, row2, row3, row4;
346 __m128i buf1, buf2, buf3, buf4;
347 __m128i t0, t1, t2, ff0, ff1;
349 const __m128i r8 = _mm_set_epi8(12, 15, 14, 13, 8, 11, 10, 9, 4, 7, 6, 5, 0, 3, 2, 1);
350 const __m128i r16 = _mm_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);
352 const __m128i m0 = LOADU(input + 00);
353 const __m128i m1 = LOADU(input + 16);
354 const __m128i m2 = LOADU(input + 32);
355 const __m128i m3 = LOADU(input + 48);
357 row1 = ff0 = LOADU(state.h()+0);
358 row2 = ff1 = LOADU(state.h()+4);
359 row3 = LOADU(BLAKE2S_IV+0);
360 row4 = _mm_xor_si128(LOADU(BLAKE2S_IV+4), LOADU(state.t()+0));
373 STOREU(state.h()+0, _mm_xor_si128(ff0, _mm_xor_si128(row1, row3)));
374 STOREU(state.h()+4, _mm_xor_si128(ff1, _mm_xor_si128(row2, row4)));
376 #endif // CRYPTOPP_SSE41_AVAILABLE 378 #if CRYPTOPP_ARM_NEON_AVAILABLE 379 void BLAKE2_Compress32_NEON(
const byte* input,
BLAKE2s_State& state)
381 #define BLAKE2S_LOAD_MSG_0_1(buf) \ 382 do { uint32x2_t t0, t1; \ 383 t0 = vzip_u32(vget_low_u32(m0), vget_high_u32(m0)).val[0]; \ 384 t1 = vzip_u32(vget_low_u32(m1), vget_high_u32(m1)).val[0]; \ 385 buf = vcombine_u32(t0, t1); } while(0) 387 #define BLAKE2S_LOAD_MSG_0_2(buf) \ 388 do { uint32x2_t t0, t1; \ 389 t0 = vzip_u32(vget_low_u32(m0), vget_high_u32(m0)).val[1]; \ 390 t1 = vzip_u32(vget_low_u32(m1), vget_high_u32(m1)).val[1]; \ 391 buf = vcombine_u32(t0, t1); } while(0) 393 #define BLAKE2S_LOAD_MSG_0_3(buf) \ 394 do { uint32x2_t t0, t1; \ 395 t0 = vzip_u32(vget_low_u32(m2), vget_high_u32(m2)).val[0]; \ 396 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m3)).val[0]; \ 397 buf = vcombine_u32(t0, t1); } while(0) 399 #define BLAKE2S_LOAD_MSG_0_4(buf) \ 400 do { uint32x2_t t0, t1; \ 401 t0 = vzip_u32(vget_low_u32(m2), vget_high_u32(m2)).val[1]; \ 402 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m3)).val[1]; \ 403 buf = vcombine_u32(t0, t1); } while(0) 405 #define BLAKE2S_LOAD_MSG_1_1(buf) \ 406 do { uint32x2_t t0, t1; \ 407 t0 = vzip_u32(vget_high_u32(m3), vget_low_u32(m1)).val[0]; \ 408 t1 = vzip_u32(vget_low_u32(m2), vget_low_u32(m3)).val[1]; \ 409 buf = vcombine_u32(t0, t1); } while(0) 411 #define BLAKE2S_LOAD_MSG_1_2(buf) \ 412 do { uint32x2_t t0, t1; \ 413 t0 = vzip_u32(vget_high_u32(m2), vget_low_u32(m2)).val[0]; \ 414 t1 = vext_u32(vget_high_u32(m3), vget_high_u32(m1), 1); \ 415 buf = vcombine_u32(t0, t1); } while(0) 417 #define BLAKE2S_LOAD_MSG_1_3(buf) \ 418 do { uint32x2_t t0, t1; \ 419 t0 = vext_u32(vget_low_u32(m0), vget_low_u32(m0), 1); \ 420 t1 = vzip_u32(vget_high_u32(m2), vget_low_u32(m1)).val[1]; \ 421 buf = vcombine_u32(t0, t1); } while(0) 423 #define BLAKE2S_LOAD_MSG_1_4(buf) \ 424 do { uint32x2_t t0, t1; \ 425 t0 = vzip_u32(vget_low_u32(m3), vget_high_u32(m0)).val[0]; \ 426 t1 = vzip_u32(vget_high_u32(m1), vget_high_u32(m0)).val[1]; \ 427 buf = vcombine_u32(t0, t1); } while(0) 429 #define BLAKE2S_LOAD_MSG_2_1(buf) \ 430 do { uint32x2_t t0, t1; \ 431 t0 = vext_u32(vget_high_u32(m2), vget_low_u32(m3), 1); \ 432 t1 = vzip_u32(vget_low_u32(m1), vget_high_u32(m3)).val[1]; \ 433 buf = vcombine_u32(t0, t1); } while(0) 435 #define BLAKE2S_LOAD_MSG_2_2(buf) \ 436 do { uint32x2_t t0, t1; \ 437 t0 = vzip_u32(vget_low_u32(m2), vget_low_u32(m0)).val[0]; \ 438 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_low_u32(m3)); \ 439 buf = vcombine_u32(t0, t1); } while(0) 441 #define BLAKE2S_LOAD_MSG_2_3(buf) \ 442 do { uint32x2_t t0, t1; \ 443 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m2), vget_high_u32(m0)); \ 444 t1 = vzip_u32(vget_high_u32(m1), vget_low_u32(m2)).val[1]; \ 445 buf = vcombine_u32(t0, t1); } while(0) 447 #define BLAKE2S_LOAD_MSG_2_4(buf) \ 448 do { uint32x2_t t0, t1; \ 449 t0 = vzip_u32(vget_high_u32(m3), vget_high_u32(m1)).val[0]; \ 450 t1 = vext_u32(vget_low_u32(m0), vget_low_u32(m1), 1); \ 451 buf = vcombine_u32(t0, t1); } while(0) 453 #define BLAKE2S_LOAD_MSG_3_1(buf) \ 454 do { uint32x2_t t0, t1; \ 455 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m0)).val[1]; \ 456 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m2)).val[1]; \ 457 buf = vcombine_u32(t0, t1); } while(0) 459 #define BLAKE2S_LOAD_MSG_3_2(buf) \ 460 do { uint32x2_t t0, t1; \ 461 t0 = vzip_u32(vget_low_u32(m2), vget_low_u32(m0)).val[1]; \ 462 t1 = vzip_u32(vget_low_u32(m3), vget_high_u32(m3)).val[0]; \ 463 buf = vcombine_u32(t0, t1); } while(0) 465 #define BLAKE2S_LOAD_MSG_3_3(buf) \ 466 do { uint32x2_t t0, t1; \ 467 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_low_u32(m1)); \ 468 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_high_u32(m3)); \ 469 buf = vcombine_u32(t0, t1); } while(0) 471 #define BLAKE2S_LOAD_MSG_3_4(buf) \ 472 do { uint32x2_t t0, t1; \ 473 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m2)).val[0]; \ 474 t1 = vzip_u32(vget_low_u32(m0), vget_low_u32(m2)).val[0]; \ 475 buf = vcombine_u32(t0, t1); } while(0) 477 #define BLAKE2S_LOAD_MSG_4_1(buf) \ 478 do { uint32x2_t t0, t1; \ 479 t0 = vzip_u32(vget_low_u32(m2), vget_low_u32(m1)).val[1]; \ 480 t1 = vzip_u32((vget_high_u32(m0)), vget_high_u32(m2)).val[0]; \ 481 buf = vcombine_u32(t0, t1); } while(0) 483 #define BLAKE2S_LOAD_MSG_4_2(buf) \ 484 do { uint32x2_t t0, t1; \ 485 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m0), vget_high_u32(m1)); \ 486 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_high_u32(m3)); \ 487 buf = vcombine_u32(t0, t1); } while(0) 489 #define BLAKE2S_LOAD_MSG_4_3(buf) \ 490 do { uint32x2_t t0, t1; \ 491 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m3), vget_high_u32(m2)); \ 492 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m1), vget_high_u32(m0)); \ 493 buf = vcombine_u32(t0, t1); } while(0) 495 #define BLAKE2S_LOAD_MSG_4_4(buf) \ 496 do { uint32x2_t t0, t1; \ 497 t0 = vext_u32(vget_low_u32(m0), vget_low_u32(m3), 1); \ 498 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m2), vget_low_u32(m3)); \ 499 buf = vcombine_u32(t0, t1); } while(0) 501 #define BLAKE2S_LOAD_MSG_5_1(buf) \ 502 do { uint32x2_t t0, t1; \ 503 t0 = vzip_u32((vget_high_u32(m0)), vget_high_u32(m1)).val[0]; \ 504 t1 = vzip_u32(vget_low_u32(m0), vget_low_u32(m2)).val[0]; \ 505 buf = vcombine_u32(t0, t1); } while(0) 507 #define BLAKE2S_LOAD_MSG_5_2(buf) \ 508 do { uint32x2_t t0, t1; \ 509 t0 = vzip_u32(vget_low_u32(m3), vget_high_u32(m2)).val[0]; \ 510 t1 = vzip_u32(vget_high_u32(m2), vget_high_u32(m0)).val[1]; \ 511 buf = vcombine_u32(t0, t1); } while(0) 513 #define BLAKE2S_LOAD_MSG_5_3(buf) \ 514 do { uint32x2_t t0, t1; \ 515 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_high_u32(m1)); \ 516 t1 = vzip_u32(vget_high_u32(m3), vget_low_u32(m0)).val[1]; \ 517 buf = vcombine_u32(t0, t1); } while(0) 519 #define BLAKE2S_LOAD_MSG_5_4(buf) \ 520 do { uint32x2_t t0, t1; \ 521 t0 = vzip_u32(vget_low_u32(m3), vget_low_u32(m1)).val[1]; \ 522 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m3), vget_low_u32(m2)); \ 523 buf = vcombine_u32(t0, t1); } while(0) 525 #define BLAKE2S_LOAD_MSG_6_1(buf) \ 526 do { uint32x2_t t0, t1; \ 527 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m3), vget_low_u32(m0)); \ 528 t1 = vzip_u32(vget_high_u32(m3), vget_low_u32(m1)).val[0]; \ 529 buf = vcombine_u32(t0, t1); } while(0) 531 #define BLAKE2S_LOAD_MSG_6_2(buf) \ 532 do { uint32x2_t t0, t1; \ 533 t0 = vzip_u32(vget_low_u32(m1), vget_high_u32(m3)).val[1]; \ 534 t1 = vext_u32(vget_low_u32(m3), vget_high_u32(m2), 1); \ 535 buf = vcombine_u32(t0, t1); } while(0) 537 #define BLAKE2S_LOAD_MSG_6_3(buf) \ 538 do { uint32x2_t t0, t1; \ 539 t0 = vzip_u32(vget_low_u32(m0), vget_high_u32(m1)).val[0]; \ 540 t1 = vext_u32(vget_low_u32(m2), vget_low_u32(m2), 1); \ 541 buf = vcombine_u32(t0, t1); } while(0) 543 #define BLAKE2S_LOAD_MSG_6_4(buf) \ 544 do { uint32x2_t t0, t1; \ 545 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m0)).val[1]; \ 546 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_high_u32(m2)); \ 547 buf = vcombine_u32(t0, t1); } while(0) 549 #define BLAKE2S_LOAD_MSG_7_1(buf) \ 550 do { uint32x2_t t0, t1; \ 551 t0 = vzip_u32(vget_low_u32(m3), vget_high_u32(m1)).val[1]; \ 552 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m3), vget_high_u32(m0)); \ 553 buf = vcombine_u32(t0, t1); } while(0) 555 #define BLAKE2S_LOAD_MSG_7_2(buf) \ 556 do { uint32x2_t t0, t1; \ 557 t0 = vext_u32(vget_high_u32(m2), vget_high_u32(m3), 1); \ 558 t1 = vzip_u32(vget_low_u32(m0), vget_low_u32(m2)).val[1]; \ 559 buf = vcombine_u32(t0, t1); } while(0) 561 #define BLAKE2S_LOAD_MSG_7_3(buf) \ 562 do { uint32x2_t t0, t1; \ 563 t0 = vzip_u32(vget_low_u32(m1), vget_high_u32(m3)).val[1]; \ 564 t1 = vzip_u32(vget_low_u32(m2), vget_high_u32(m0)).val[0]; \ 565 buf = vcombine_u32(t0, t1); } while(0) 567 #define BLAKE2S_LOAD_MSG_7_4(buf) \ 568 do { uint32x2_t t0, t1; \ 569 t0 = vzip_u32(vget_low_u32(m0), vget_low_u32(m1)).val[0]; \ 570 t1 = vzip_u32(vget_high_u32(m1), vget_high_u32(m2)).val[0]; \ 571 buf = vcombine_u32(t0, t1); } while(0) 573 #define BLAKE2S_LOAD_MSG_8_1(buf) \ 574 do { uint32x2_t t0, t1; \ 575 t0 = vzip_u32(vget_high_u32(m1), vget_high_u32(m3)).val[0]; \ 576 t1 = vext_u32(vget_high_u32(m2), vget_low_u32(m0), 1); \ 577 buf = vcombine_u32(t0, t1); } while(0) 579 #define BLAKE2S_LOAD_MSG_8_2(buf) \ 580 do { uint32x2_t t0, t1; \ 581 t0 = vzip_u32(vget_high_u32(m3), vget_low_u32(m2)).val[1]; \ 582 t1 = vext_u32(vget_high_u32(m0), vget_low_u32(m2), 1); \ 583 buf = vcombine_u32(t0, t1); } while(0) 585 #define BLAKE2S_LOAD_MSG_8_3(buf) \ 586 do { uint32x2_t t0, t1; \ 587 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m3), vget_low_u32(m3)); \ 588 t1 = vext_u32(vget_low_u32(m0), vget_high_u32(m2), 1); \ 589 buf = vcombine_u32(t0, t1); } while(0) 591 #define BLAKE2S_LOAD_MSG_8_4(buf) \ 592 do { uint32x2_t t0, t1; \ 593 t0 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m0), vget_high_u32(m1)); \ 594 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_low_u32(m1), vget_low_u32(m1)); \ 595 buf = vcombine_u32(t0, t1); } while(0) 597 #define BLAKE2S_LOAD_MSG_9_1(buf) \ 598 do { uint32x2_t t0, t1; \ 599 t0 = vzip_u32(vget_high_u32(m2), vget_low_u32(m2)).val[0]; \ 600 t1 = vzip_u32(vget_high_u32(m1), vget_low_u32(m0)).val[1]; \ 601 buf = vcombine_u32(t0, t1); } while(0) 603 #define BLAKE2S_LOAD_MSG_9_2(buf) \ 604 do { uint32x2_t t0, t1; \ 605 t0 = vzip_u32((vget_high_u32(m0)), vget_low_u32(m1)).val[0]; \ 606 t1 = vbsl_u32(vcreate_u32(0xFFFFFFFF), vget_high_u32(m1), vget_low_u32(m1)); \ 607 buf = vcombine_u32(t0, t1); } while(0) 609 #define BLAKE2S_LOAD_MSG_9_3(buf) \ 610 do { uint32x2_t t0, t1; \ 611 t0 = vzip_u32(vget_high_u32(m3), vget_low_u32(m2)).val[1]; \ 612 t1 = vzip_u32((vget_high_u32(m0)), vget_low_u32(m3)).val[1]; \ 613 buf = vcombine_u32(t0, t1); } while(0) 615 #define BLAKE2S_LOAD_MSG_9_4(buf) \ 616 do { uint32x2_t t0, t1; \ 617 t0 = vext_u32(vget_high_u32(m2), vget_high_u32(m3), 1); \ 618 t1 = vzip_u32(vget_low_u32(m3), vget_low_u32(m0)).val[0]; \ 619 buf = vcombine_u32(t0, t1); } while(0) 621 #define vrorq_n_u32_16(x) vreinterpretq_u32_u16(vrev32q_u16(vreinterpretq_u16_u32(x))) 623 #define vrorq_n_u32_8(x) vsriq_n_u32(vshlq_n_u32((x), 24), (x), 8) 625 #define vrorq_n_u32(x, c) vsriq_n_u32(vshlq_n_u32((x), 32-(c)), (x), (c)) 627 #define BLAKE2S_G1(row1,row2,row3,row4,buf) \ 629 row1 = vaddq_u32(vaddq_u32(row1, buf), row2); row4 = veorq_u32(row4, row1); \ 630 row4 = vrorq_n_u32_16(row4); row3 = vaddq_u32(row3, row4); \ 631 row2 = veorq_u32(row2, row3); row2 = vrorq_n_u32(row2, 12); \ 634 #define BLAKE2S_G2(row1,row2,row3,row4,buf) \ 636 row1 = vaddq_u32(vaddq_u32(row1, buf), row2); row4 = veorq_u32(row4, row1); \ 637 row4 = vrorq_n_u32_8(row4); row3 = vaddq_u32(row3, row4); \ 638 row2 = veorq_u32(row2, row3); row2 = vrorq_n_u32(row2, 7); \ 641 #define BLAKE2S_DIAGONALIZE(row1,row2,row3,row4) \ 643 row4 = vextq_u32(row4, row4, 3); row3 = vextq_u32(row3, row3, 2); row2 = vextq_u32(row2, row2, 1); \ 646 #define BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4) \ 648 row4 = vextq_u32(row4, row4, 1); \ 649 row3 = vextq_u32(row3, row3, 2); \ 650 row2 = vextq_u32(row2, row2, 3); \ 653 #define BLAKE2S_ROUND(r) \ 655 uint32x4_t buf1, buf2, buf3, buf4; \ 656 BLAKE2S_LOAD_MSG_ ##r ##_1(buf1); \ 657 BLAKE2S_G1(row1,row2,row3,row4,buf1); \ 658 BLAKE2S_LOAD_MSG_ ##r ##_2(buf2); \ 659 BLAKE2S_G2(row1,row2,row3,row4,buf2); \ 660 BLAKE2S_DIAGONALIZE(row1,row2,row3,row4); \ 661 BLAKE2S_LOAD_MSG_ ##r ##_3(buf3); \ 662 BLAKE2S_G1(row1,row2,row3,row4,buf3); \ 663 BLAKE2S_LOAD_MSG_ ##r ##_4(buf4); \ 664 BLAKE2S_G2(row1,row2,row3,row4,buf4); \ 665 BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4); \ 668 const uint32x4_t m0 = vreinterpretq_u32_u8(vld1q_u8(input + 00));
669 const uint32x4_t m1 = vreinterpretq_u32_u8(vld1q_u8(input + 16));
670 const uint32x4_t m2 = vreinterpretq_u32_u8(vld1q_u8(input + 32));
671 const uint32x4_t m3 = vreinterpretq_u32_u8(vld1q_u8(input + 48));
673 uint32x4_t row1, row2, row3, row4;
675 const uint32x4_t f0 = row1 = vld1q_u32(state.h()+0);
676 const uint32x4_t f1 = row2 = vld1q_u32(state.h()+4);
677 row3 = vld1q_u32(BLAKE2S_IV+0);
678 row4 = veorq_u32(vld1q_u32(BLAKE2S_IV+4), vld1q_u32(state.t()+0));
691 vst1q_u32(state.h()+0, veorq_u32(f0, veorq_u32(row1, row3)));
692 vst1q_u32(state.h()+4, veorq_u32(f1, veorq_u32(row2, row4)));
694 #endif // CRYPTOPP_ARM_NEON_AVAILABLE 696 #if (CRYPTOPP_POWER7_AVAILABLE || CRYPTOPP_ALTIVEC_AVAILABLE) 700 return VecLoad((
const word32*)p);
706 const uint8x16_p m = {3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12};
710 return VecLoad((
const word32*)p);
714 inline void VecStore32(
void* p,
const uint32x4_p x)
719 inline void VecStore32LE(
void* p,
const uint32x4_p x)
722 const uint8x16_p m = {3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12};
729 template <
unsigned int E1,
unsigned int E2>
735 enum {X=E1&3, Y=E2&3};
738 const unsigned int DC = 31;
741 if (X == 0 && Y == 0)
743 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
746 else if (X == 0 && Y == 1)
748 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
749 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
751 else if (X == 0 && Y == 2)
753 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
754 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
756 else if (X == 0 && Y == 3)
758 const uint8x16_p mask = {0,1,2,3, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
759 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
763 else if (X == 1 && Y == 0)
765 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
768 else if (X == 1 && Y == 1)
770 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
771 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
773 else if (X == 1 && Y == 2)
775 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
776 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
778 else if (X == 1 && Y == 3)
780 const uint8x16_p mask = {4,5,6,7, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
781 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
785 else if (X == 2 && Y == 0)
787 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
790 else if (X == 2 && Y == 1)
792 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
793 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
795 else if (X == 2 && Y == 2)
797 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
798 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
800 else if (X == 2 && Y == 3)
802 const uint8x16_p mask = {8,9,10,11, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
803 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
807 else if (X == 3 && Y == 0)
809 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
812 else if (X == 3 && Y == 1)
814 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
815 return VecPermute(a, VecShiftLeftOctet<4>(b), mask);
817 else if (X == 3 && Y == 2)
819 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
820 return VecPermute(a, VecShiftLeftOctet<8>(b), mask);
822 else if (X == 3 && Y == 3)
824 const uint8x16_p mask = {12,13,14,15, 16,17,18,19, DC,DC,DC,DC, DC,DC,DC,DC};
825 return VecPermute(a, VecShiftLeftOctet<12>(b), mask);
832 template <
unsigned int E1,
unsigned int E2,
unsigned int E3,
unsigned int E4>
837 enum {W=E1&3, X=E2&3, Y=E3&3, Z=E4&3};
843 const uint8x16_p mask = {20,21,22,23, 16,17,18,19, 4,5,6,7, 0,1,2,3};
852 const uint8x16_p mask = {16,17,18,19, 24,25,26,27, 0,1,2,3, 8,9,10,11};
861 const uint8x16_p mask = {20,21,22,23, 28,29,30,31, 4,5,6,7, 12,13,14,15};
870 void BLAKE2_Compress32_CORE(
const byte* input,
BLAKE2s_State& state)
889 #define BLAKE2S_LOAD_MSG_0_1(buf) buf = VectorSet32<2,0,2,0>(m6,m4,m2,m0); 891 #define BLAKE2S_LOAD_MSG_0_2(buf) buf = VectorSet32<3,1,3,1>(m7,m5,m3,m1); 893 #define BLAKE2S_LOAD_MSG_0_3(buf) buf = VectorSet32<2,0,2,0>(m14,m12,m10,m8); 895 #define BLAKE2S_LOAD_MSG_0_4(buf) buf = VectorSet32<3,1,3,1>(m15,m13,m11,m9); 897 #define BLAKE2S_LOAD_MSG_1_1(buf) buf = VectorSet32<13,9,4,14>(m13,m9,m4,m14); 898 #define BLAKE2S_LOAD_MSG_1_2(buf) buf = VectorSet32<6,15,8,10>(m6,m15,m8,m10) 899 #define BLAKE2S_LOAD_MSG_1_3(buf) buf = VectorSet32<5,11,0,1>(m5,m11,m0,m1) 900 #define BLAKE2S_LOAD_MSG_1_4(buf) buf = VectorSet32<3,7,2,12>(m3,m7,m2,m12) 902 #define BLAKE2S_LOAD_MSG_2_1(buf) buf = VectorSet32<15,5,12,11>(m15,m5,m12,m11) 903 #define BLAKE2S_LOAD_MSG_2_2(buf) buf = VectorSet32<13,2,0,8>(m13,m2,m0,m8) 904 #define BLAKE2S_LOAD_MSG_2_3(buf) buf = VectorSet32<9,7,3,10>(m9,m7,m3,m10) 905 #define BLAKE2S_LOAD_MSG_2_4(buf) buf = VectorSet32<4,1,6,14>(m4,m1,m6,m14) 907 #define BLAKE2S_LOAD_MSG_3_1(buf) buf = VectorSet32<11,13,3,7>(m11,m13,m3,m7) 908 #define BLAKE2S_LOAD_MSG_3_2(buf) buf = VectorSet32<14,12,1,9>(m14,m12,m1,m9) 909 #define BLAKE2S_LOAD_MSG_3_3(buf) buf = VectorSet32<15,4,5,2>(m15,m4,m5,m2) 910 #define BLAKE2S_LOAD_MSG_3_4(buf) buf = VectorSet32<8,0,10,6>(m8,m0,m10,m6) 912 #define BLAKE2S_LOAD_MSG_4_1(buf) buf = VectorSet32<10,2,5,9>(m10,m2,m5,m9) 913 #define BLAKE2S_LOAD_MSG_4_2(buf) buf = VectorSet32<15,4,7,0>(m15,m4,m7,m0) 914 #define BLAKE2S_LOAD_MSG_4_3(buf) buf = VectorSet32<3,6,11,14>(m3,m6,m11,m14) 915 #define BLAKE2S_LOAD_MSG_4_4(buf) buf = VectorSet32<13,8,12,1>(m13,m8,m12,m1) 917 #define BLAKE2S_LOAD_MSG_5_1(buf) buf = VectorSet32<8,0,6,2>(m8,m0,m6,m2) 918 #define BLAKE2S_LOAD_MSG_5_2(buf) buf = VectorSet32<3,11,10,12>(m3,m11,m10,m12) 919 #define BLAKE2S_LOAD_MSG_5_3(buf) buf = VectorSet32<1,15,7,4>(m1,m15,m7,m4) 920 #define BLAKE2S_LOAD_MSG_5_4(buf) buf = VectorSet32<9,14,5,13>(m9,m14,m5,m13) 922 #define BLAKE2S_LOAD_MSG_6_1(buf) buf = VectorSet32<4,14,1,12>(m4,m14,m1,m12) 923 #define BLAKE2S_LOAD_MSG_6_2(buf) buf = VectorSet32<10,13,15,5>(m10,m13,m15,m5) 924 #define BLAKE2S_LOAD_MSG_6_3(buf) buf = VectorSet32<8,9,6,0>(m8,m9,m6,m0) 925 #define BLAKE2S_LOAD_MSG_6_4(buf) buf = VectorSet32<11,2,3,7>(m11,m2,m3,m7) 927 #define BLAKE2S_LOAD_MSG_7_1(buf) buf = VectorSet32<3,12,7,13>(m3,m12,m7,m13) 928 #define BLAKE2S_LOAD_MSG_7_2(buf) buf = VectorSet32<9,1,14,11>(m9,m1,m14,m11) 929 #define BLAKE2S_LOAD_MSG_7_3(buf) buf = VectorSet32<2,8,15,5>(m2,m8,m15,m5) 930 #define BLAKE2S_LOAD_MSG_7_4(buf) buf = VectorSet32<10,6,4,0>(m10,m6,m4,m0) 932 #define BLAKE2S_LOAD_MSG_8_1(buf) buf = VectorSet32<0,11,14,6>(m0,m11,m14,m6) 933 #define BLAKE2S_LOAD_MSG_8_2(buf) buf = VectorSet32<8,3,9,15>(m8,m3,m9,m15) 934 #define BLAKE2S_LOAD_MSG_8_3(buf) buf = VectorSet32<10,1,13,12>(m10,m1,m13,m12) 935 #define BLAKE2S_LOAD_MSG_8_4(buf) buf = VectorSet32<5,4,7,2>(m5,m4,m7,m2) 937 #define BLAKE2S_LOAD_MSG_9_1(buf) buf = VectorSet32<1,7,8,10>(m1,m7,m8,m10) 938 #define BLAKE2S_LOAD_MSG_9_2(buf) buf = VectorSet32<5,6,4,2>(m5,m6,m4,m2) 939 #define BLAKE2S_LOAD_MSG_9_3(buf) buf = VectorSet32<13,3,9,15>(m13,m3,m9,m15) 940 #define BLAKE2S_LOAD_MSG_9_4(buf) buf = VectorSet32<0,12,14,11>(m0,m12,m14,m11) 942 #define vec_ror_16(x) VecRotateRight<16>(x) 943 #define vec_ror_12(x) VecRotateRight<12>(x) 944 #define vec_ror_8(x) VecRotateRight<8>(x) 945 #define vec_ror_7(x) VecRotateRight<7>(x) 947 #define BLAKE2S_G1(row1,row2,row3,row4,buf) \ 948 row1 = VecAdd(VecAdd(row1, buf), row2); \ 949 row4 = VecXor(row4, row1); \ 950 row4 = vec_ror_16(row4); \ 951 row3 = VecAdd(row3, row4); \ 952 row2 = VecXor(row2, row3); \ 953 row2 = vec_ror_12(row2); 955 #define BLAKE2S_G2(row1,row2,row3,row4,buf) \ 956 row1 = VecAdd(VecAdd(row1, buf), row2); \ 957 row4 = VecXor(row4, row1); \ 958 row4 = vec_ror_8(row4); \ 959 row3 = VecAdd(row3, row4); \ 960 row2 = VecXor(row2, row3); \ 961 row2 = vec_ror_7(row2); 963 const uint8x16_p D2103_MASK = {12,13,14,15, 0,1,2,3, 4,5,6,7, 8,9,10,11};
964 const uint8x16_p D1032_MASK = {8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7};
965 const uint8x16_p D0321_MASK = {4,5,6,7, 8,9,10,11, 12,13,14,15, 0,1,2,3};
967 #define BLAKE2S_DIAGONALIZE(row1,row2,row3,row4) \ 968 row4 = VecPermute(row4, row4, D2103_MASK); \ 969 row3 = VecPermute(row3, row3, D1032_MASK); \ 970 row2 = VecPermute(row2, row2, D0321_MASK); 972 #define BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4) \ 973 row4 = VecPermute(row4, row4, D0321_MASK); \ 974 row3 = VecPermute(row3, row3, D1032_MASK); \ 975 row2 = VecPermute(row2, row2, D2103_MASK); 977 #define BLAKE2S_ROUND(r) \ 978 BLAKE2S_LOAD_MSG_ ##r ##_1(buf1); \ 979 BLAKE2S_G1(row1,row2,row3,row4,buf1); \ 980 BLAKE2S_LOAD_MSG_ ##r ##_2(buf2); \ 981 BLAKE2S_G2(row1,row2,row3,row4,buf2); \ 982 BLAKE2S_DIAGONALIZE(row1,row2,row3,row4); \ 983 BLAKE2S_LOAD_MSG_ ##r ##_3(buf3); \ 984 BLAKE2S_G1(row1,row2,row3,row4,buf3); \ 985 BLAKE2S_LOAD_MSG_ ##r ##_4(buf4); \ 986 BLAKE2S_G2(row1,row2,row3,row4,buf4); \ 987 BLAKE2S_UNDIAGONALIZE(row1,row2,row3,row4); 994 const uint32x4_p m4 = VecLoad32LE(input + 16);
995 const uint32x4_p m8 = VecLoad32LE(input + 32);
996 const uint32x4_p m12 = VecLoad32LE(input + 48);
998 row1 = ff0 = VecLoad32LE(state.h()+0);
999 row2 = ff1 = VecLoad32LE(state.h()+4);
1000 row3 = VecLoad32(BLAKE2S_IV+0);
1001 row4 =
VecXor(VecLoad32(BLAKE2S_IV+4), VecLoad32(state.t()+0));
1014 VecStore32LE(state.h()+0,
VecXor(ff0,
VecXor(row1, row3)));
1015 VecStore32LE(state.h()+4,
VecXor(ff1,
VecXor(row2, row4)));
1017 #endif // CRYPTOPP_POWER7_AVAILABLE || CRYPTOPP_ALTIVEC_AVAILABLE 1019 #if (CRYPTOPP_POWER7_AVAILABLE) 1021 void BLAKE2_Compress32_POWER7(
const byte* input,
BLAKE2s_State& state)
1023 BLAKE2_Compress32_CORE(input, state);
1026 #elif (CRYPTOPP_ALTIVEC_AVAILABLE) 1028 void BLAKE2_Compress32_ALTIVEC(
const byte* input,
BLAKE2s_State& state)
1030 BLAKE2_Compress32_CORE(input, state);
Utility functions for the Crypto++ library.
Library configuration file.
T1 VecPermute(const T1 vec, const T2 mask)
Permutes a vector.
__vector unsigned int uint32x4_p
Vector of 32-bit elements.
Support functions for PowerPC and vector operations.
Classes for BLAKE2b and BLAKE2s message digests and keyed message digests.
void VecStore(const T data, byte dest[16])
Stores a vector to a byte array.
T1 VecXor(const T1 vec1, const T2 vec2)
XOR two vectors.
BLAKE2s state information.
Crypto++ library namespace.
uint32x4_p VecLoad(const byte src[16])
Loads a vector from a byte array.
__vector unsigned char uint8x16_p
Vector of 8-bit elements.