20 #if (CRYPTOPP_SSSE3_AVAILABLE) 21 # include <pmmintrin.h> 22 # include <tmmintrin.h> 26 # include <ammintrin.h> 29 #if defined(__AVX512F__) && defined(__AVX512VL__) 30 # define CRYPTOPP_AVX512_ROTATE 1 31 # include <immintrin.h> 34 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 35 # include <arm_neon.h> 40 #if (CRYPTOPP_ARM_ACLE_AVAILABLE) 42 # include <arm_acle.h> 45 #if defined(CRYPTOPP_POWER7_AVAILABLE) 50 extern const char SIMON128_SIMD_FNAME[] = __FILE__;
52 ANONYMOUS_NAMESPACE_BEGIN
55 using CryptoPP::word32;
56 using CryptoPP::word64;
61 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 64 inline T UnpackHigh64(
const T& a,
const T& b)
66 const uint64x1_t x(vget_high_u64((uint64x2_t)a));
67 const uint64x1_t y(vget_high_u64((uint64x2_t)b));
68 return (T)vcombine_u64(x, y);
72 inline T UnpackLow64(
const T& a,
const T& b)
74 const uint64x1_t x(vget_low_u64((uint64x2_t)a));
75 const uint64x1_t y(vget_low_u64((uint64x2_t)b));
76 return (T)vcombine_u64(x, y);
79 template <
unsigned int R>
80 inline uint64x2_t RotateLeft64(
const uint64x2_t& val)
82 const uint64x2_t a(vshlq_n_u64(val, R));
83 const uint64x2_t b(vshrq_n_u64(val, 64 - R));
84 return vorrq_u64(a, b);
87 template <
unsigned int R>
88 inline uint64x2_t RotateRight64(
const uint64x2_t& val)
90 const uint64x2_t a(vshlq_n_u64(val, 64 - R));
91 const uint64x2_t b(vshrq_n_u64(val, R));
92 return vorrq_u64(a, b);
95 #if defined(__aarch32__) || defined(__aarch64__) 98 inline uint64x2_t RotateLeft64<8>(
const uint64x2_t& val)
100 #if (CRYPTOPP_BIG_ENDIAN) 101 const uint8_t maskb[16] = { 14,13,12,11, 10,9,8,15, 6,5,4,3, 2,1,0,7 };
102 const uint8x16_t mask = vld1q_u8(maskb);
104 const uint8_t maskb[16] = { 7,0,1,2, 3,4,5,6, 15,8,9,10, 11,12,13,14 };
105 const uint8x16_t mask = vld1q_u8(maskb);
108 return vreinterpretq_u64_u8(
109 vqtbl1q_u8(vreinterpretq_u8_u64(val), mask));
114 inline uint64x2_t RotateRight64<8>(
const uint64x2_t& val)
116 #if (CRYPTOPP_BIG_ENDIAN) 117 const uint8_t maskb[16] = { 8,15,14,13, 12,11,10,9, 0,7,6,5, 4,3,2,1 };
118 const uint8x16_t mask = vld1q_u8(maskb);
120 const uint8_t maskb[16] = { 1,2,3,4, 5,6,7,0, 9,10,11,12, 13,14,15,8 };
121 const uint8x16_t mask = vld1q_u8(maskb);
124 return vreinterpretq_u64_u8(
125 vqtbl1q_u8(vreinterpretq_u8_u64(val), mask));
129 inline uint64x2_t SIMON128_f(
const uint64x2_t& val)
131 return veorq_u64(RotateLeft64<2>(val),
132 vandq_u64(RotateLeft64<1>(val), RotateLeft64<8>(val)));
135 inline void SIMON128_Enc_Block(uint64x2_t &block0, uint64x2_t &block1,
136 const word64 *subkeys,
unsigned int rounds)
139 uint64x2_t x1 = UnpackHigh64(block0, block1);
140 uint64x2_t y1 = UnpackLow64(block0, block1);
142 for (
int i = 0; i < static_cast<int>(rounds & ~1)-1; i += 2)
144 const uint64x2_t rk1 = vld1q_dup_u64(subkeys+i);
145 y1 = veorq_u64(veorq_u64(y1, SIMON128_f(x1)), rk1);
147 const uint64x2_t rk2 = vld1q_dup_u64(subkeys+i+1);
148 x1 = veorq_u64(veorq_u64(x1, SIMON128_f(y1)), rk2);
153 const uint64x2_t rk = vld1q_dup_u64(subkeys+rounds-1);
155 y1 = veorq_u64(veorq_u64(y1, SIMON128_f(x1)), rk);
160 block0 = UnpackLow64(y1, x1);
161 block1 = UnpackHigh64(y1, x1);
164 inline void SIMON128_Enc_6_Blocks(uint64x2_t &block0, uint64x2_t &block1,
165 uint64x2_t &block2, uint64x2_t &block3, uint64x2_t &block4, uint64x2_t &block5,
166 const word64 *subkeys,
unsigned int rounds)
169 uint64x2_t x1 = UnpackHigh64(block0, block1);
170 uint64x2_t y1 = UnpackLow64(block0, block1);
171 uint64x2_t x2 = UnpackHigh64(block2, block3);
172 uint64x2_t y2 = UnpackLow64(block2, block3);
173 uint64x2_t x3 = UnpackHigh64(block4, block5);
174 uint64x2_t y3 = UnpackLow64(block4, block5);
176 for (
int i = 0; i < static_cast<int>(rounds & ~1) - 1; i += 2)
178 const uint64x2_t rk1 = vld1q_dup_u64(subkeys+i);
179 y1 = veorq_u64(veorq_u64(y1, SIMON128_f(x1)), rk1);
180 y2 = veorq_u64(veorq_u64(y2, SIMON128_f(x2)), rk1);
181 y3 = veorq_u64(veorq_u64(y3, SIMON128_f(x3)), rk1);
183 const uint64x2_t rk2 = vld1q_dup_u64(subkeys+i+1);
184 x1 = veorq_u64(veorq_u64(x1, SIMON128_f(y1)), rk2);
185 x2 = veorq_u64(veorq_u64(x2, SIMON128_f(y2)), rk2);
186 x3 = veorq_u64(veorq_u64(x3, SIMON128_f(y3)), rk2);
191 const uint64x2_t rk = vld1q_dup_u64(subkeys + rounds - 1);
193 y1 = veorq_u64(veorq_u64(y1, SIMON128_f(x1)), rk);
194 y2 = veorq_u64(veorq_u64(y2, SIMON128_f(x2)), rk);
195 y3 = veorq_u64(veorq_u64(y3, SIMON128_f(x3)), rk);
196 std::swap(x1, y1); std::swap(x2, y2); std::swap(x3, y3);
200 block0 = UnpackLow64(y1, x1);
201 block1 = UnpackHigh64(y1, x1);
202 block2 = UnpackLow64(y2, x2);
203 block3 = UnpackHigh64(y2, x2);
204 block4 = UnpackLow64(y3, x3);
205 block5 = UnpackHigh64(y3, x3);
208 inline void SIMON128_Dec_Block(uint64x2_t &block0, uint64x2_t &block1,
209 const word64 *subkeys,
unsigned int rounds)
212 uint64x2_t x1 = UnpackHigh64(block0, block1);
213 uint64x2_t y1 = UnpackLow64(block0, block1);
218 const uint64x2_t rk = vld1q_dup_u64(subkeys + rounds - 1);
220 y1 = veorq_u64(veorq_u64(y1, rk), SIMON128_f(x1));
224 for (
int i = static_cast<int>(rounds-2); i >= 0; i -= 2)
226 const uint64x2_t rk1 = vld1q_dup_u64(subkeys+i+1);
227 x1 = veorq_u64(veorq_u64(x1, SIMON128_f(y1)), rk1);
229 const uint64x2_t rk2 = vld1q_dup_u64(subkeys+i);
230 y1 = veorq_u64(veorq_u64(y1, SIMON128_f(x1)), rk2);
234 block0 = UnpackLow64(y1, x1);
235 block1 = UnpackHigh64(y1, x1);
238 inline void SIMON128_Dec_6_Blocks(uint64x2_t &block0, uint64x2_t &block1,
239 uint64x2_t &block2, uint64x2_t &block3, uint64x2_t &block4, uint64x2_t &block5,
240 const word64 *subkeys,
unsigned int rounds)
243 uint64x2_t x1 = UnpackHigh64(block0, block1);
244 uint64x2_t y1 = UnpackLow64(block0, block1);
245 uint64x2_t x2 = UnpackHigh64(block2, block3);
246 uint64x2_t y2 = UnpackLow64(block2, block3);
247 uint64x2_t x3 = UnpackHigh64(block4, block5);
248 uint64x2_t y3 = UnpackLow64(block4, block5);
252 std::swap(x1, y1); std::swap(x2, y2); std::swap(x3, y3);
253 const uint64x2_t rk = vld1q_dup_u64(subkeys + rounds - 1);
255 y1 = veorq_u64(veorq_u64(y1, rk), SIMON128_f(x1));
256 y2 = veorq_u64(veorq_u64(y2, rk), SIMON128_f(x2));
257 y3 = veorq_u64(veorq_u64(y3, rk), SIMON128_f(x3));
261 for (
int i = static_cast<int>(rounds-2); i >= 0; i -= 2)
263 const uint64x2_t rk1 = vld1q_dup_u64(subkeys + i + 1);
264 x1 = veorq_u64(veorq_u64(x1, SIMON128_f(y1)), rk1);
265 x2 = veorq_u64(veorq_u64(x2, SIMON128_f(y2)), rk1);
266 x3 = veorq_u64(veorq_u64(x3, SIMON128_f(y3)), rk1);
268 const uint64x2_t rk2 = vld1q_dup_u64(subkeys + i);
269 y1 = veorq_u64(veorq_u64(y1, SIMON128_f(x1)), rk2);
270 y2 = veorq_u64(veorq_u64(y2, SIMON128_f(x2)), rk2);
271 y3 = veorq_u64(veorq_u64(y3, SIMON128_f(x3)), rk2);
275 block0 = UnpackLow64(y1, x1);
276 block1 = UnpackHigh64(y1, x1);
277 block2 = UnpackLow64(y2, x2);
278 block3 = UnpackHigh64(y2, x2);
279 block4 = UnpackLow64(y3, x3);
280 block5 = UnpackHigh64(y3, x3);
283 #endif // CRYPTOPP_ARM_NEON_AVAILABLE 287 #if defined(CRYPTOPP_SSSE3_AVAILABLE) 291 # define M128_CAST(x) ((__m128i *)(void *)(x)) 293 #ifndef CONST_M128_CAST 294 # define CONST_M128_CAST(x) ((const __m128i *)(const void *)(x)) 299 # define DOUBLE_CAST(x) ((double *)(void *)(x)) 301 #ifndef CONST_DOUBLE_CAST 302 # define CONST_DOUBLE_CAST(x) ((const double *)(const void *)(x)) 305 inline void Swap128(__m128i& a,__m128i& b)
307 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120) 316 template <
unsigned int R>
317 inline __m128i RotateLeft64(
const __m128i& val)
319 #if defined(CRYPTOPP_AVX512_ROTATE) 320 return _mm_rol_epi64(val, R);
321 #elif defined(__XOP__) 322 return _mm_roti_epi64(val, R);
325 _mm_slli_epi64(val, R), _mm_srli_epi64(val, 64-R));
329 template <
unsigned int R>
330 inline __m128i RotateRight64(
const __m128i& val)
332 #if defined(CRYPTOPP_AVX512_ROTATE) 333 return _mm_ror_epi64(val, R);
334 #elif defined(__XOP__) 335 return _mm_roti_epi64(val, 64-R);
338 _mm_slli_epi64(val, 64-R), _mm_srli_epi64(val, R));
344 __m128i RotateLeft64<8>(
const __m128i& val)
347 return _mm_roti_epi64(val, 8);
349 const __m128i mask = _mm_set_epi8(14,13,12,11, 10,9,8,15, 6,5,4,3, 2,1,0,7);
350 return _mm_shuffle_epi8(val, mask);
356 __m128i RotateRight64<8>(
const __m128i& val)
359 return _mm_roti_epi64(val, 64-8);
361 const __m128i mask = _mm_set_epi8(8,15,14,13, 12,11,10,9, 0,7,6,5, 4,3,2,1);
362 return _mm_shuffle_epi8(val, mask);
366 inline __m128i SIMON128_f(
const __m128i& v)
368 return _mm_xor_si128(RotateLeft64<2>(v),
369 _mm_and_si128(RotateLeft64<1>(v), RotateLeft64<8>(v)));
372 inline void SIMON128_Enc_Block(__m128i &block0, __m128i &block1,
373 const word64 *subkeys,
unsigned int rounds)
376 __m128i x1 = _mm_unpackhi_epi64(block0, block1);
377 __m128i y1 = _mm_unpacklo_epi64(block0, block1);
379 for (
int i = 0; i < static_cast<int>(rounds & ~1)-1; i += 2)
381 const __m128i rk1 = _mm_castpd_si128(
382 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys+i)));
383 y1 = _mm_xor_si128(_mm_xor_si128(y1, SIMON128_f(x1)), rk1);
385 const __m128i rk2 = _mm_castpd_si128(
386 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys+i+1)));
387 x1 = _mm_xor_si128(_mm_xor_si128(x1, SIMON128_f(y1)), rk2);
392 const __m128i rk = _mm_castpd_si128(
393 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys+rounds-1)));
395 y1 = _mm_xor_si128(_mm_xor_si128(y1, SIMON128_f(x1)), rk);
400 block0 = _mm_unpacklo_epi64(y1, x1);
401 block1 = _mm_unpackhi_epi64(y1, x1);
404 inline void SIMON128_Enc_6_Blocks(__m128i &block0, __m128i &block1,
405 __m128i &block2, __m128i &block3, __m128i &block4, __m128i &block5,
406 const word64 *subkeys,
unsigned int rounds)
409 __m128i x1 = _mm_unpackhi_epi64(block0, block1);
410 __m128i y1 = _mm_unpacklo_epi64(block0, block1);
411 __m128i x2 = _mm_unpackhi_epi64(block2, block3);
412 __m128i y2 = _mm_unpacklo_epi64(block2, block3);
413 __m128i x3 = _mm_unpackhi_epi64(block4, block5);
414 __m128i y3 = _mm_unpacklo_epi64(block4, block5);
416 for (
int i = 0; i < static_cast<int>(rounds & ~1) - 1; i += 2)
418 const __m128i rk1 = _mm_castpd_si128(
419 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + i)));
420 y1 = _mm_xor_si128(_mm_xor_si128(y1, SIMON128_f(x1)), rk1);
421 y2 = _mm_xor_si128(_mm_xor_si128(y2, SIMON128_f(x2)), rk1);
422 y3 = _mm_xor_si128(_mm_xor_si128(y3, SIMON128_f(x3)), rk1);
424 const __m128i rk2 = _mm_castpd_si128(
425 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + i + 1)));
426 x1 = _mm_xor_si128(_mm_xor_si128(x1, SIMON128_f(y1)), rk2);
427 x2 = _mm_xor_si128(_mm_xor_si128(x2, SIMON128_f(y2)), rk2);
428 x3 = _mm_xor_si128(_mm_xor_si128(x3, SIMON128_f(y3)), rk2);
433 const __m128i rk = _mm_castpd_si128(
434 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + rounds - 1)));
435 y1 = _mm_xor_si128(_mm_xor_si128(y1, SIMON128_f(x1)), rk);
436 y2 = _mm_xor_si128(_mm_xor_si128(y2, SIMON128_f(x2)), rk);
437 y3 = _mm_xor_si128(_mm_xor_si128(y3, SIMON128_f(x3)), rk);
438 Swap128(x1, y1); Swap128(x2, y2); Swap128(x3, y3);
442 block0 = _mm_unpacklo_epi64(y1, x1);
443 block1 = _mm_unpackhi_epi64(y1, x1);
444 block2 = _mm_unpacklo_epi64(y2, x2);
445 block3 = _mm_unpackhi_epi64(y2, x2);
446 block4 = _mm_unpacklo_epi64(y3, x3);
447 block5 = _mm_unpackhi_epi64(y3, x3);
450 inline void SIMON128_Dec_Block(__m128i &block0, __m128i &block1,
451 const word64 *subkeys,
unsigned int rounds)
454 __m128i x1 = _mm_unpackhi_epi64(block0, block1);
455 __m128i y1 = _mm_unpacklo_epi64(block0, block1);
459 const __m128i rk = _mm_castpd_si128(
460 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + rounds - 1)));
463 y1 = _mm_xor_si128(_mm_xor_si128(y1, rk), SIMON128_f(x1));
467 for (
int i = static_cast<int>(rounds-2); i >= 0; i -= 2)
469 const __m128i rk1 = _mm_castpd_si128(
470 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys+i+1)));
471 x1 = _mm_xor_si128(_mm_xor_si128(x1, SIMON128_f(y1)), rk1);
473 const __m128i rk2 = _mm_castpd_si128(
474 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys+i)));
475 y1 = _mm_xor_si128(_mm_xor_si128(y1, SIMON128_f(x1)), rk2);
479 block0 = _mm_unpacklo_epi64(y1, x1);
480 block1 = _mm_unpackhi_epi64(y1, x1);
483 inline void SIMON128_Dec_6_Blocks(__m128i &block0, __m128i &block1,
484 __m128i &block2, __m128i &block3, __m128i &block4, __m128i &block5,
485 const word64 *subkeys,
unsigned int rounds)
488 __m128i x1 = _mm_unpackhi_epi64(block0, block1);
489 __m128i y1 = _mm_unpacklo_epi64(block0, block1);
490 __m128i x2 = _mm_unpackhi_epi64(block2, block3);
491 __m128i y2 = _mm_unpacklo_epi64(block2, block3);
492 __m128i x3 = _mm_unpackhi_epi64(block4, block5);
493 __m128i y3 = _mm_unpacklo_epi64(block4, block5);
497 const __m128i rk = _mm_castpd_si128(
498 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + rounds - 1)));
500 Swap128(x1, y1); Swap128(x2, y2); Swap128(x3, y3);
501 y1 = _mm_xor_si128(_mm_xor_si128(y1, rk), SIMON128_f(x1));
502 y2 = _mm_xor_si128(_mm_xor_si128(y2, rk), SIMON128_f(x2));
503 y3 = _mm_xor_si128(_mm_xor_si128(y3, rk), SIMON128_f(x3));
507 for (
int i = static_cast<int>(rounds-2); i >= 0; i -= 2)
509 const __m128i rk1 = _mm_castpd_si128(
510 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + i + 1)));
511 x1 = _mm_xor_si128(_mm_xor_si128(x1, SIMON128_f(y1)), rk1);
512 x2 = _mm_xor_si128(_mm_xor_si128(x2, SIMON128_f(y2)), rk1);
513 x3 = _mm_xor_si128(_mm_xor_si128(x3, SIMON128_f(y3)), rk1);
515 const __m128i rk2 = _mm_castpd_si128(
516 _mm_loaddup_pd(CONST_DOUBLE_CAST(subkeys + i)));
517 y1 = _mm_xor_si128(_mm_xor_si128(y1, SIMON128_f(x1)), rk2);
518 y2 = _mm_xor_si128(_mm_xor_si128(y2, SIMON128_f(x2)), rk2);
519 y3 = _mm_xor_si128(_mm_xor_si128(y3, SIMON128_f(x3)), rk2);
523 block0 = _mm_unpacklo_epi64(y1, x1);
524 block1 = _mm_unpackhi_epi64(y1, x1);
525 block2 = _mm_unpacklo_epi64(y2, x2);
526 block3 = _mm_unpackhi_epi64(y2, x2);
527 block4 = _mm_unpacklo_epi64(y3, x3);
528 block5 = _mm_unpackhi_epi64(y3, x3);
531 #endif // CRYPTOPP_SSSE3_AVAILABLE 535 #if defined(CRYPTOPP_POWER8_AVAILABLE) 546 template<
unsigned int C>
550 return vec_rl(val, m);
554 template<
unsigned int C>
558 return vec_rl(val, m);
563 return VecXor(RotateLeft64<2>(val),
564 VecAnd(RotateLeft64<1>(val), RotateLeft64<8>(val)));
567 inline void SIMON128_Enc_Block(
uint32x4_p &block,
const word64 *subkeys,
unsigned int rounds)
569 #if (CRYPTOPP_BIG_ENDIAN) 570 const uint8x16_p m1 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
571 const uint8x16_p m2 = {23,22,21,20,19,18,17,16, 7,6,5,4,3,2,1,0};
573 const uint8x16_p m1 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
574 const uint8x16_p m2 = {15,14,13,12,11,10,9,8, 31,30,29,28,27,26,25,24};
581 for (
int i = 0; i < static_cast<int>(rounds & ~1)-1; i += 2)
583 const uint64x2_p rk1 = vec_splats((
unsigned long long)subkeys[i]);
586 const uint64x2_p rk2 = vec_splats((
unsigned long long)subkeys[i+1]);
592 const uint64x2_p rk = vec_splats((
unsigned long long)subkeys[rounds-1]);
597 #if (CRYPTOPP_BIG_ENDIAN) 598 const uint8x16_p m3 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
601 const uint8x16_p m3 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
609 inline void SIMON128_Dec_Block(
uint32x4_p &block,
const word64 *subkeys,
unsigned int rounds)
611 #if (CRYPTOPP_BIG_ENDIAN) 612 const uint8x16_p m1 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
613 const uint8x16_p m2 = {23,22,21,20,19,18,17,16, 7,6,5,4,3,2,1,0};
615 const uint8x16_p m1 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
616 const uint8x16_p m2 = {15,14,13,12,11,10,9,8, 31,30,29,28,27,26,25,24};
626 const uint64x2_p rk = vec_splats((
unsigned long long)subkeys[rounds-1]);
631 for (
int i = static_cast<int>(rounds-2); i >= 0; i -= 2)
633 const uint64x2_p rk1 = vec_splats((
unsigned long long)subkeys[i+1]);
636 const uint64x2_p rk2 = vec_splats((
unsigned long long)subkeys[i]);
640 #if (CRYPTOPP_BIG_ENDIAN) 641 const uint8x16_p m3 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
644 const uint8x16_p m3 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
654 uint32x4_p &block5,
const word64 *subkeys,
unsigned int rounds)
656 #if (CRYPTOPP_BIG_ENDIAN) 657 const uint8x16_p m1 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
658 const uint8x16_p m2 = {23,22,21,20,19,18,17,16, 7,6,5,4,3,2,1,0};
660 const uint8x16_p m1 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
661 const uint8x16_p m2 = {15,14,13,12,11,10,9,8, 31,30,29,28,27,26,25,24};
672 for (
int i = 0; i < static_cast<int>(rounds & ~1)-1; i += 2)
674 const uint64x2_p rk1 = vec_splats((
unsigned long long)subkeys[i]);
679 const uint64x2_p rk2 = vec_splats((
unsigned long long)subkeys[i+1]);
687 const uint64x2_p rk = vec_splats((
unsigned long long)subkeys[rounds-1]);
691 std::swap(x1, y1); std::swap(x2, y2); std::swap(x3, y3);
694 #if (CRYPTOPP_BIG_ENDIAN) 695 const uint8x16_p m3 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
696 const uint8x16_p m4 = {23,22,21,20,19,18,17,16, 7,6,5,4,3,2,1,0};
698 const uint8x16_p m3 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
699 const uint8x16_p m4 = {15,14,13,12,11,10,9,8, 31,30,29,28,27,26,25,24};
713 uint32x4_p &block5,
const word64 *subkeys,
unsigned int rounds)
715 #if (CRYPTOPP_BIG_ENDIAN) 716 const uint8x16_p m1 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
717 const uint8x16_p m2 = {23,22,21,20,19,18,17,16, 7,6,5,4,3,2,1,0};
719 const uint8x16_p m1 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
720 const uint8x16_p m2 = {15,14,13,12,11,10,9,8, 31,30,29,28,27,26,25,24};
733 std::swap(x1, y1); std::swap(x2, y2); std::swap(x3, y3);
734 const uint64x2_p rk = vec_splats((
unsigned long long)subkeys[rounds-1]);
741 for (
int i = static_cast<int>(rounds-2); i >= 0; i -= 2)
743 const uint64x2_p rk1 = vec_splats((
unsigned long long)subkeys[i+1]);
748 const uint64x2_p rk2 = vec_splats((
unsigned long long)subkeys[i]);
754 #if (CRYPTOPP_BIG_ENDIAN) 755 const uint8x16_p m3 = {31,30,29,28,27,26,25,24, 15,14,13,12,11,10,9,8};
756 const uint8x16_p m4 = {23,22,21,20,19,18,17,16, 7,6,5,4,3,2,1,0};
758 const uint8x16_p m3 = {7,6,5,4,3,2,1,0, 23,22,21,20,19,18,17,16};
759 const uint8x16_p m4 = {15,14,13,12,11,10,9,8, 31,30,29,28,27,26,25,24};
771 #endif // CRYPTOPP_POWER8_AVAILABLE 773 ANONYMOUS_NAMESPACE_END
781 #if (CRYPTOPP_ARM_NEON_AVAILABLE) 782 size_t SIMON128_Enc_AdvancedProcessBlocks_NEON(
const word64* subKeys,
size_t rounds,
783 const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
785 return AdvancedProcessBlocks128_6x2_NEON(SIMON128_Enc_Block, SIMON128_Enc_6_Blocks,
786 subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags);
789 size_t SIMON128_Dec_AdvancedProcessBlocks_NEON(
const word64* subKeys,
size_t rounds,
790 const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
792 return AdvancedProcessBlocks128_6x2_NEON(SIMON128_Dec_Block, SIMON128_Dec_6_Blocks,
793 subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags);
795 #endif // CRYPTOPP_ARM_NEON_AVAILABLE 799 #if defined(CRYPTOPP_SSSE3_AVAILABLE) 800 size_t SIMON128_Enc_AdvancedProcessBlocks_SSSE3(
const word64* subKeys,
size_t rounds,
801 const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
803 return AdvancedProcessBlocks128_6x2_SSE(SIMON128_Enc_Block, SIMON128_Enc_6_Blocks,
804 subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags);
807 size_t SIMON128_Dec_AdvancedProcessBlocks_SSSE3(
const word64* subKeys,
size_t rounds,
808 const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
810 return AdvancedProcessBlocks128_6x2_SSE(SIMON128_Dec_Block, SIMON128_Dec_6_Blocks,
811 subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags);
813 #endif // CRYPTOPP_SSSE3_AVAILABLE 817 #if defined(CRYPTOPP_POWER8_AVAILABLE) 818 size_t SIMON128_Enc_AdvancedProcessBlocks_POWER8(
const word64* subKeys,
size_t rounds,
819 const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
821 return AdvancedProcessBlocks128_6x1_ALTIVEC(SIMON128_Enc_Block, SIMON128_Enc_6_Blocks,
822 subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags);
825 size_t SIMON128_Dec_AdvancedProcessBlocks_POWER8(
const word64* subKeys,
size_t rounds,
826 const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
828 return AdvancedProcessBlocks128_6x1_ALTIVEC(SIMON128_Dec_Block, SIMON128_Dec_6_Blocks,
829 subKeys, rounds, inBlocks, xorBlocks, outBlocks, length, flags);
831 #endif // CRYPTOPP_POWER8_AVAILABLE 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.
Template for AdvancedProcessBlocks and SIMD processing.
T1 VecXor(const T1 vec1, const T2 vec2)
XOR two vectors.
__vector unsigned long long uint64x2_p
Vector of 64-bit elements.
Classes for the Simon block cipher.
Crypto++ library namespace.
__vector unsigned char uint8x16_p
Vector of 8-bit elements.
T1 VecAnd(const T1 vec1, const T2 vec2)
AND two vectors.
void vec_swap(T &a, T &b)
Swaps two variables which are arrays.