7#include <botan/internal/sm4.h>
9#include <botan/mem_ops.h>
10#include <botan/internal/isa_extn.h>
11#include <botan/internal/simd_avx2.h>
19 return SIMD_8x32(_mm256_sm4rnds4_epi32(b.raw(), k.raw()));
23 const uint8_t inp[2 * 16],
24 std::span<const uint32_t> RK) {
27 for(
size_t i = 0; i != 8; ++i) {
29 B0 = sm4_x86_rnds4(B0, RK_i);
32 B0.reverse().store_le(out);
36 const uint8_t inp[8 * 16],
37 std::span<const uint32_t> RK) {
43 for(
size_t i = 0; i != 8; ++i) {
45 B0 = sm4_x86_rnds4(B0, RK_i);
46 B1 = sm4_x86_rnds4(B1, RK_i);
47 B2 = sm4_x86_rnds4(B2, RK_i);
48 B3 = sm4_x86_rnds4(B3, RK_i);
51 B0.reverse().store_le(out);
52 B1.reverse().store_le(out + 32);
53 B2.reverse().store_le(out + 64);
54 B3.reverse().store_le(out + 96);
58 const uint8_t inp[2 * 16],
59 std::span<const uint32_t> RK) {
62 for(
size_t i = 0; i != 8; ++i) {
64 B0 = sm4_x86_rnds4(B0, RK_i);
67 B0.reverse().store_le(out);
71 const uint8_t inp[8 * 16],
72 std::span<const uint32_t> RK) {
78 for(
size_t i = 0; i != 8; ++i) {
80 B0 = sm4_x86_rnds4(B0, RK_i);
81 B1 = sm4_x86_rnds4(B1, RK_i);
82 B2 = sm4_x86_rnds4(B2, RK_i);
83 B3 = sm4_x86_rnds4(B3, RK_i);
86 B0.reverse().store_le(out);
87 B1.reverse().store_le(out + 32);
88 B2.reverse().store_le(out + 64);
89 B3.reverse().store_le(out + 96);
94void BOTAN_FN_ISA_AVX2_SM4 SM4::sm4_x86_encrypt(
const uint8_t inp[], uint8_t out[],
size_t blocks)
const {
96 sm4_x86_encrypt_x8(out, inp, m_RK);
103 sm4_x86_encrypt_x2(out, inp, m_RK);
110 uint8_t ibuf[2 * 16] = {0};
111 uint8_t obuf[2 * 16] = {0};
113 sm4_x86_encrypt_x2(obuf, ibuf, m_RK);
118void BOTAN_FN_ISA_AVX2_SM4 SM4::sm4_x86_decrypt(
const uint8_t inp[], uint8_t out[],
size_t blocks)
const {
120 sm4_x86_decrypt_x8(out, inp, m_RK);
127 sm4_x86_decrypt_x2(out, inp, m_RK);
134 uint8_t ibuf[2 * 16] = {0};
135 uint8_t obuf[2 * 16] = {0};
137 sm4_x86_decrypt_x2(obuf, ibuf, m_RK);
static BOTAN_FN_ISA_AVX2 SIMD_8x32 load_le128(const uint8_t *in) noexcept
BOTAN_FN_ISA_AVX2 SIMD_8x32 rev_words() const noexcept
static BOTAN_FN_ISA_AVX2 SIMD_8x32 load_be(const uint8_t *in) noexcept
#define BOTAN_FORCE_INLINE
constexpr void copy_mem(T *out, const T *in, size_t n)