7#ifndef BOTAN_SIMD_HWAES_H_
8#define BOTAN_SIMD_HWAES_H_
10#include <botan/internal/gfni_utils.h>
11#include <botan/internal/isa_extn.h>
12#include <botan/internal/simd_4x32.h>
21 const auto inv_sr =
SIMD_4x32(0x070A0D00, 0x0B0E0104, 0x0F020508, 0x0306090C);
23#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
24 auto enc =
SIMD_4x32(_mm_aesenclast_si128(x.
raw(), _mm_setzero_si128()));
25#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
26 auto enc =
SIMD_4x32(vreinterpretq_u32_u8(vaeseq_u8(vreinterpretq_u8_u32(x.
raw()), vdupq_n_u8(0))));
28 #error "hw_aes_sbox not implemented for this architecture"
39 const auto sr =
SIMD_4x32(0x0F0A0500, 0x030E0904, 0x07020D08, 0x0B06010C);
41#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
42 auto dec =
SIMD_4x32(_mm_aesdeclast_si128(x.
raw(), _mm_setzero_si128()));
43#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
44 auto dec =
SIMD_4x32(vreinterpretq_u32_u8(vaesdq_u8(vreinterpretq_u8_u32(x.
raw()), vdupq_n_u8(0))));
46 #error "hw_aes_inv_sbox not implemented for this architecture"
60 for(
size_t i = 0; i != 8; ++i) {
62 for(
size_t j = 0; j != 8; ++j) {
63 if(((M >> (56 - 8 * i + j)) & 1) == 1) {
77 for(
size_t i = 0; i != 8; ++i) {
78 for(
size_t j = 0; j != 8; ++j) {
80 for(
size_t k = 0; k != 8; ++k) {
81 auto a_ik =
static_cast<uint8_t
>((A >> (56 - 8 * i + k)) & 1);
82 auto b_kj =
static_cast<uint8_t
>((B >> (56 - 8 * k + j)) & 1);
86 result |= uint64_t(1) << (56 - 8 * i + j);
125 for(
size_t i = 0; i != 16; ++i) {
130 lo[i / 4] |=
static_cast<uint32_t
>(lo_val) << (8 * (i % 4));
131 hi[i / 4] |=
static_cast<uint32_t
>(hi_val) << (8 * (i % 4));
156 const SIMD_4x32 tbl_lo(lo[0], lo[1], lo[2], lo[3]);
157 const SIMD_4x32 tbl_hi(hi[0], hi[1], hi[2], hi[3]);
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 shr() const noexcept
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 byte_shuffle(const SIMD_4x32 &tbl, const SIMD_4x32 &idx)
native_simd_type BOTAN_FN_ISA_SIMD_4X32 raw() const noexcept
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 splat_u8(uint8_t B) noexcept
constexpr uint64_t AES_AFF
consteval uint8_t gf2_mat_vec(uint64_t M, uint8_t x)
consteval uint64_t gf2_mat_mul(uint64_t A, uint64_t B)
constexpr uint64_t AES_AFF_INV
constexpr uint8_t AES_C_INV
consteval uint64_t gfni_matrix(std::string_view s)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_inv_sbox(SIMD_4x32 x)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_sbox(SIMD_4x32 x)