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>
18 return SIMD_8x32(_mm256_sm4rnds4_epi32(b.raw(), k.raw()));
22 const uint8_t inp[2 * 16],
23 std::span<const uint32_t> RK) {
26 for(
size_t i = 0; i != 8; ++i) {
28 B0 = sm4_x86_rnds4(B0, RK_i);
31 B0.reverse().store_le(out);
35 const uint8_t inp[8 * 16],
36 std::span<const uint32_t> RK) {
42 for(
size_t i = 0; i != 8; ++i) {
44 B0 = sm4_x86_rnds4(B0, RK_i);
45 B1 = sm4_x86_rnds4(B1, RK_i);
46 B2 = sm4_x86_rnds4(B2, RK_i);
47 B3 = sm4_x86_rnds4(B3, RK_i);
50 B0.reverse().store_le(out);
51 B1.reverse().store_le(out + 32);
52 B2.reverse().store_le(out + 64);
53 B3.reverse().store_le(out + 96);
57 const uint8_t inp[2 * 16],
58 std::span<const uint32_t> RK) {
61 for(
size_t i = 0; i != 8; ++i) {
63 B0 = sm4_x86_rnds4(B0, RK_i);
66 B0.reverse().store_le(out);
70 const uint8_t inp[8 * 16],
71 std::span<const uint32_t> RK) {
77 for(
size_t i = 0; i != 8; ++i) {
79 B0 = sm4_x86_rnds4(B0, RK_i);
80 B1 = sm4_x86_rnds4(B1, RK_i);
81 B2 = sm4_x86_rnds4(B2, RK_i);
82 B3 = sm4_x86_rnds4(B3, RK_i);
85 B0.reverse().store_le(out);
86 B1.reverse().store_le(out + 32);
87 B2.reverse().store_le(out + 64);
88 B3.reverse().store_le(out + 96);
93void BOTAN_FN_ISA_AVX2_SM4 SM4::sm4_x86_encrypt(
const uint8_t inp[], uint8_t out[],
size_t blocks)
const {
95 sm4_x86_encrypt_x8(out, inp, m_RK);
102 sm4_x86_encrypt_x2(out, inp, m_RK);
109 uint8_t ibuf[2 * 16] = {0};
110 uint8_t obuf[2 * 16] = {0};
112 sm4_x86_encrypt_x2(obuf, ibuf, m_RK);
117void BOTAN_FN_ISA_AVX2_SM4 SM4::sm4_x86_decrypt(
const uint8_t inp[], uint8_t out[],
size_t blocks)
const {
119 sm4_x86_decrypt_x8(out, inp, m_RK);
126 sm4_x86_decrypt_x2(out, inp, m_RK);
133 uint8_t ibuf[2 * 16] = {0};
134 uint8_t obuf[2 * 16] = {0};
136 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)