7#include <botan/internal/seed.h>
9#include <botan/mem_ops.h>
10#include <botan/internal/isa_extn.h>
11#include <botan/internal/simd_4x32.h>
12#include <botan/internal/simd_hwaes.h>
42 constexpr uint8_t s0_post_c = 0xA9;
54 constexpr uint8_t s1_post_c = 0x38;
61 const auto sub =
hw_aes_sbox(pre.affine_transform(X));
64 const auto s0 = post_s0.affine_transform(sub);
65 const auto s1 = post_s1.affine_transform(sub);
77 const auto SHUF0 =
SIMD_4x32(0x00000000, 0x04040404, 0x08080808, 0x0C0C0C0C);
78 const auto SHUF1 =
SIMD_4x32(0x01010101, 0x05050505, 0x09090909, 0x0D0D0D0D);
79 const auto SHUF2 =
SIMD_4x32(0x02020202, 0x06060606, 0x0A0A0A0A, 0x0E0E0E0E);
80 const auto SHUF3 =
SIMD_4x32(0x03030303, 0x07070707, 0x0B0B0B0B, 0x0F0F0F0F);
87 return (b0 & M0) ^ (b1 & M1) ^ (b2 & M2) ^ (b3 & M3);
101 T0 = seed_g(T1 + T0);
102 T1 = seed_g(T1 + T0);
107BOTAN_FN_ISA_HWAES
void encrypt_4(
const uint8_t ptext[4 * 16], uint8_t ctext[4 * 16], std::span<const uint32_t> RK) {
115 for(
size_t j = 0; j != 8; ++j) {
116 const uint32_t K0 = RK[4 * j];
117 const uint32_t K1 = RK[4 * j + 1];
118 const uint32_t K2 = RK[4 * j + 2];
119 const uint32_t K3 = RK[4 * j + 3];
121 seed_round(B0, B1, B2, B3, K0, K1, K2, K3);
133BOTAN_FN_ISA_HWAES
void decrypt_4(
const uint8_t ctext[4 * 16], uint8_t ptext[4 * 16], std::span<const uint32_t> RK) {
141 for(
size_t j = 0; j != 8; ++j) {
142 const uint32_t K0 = RK[30 - 4 * j];
143 const uint32_t K1 = RK[31 - 4 * j];
144 const uint32_t K2 = RK[28 - 4 * j];
145 const uint32_t K3 = RK[29 - 4 * j];
147 seed_round(B0, B1, B2, B3, K0, K1, K2, K3);
162void BOTAN_FN_ISA_HWAES SEED::hwaes_encrypt(
const uint8_t ptext[], uint8_t ctext[],
size_t blocks)
const {
164 SEED_HWAES::encrypt_4(ptext, ctext, m_K);
171 uint8_t pbuf[4 * 16] = {0};
172 uint8_t cbuf[4 * 16] = {0};
174 SEED_HWAES::encrypt_4(pbuf, cbuf, m_K);
179void BOTAN_FN_ISA_HWAES SEED::hwaes_decrypt(
const uint8_t ctext[], uint8_t ptext[],
size_t blocks)
const {
181 SEED_HWAES::decrypt_4(ctext, ptext, m_K);
188 uint8_t cbuf[4 * 16] = {0};
189 uint8_t pbuf[4 * 16] = {0};
191 SEED_HWAES::decrypt_4(cbuf, pbuf, m_K);
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 load_be(const void *in) noexcept
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 byte_shuffle(const SIMD_4x32 &tbl, const SIMD_4x32 &idx)
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 byte_blend(const SIMD_4x32 &mask, const SIMD_4x32 &a, const SIMD_4x32 &b) noexcept
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 splat(uint32_t B) noexcept
static void BOTAN_FN_ISA_SIMD_4X32 transpose(SIMD_4x32 &B0, SIMD_4x32 &B1, SIMD_4x32 &B2, SIMD_4x32 &B3) noexcept
void BOTAN_FN_ISA_SIMD_4X32 store_be(uint32_t out[4]) const noexcept
#define BOTAN_FORCE_INLINE
constexpr void copy_mem(T *out, const T *in, size_t n)
consteval uint64_t gfni_matrix(std::string_view s)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_sbox(SIMD_4x32 x)