8#include <botan/internal/shacal2.h>
18BOTAN_FUNC_ISA(
"sha,ssse3") void SHACAL2::x86_encrypt_blocks(const uint8_t in[], uint8_t out[],
size_t blocks)
const {
19 const __m128i MASK1 = _mm_set_epi8(8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7);
20 const __m128i MASK2 = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
22 const __m128i* RK_mm =
reinterpret_cast<const __m128i*
>(m_RK.data());
23 const __m128i* in_mm =
reinterpret_cast<const __m128i*
>(in);
24 __m128i* out_mm =
reinterpret_cast<__m128i*
>(out);
27 __m128i B0_0 = _mm_loadu_si128(in_mm);
28 __m128i B0_1 = _mm_loadu_si128(in_mm + 1);
29 __m128i B1_0 = _mm_loadu_si128(in_mm + 2);
30 __m128i B1_1 = _mm_loadu_si128(in_mm + 3);
32 __m128i TMP = _mm_shuffle_epi8(_mm_unpacklo_epi64(B0_0, B0_1), MASK2);
33 B0_1 = _mm_shuffle_epi8(_mm_unpackhi_epi64(B0_0, B0_1), MASK2);
36 TMP = _mm_shuffle_epi8(_mm_unpacklo_epi64(B1_0, B1_1), MASK2);
37 B1_1 = _mm_shuffle_epi8(_mm_unpackhi_epi64(B1_0, B1_1), MASK2);
40 for(
size_t i = 0; i != 8; ++i) {
41 const __m128i RK0 = _mm_loadu_si128(RK_mm + 2 * i);
42 const __m128i RK2 = _mm_loadu_si128(RK_mm + 2 * i + 1);
43 const __m128i RK1 = _mm_srli_si128(RK0, 8);
44 const __m128i RK3 = _mm_srli_si128(RK2, 8);
46 B0_1 = _mm_sha256rnds2_epu32(B0_1, B0_0, RK0);
47 B1_1 = _mm_sha256rnds2_epu32(B1_1, B1_0, RK0);
49 B0_0 = _mm_sha256rnds2_epu32(B0_0, B0_1, RK1);
50 B1_0 = _mm_sha256rnds2_epu32(B1_0, B1_1, RK1);
52 B0_1 = _mm_sha256rnds2_epu32(B0_1, B0_0, RK2);
53 B1_1 = _mm_sha256rnds2_epu32(B1_1, B1_0, RK2);
55 B0_0 = _mm_sha256rnds2_epu32(B0_0, B0_1, RK3);
56 B1_0 = _mm_sha256rnds2_epu32(B1_0, B1_1, RK3);
59 _mm_storeu_si128(out_mm + 0, _mm_shuffle_epi8(_mm_unpackhi_epi64(B0_0, B0_1), MASK1));
60 _mm_storeu_si128(out_mm + 1, _mm_shuffle_epi8(_mm_unpacklo_epi64(B0_0, B0_1), MASK1));
61 _mm_storeu_si128(out_mm + 2, _mm_shuffle_epi8(_mm_unpackhi_epi64(B1_0, B1_1), MASK1));
62 _mm_storeu_si128(out_mm + 3, _mm_shuffle_epi8(_mm_unpacklo_epi64(B1_0, B1_1), MASK1));
70 __m128i B0 = _mm_loadu_si128(in_mm);
71 __m128i B1 = _mm_loadu_si128(in_mm + 1);
73 __m128i TMP = _mm_shuffle_epi8(_mm_unpacklo_epi64(B0, B1), MASK2);
74 B1 = _mm_shuffle_epi8(_mm_unpackhi_epi64(B0, B1), MASK2);
77 for(
size_t i = 0; i != 8; ++i) {
78 const __m128i RK0 = _mm_loadu_si128(RK_mm + 2 * i);
79 const __m128i RK2 = _mm_loadu_si128(RK_mm + 2 * i + 1);
80 const __m128i RK1 = _mm_srli_si128(RK0, 8);
81 const __m128i RK3 = _mm_srli_si128(RK2, 8);
83 B1 = _mm_sha256rnds2_epu32(B1, B0, RK0);
84 B0 = _mm_sha256rnds2_epu32(B0, B1, RK1);
85 B1 = _mm_sha256rnds2_epu32(B1, B0, RK2);
86 B0 = _mm_sha256rnds2_epu32(B0, B1, RK3);
89 _mm_storeu_si128(out_mm, _mm_shuffle_epi8(_mm_unpackhi_epi64(B0, B1), MASK1));
90 _mm_storeu_si128(out_mm + 1, _mm_shuffle_epi8(_mm_unpacklo_epi64(B0, B1), MASK1));
#define BOTAN_FUNC_ISA(isa)