native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.x86.aes.ccm
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2module;
3#include "native/x86/instruction_storage.h"
4
5#include "native/isa_import.h"
6#include "native/x86/aes.h"
7#include "native/x86/aes_constant.h"
8
9export module native.x86.aes;
10export import native.x86.features;
11export import native.simd;
12
13#if NATIVE_HOST_X86 || defined(NATIVE_DOXYGEN)
14export namespace native {
27
29 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
30 [[nodiscard]] hint_inline hint_const hint_target("aes")
31 constexpr simd<std::uint8_t, 16, Arch> aesenc(
32 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> round_key) noexcept {
33 if consteval {
34 return detail::x86_aes_constant::round<false, false>(state, round_key);
35 } else {
36 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
37 detail::x86_aes::aesenc<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(round_key)));
38 }
39 }
40
42 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
43 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
44 [[nodiscard]] consteval simd<std::uint8_t, 16, Arch> aesenc(
46 return detail::x86_aes_constant::round<false, false>(state, round_key);
47 }
48
50 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
51 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
52 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> aesenc(
54 return detail::x86_aes_constant::round<false, false>(state, round_key);
55 }
56
58 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
59 [[nodiscard]] hint_inline hint_const hint_target("aes")
62 if consteval {
63 return detail::x86_aes_constant::round<false, true>(state, round_key);
64 } else {
65 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
66 detail::x86_aes::aesenclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(round_key)));
67 }
68 }
69
71 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
72 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
75 return detail::x86_aes_constant::round<false, true>(state, round_key);
76 }
77
79 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
80 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
81 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> aesenclast(
83 return detail::x86_aes_constant::round<false, true>(state, round_key);
84 }
85
87 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
88 [[nodiscard]] hint_inline hint_const hint_target("aes")
91 if consteval {
92 return detail::x86_aes_constant::round<true, false>(state, round_key);
93 } else {
94 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
95 detail::x86_aes::aesdec<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(round_key)));
96 }
97 }
98
100 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
101 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
102 [[nodiscard]] consteval simd<std::uint8_t, 16, Arch> aesdec(
104 return detail::x86_aes_constant::round<true, false>(state, round_key);
105 }
106
108 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
109 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
110 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> aesdec(
112 return detail::x86_aes_constant::round<true, false>(state, round_key);
113 }
114
116 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
117 [[nodiscard]] hint_inline hint_const hint_target("aes")
120 if consteval {
121 return detail::x86_aes_constant::round<true, true>(state, round_key);
122 } else {
123 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
124 detail::x86_aes::aesdeclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(round_key)));
125 }
126 }
127
129 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
130 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
133 return detail::x86_aes_constant::round<true, true>(state, round_key);
134 }
135
137 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
138 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
139 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> aesdeclast(
141 return detail::x86_aes_constant::round<true, true>(state, round_key);
142 }
143
145 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
146 [[nodiscard]] hint_inline hint_const hint_target("aes")
148 if consteval {
149 return detail::x86_aes_constant::inverse_mix(state);
150 } else {
151 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(detail::x86_aes::aesimc<Arch>(detail::x86_integer_register(state)));
152 }
153 }
154
156 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
157 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
158 [[nodiscard]] consteval simd<std::uint8_t, 16, Arch> aesimc(simd<std::uint8_t, 16, Arch> state) noexcept {
159 return detail::x86_aes_constant::inverse_mix(state);
160 }
161
163 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
164 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
165 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> aesimc(simd<std::uint8_t, 16, Arch> state) noexcept {
166 return detail::x86_aes_constant::inverse_mix(state);
167 }
168
172 template<isa<x86> Arch, unsigned Imm8> requires(Arch.has(x86_feature::aes) && Imm8 <= 255)
173 [[nodiscard]] hint_inline hint_const hint_target("aes")
175 if consteval {
176 return detail::x86_aes_constant::keygen<Imm8>(state);
177 } else {
178 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
179 detail::x86_aes::aeskeygenassist<Arch, Imm8>(detail::x86_integer_register(state)));
180 }
181 }
182
184 template<isa<x86> Arch, unsigned Imm8> requires(!Arch.has(x86_feature::aes) && Imm8 <= 255 &&
185 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
187 return detail::x86_aes_constant::keygen<Imm8>(state);
188 }
189
191 template<isa<x86> Arch, unsigned Imm8> requires(!Arch.has(x86_feature::aes) && Imm8 <= 255 &&
192 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
193 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> aeskeygenassist(simd<std::uint8_t, 16, Arch> state) noexcept {
194 return detail::x86_aes_constant::keygen<Imm8>(state);
195 }
196
198 template<isa<x86> Arch, class... Args>
199 void aesenc(Args...) = delete;
200
202 template<isa<x86> Arch, class... Args>
203 void aesenclast(Args...) = delete;
204
206 template<isa<x86> Arch, class... Args>
207 void aesdec(Args...) = delete;
208
210 template<isa<x86> Arch, class... Args>
211 void aesdeclast(Args...) = delete;
212
214 template<isa<x86> Arch, class... Args>
215 void aesimc(Args...) = delete;
216
218 template<isa<x86> Arch, unsigned Imm8, class... Args>
219 void aeskeygenassist(Args...) = delete;
220
222}
223#endif
constexpr simd< std::uint8_t, 16, Arch > aesimc(simd< std::uint8_t, 16, Arch > state) noexcept
Apply inverse AES MixColumns independently to the four state columns.
constexpr simd< std::uint8_t, 16, Arch > aesdeclast(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > round_key) noexcept
Apply inverse ShiftRows, inverse SubBytes and then AddRoundKey for the final decryption round.
constexpr simd< std::uint8_t, 16, Arch > aesenclast(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > round_key) noexcept
Apply ShiftRows, SubBytes and then AddRoundKey for the final encryption round.
constexpr simd< std::uint8_t, 16, Arch > aesdec(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > round_key) noexcept
Apply inverse ShiftRows, inverse SubBytes, inverse MixColumns and then AddRoundKey.
constexpr simd< std::uint8_t, 16, Arch > aeskeygenassist(simd< std::uint8_t, 16, Arch > state) noexcept
constexpr simd< std::uint8_t, 16, Arch > aesenc(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > round_key) noexcept
Apply ShiftRows, SubBytes, MixColumns and then AddRoundKey.
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
constexpr polyfill_t polyfill
Compose this permission with an ISA using A | polyfill. Used alone, it selects scalar emulation in th...
Definition isa.h:43
Standard-library adaptations documented here for SIMD value types.
Omitted architecture arguments use the native.simd provider's baseline.