5#include "native/x86/detail/constant_lanes.h"
9namespace native::detail::x86_aes_constant {
10 using aes_constant::field_inverse;
11 using aes_constant::field_product;
12 using aes_constant::substitute;
13 using aes_constant::mix;
14 using x86_constant::lanes;
16 template<
bool Inverse,
bool Last,
class V>
17 constexpr V round(V state, V key)
noexcept {
19 static_assert(V::lanes % 16 == 0);
20 auto input = lanes(state);
22 auto round_key = lanes(key);
23 for (
unsigned base = 0; base < V::lanes; base += 16) {
24 std::array<std::uint8_t, 16> block{};
25 for (
unsigned i = 0; i < 16; ++i) block[i] = input[base + i];
26 block = aes_constant::shift_substitute<Inverse>(block);
27 if constexpr (!Last) block = mix<Inverse>(block);
28 for (
unsigned i = 0; i < 16; ++i) result[base + i] = block[i] ^ round_key[base + i];
30 return V::load(result.data());
34 constexpr V inverse_mix(V state)
noexcept {
35 auto result = mix<true>(lanes(state));
36 return V::load(result.data());
39 template<
unsigned Imm8,
class V>
40 constexpr V keygen(V state)
noexcept {
41 auto input = lanes(state);
43 for (
unsigned half = 0; half < 2; ++half) {
44 auto source = 8 * half + 4;
45 for (
unsigned i = 0; i < 4; ++i) {
46 result[8 * half + i] = substitute<false>(input[source + i]);
47 result[8 * half + 4 + i] = substitute<false>(input[source + (i + 1) % 4]);
49 result[8 * half + 4] ^= Imm8;
51 return V::load(result.data());
Shared AES byte operations for constant evaluation on ARM and x86.