native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.x86.vaes.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/vaes.h"
7
8export module native.x86.vaes;
9export import native.x86.features;
10export import native.simd;
11
12#if NATIVE_HOST_X86 || defined(NATIVE_DOXYGEN)
13export namespace native {
23
25 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
26 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
27 constexpr simd<std::uint8_t, 16, Arch> vaesenc(
28 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> key) noexcept {
29 if consteval {
30 return detail::x86_vaes_constant::round<false, false>(state, key);
31 } else {
32 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
33 detail::x86_vaes::vaesenc<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
34 }
35 }
36
38 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
39 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
40 [[nodiscard]] consteval simd<std::uint8_t, 16, Arch> vaesenc(
42 return detail::x86_vaes_constant::round<false, false>(state, key);
43 }
44
46 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
47 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
48 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> vaesenc(
50 return detail::x86_vaes_constant::round<false, false>(state, key);
51 }
52
54 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
55 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
58 if consteval {
59 return detail::x86_vaes_constant::round<false, false>(state, key);
60 } else {
61 return detail::x86_instruction_result<simd<std::uint8_t, 32, Arch>>(
62 detail::x86_vaes::vaesenc<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
63 }
64 }
65
67 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
68 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && !Arch.has(polyfill))
69 [[nodiscard]] consteval simd<std::uint8_t, 32, Arch> vaesenc(
71 return detail::x86_vaes_constant::round<false, false>(state, key);
72 }
73
75 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
76 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && Arch.has(polyfill))
77 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 32, Arch> vaesenc(
79 return detail::x86_vaes_constant::round<false, false>(state, key);
80 }
81
83 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
84 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
87 if consteval {
88 return detail::x86_vaes_constant::round<false, false>(state, key);
89 } else {
90 return detail::x86_instruction_result<simd<std::uint8_t, 64, Arch>>(
91 detail::x86_vaes::vaesenc<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
92 }
93 }
94
96 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
97 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && !Arch.has(polyfill))
98 [[nodiscard]] consteval simd<std::uint8_t, 64, Arch> vaesenc(
100 return detail::x86_vaes_constant::round<false, false>(state, key);
101 }
102
104 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
105 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && Arch.has(polyfill))
106 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 64, Arch> vaesenc(
108 return detail::x86_vaes_constant::round<false, false>(state, key);
109 }
110
112 template<isa<x86> Arch, class... Args>
113 void vaesenc(Args...) = delete;
114
116 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
117 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
118 constexpr simd<std::uint8_t, 16, Arch> vaesenclast(
119 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> key) noexcept {
120 if consteval {
121 return detail::x86_vaes_constant::round<false, true>(state, key);
122 } else {
123 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
124 detail::x86_vaes::vaesenclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
125 }
126 }
127
129 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
130 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
133 return detail::x86_vaes_constant::round<false, true>(state, key);
134 }
135
137 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
138 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
139 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> vaesenclast(
141 return detail::x86_vaes_constant::round<false, true>(state, key);
142 }
143
145 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
146 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
149 if consteval {
150 return detail::x86_vaes_constant::round<false, true>(state, key);
151 } else {
152 return detail::x86_instruction_result<simd<std::uint8_t, 32, Arch>>(
153 detail::x86_vaes::vaesenclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
154 }
155 }
156
158 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
159 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && !Arch.has(polyfill))
162 return detail::x86_vaes_constant::round<false, true>(state, key);
163 }
164
166 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
167 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && Arch.has(polyfill))
168 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 32, Arch> vaesenclast(
170 return detail::x86_vaes_constant::round<false, true>(state, key);
171 }
172
174 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
175 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
178 if consteval {
179 return detail::x86_vaes_constant::round<false, true>(state, key);
180 } else {
181 return detail::x86_instruction_result<simd<std::uint8_t, 64, Arch>>(
182 detail::x86_vaes::vaesenclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
183 }
184 }
185
187 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
188 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && !Arch.has(polyfill))
191 return detail::x86_vaes_constant::round<false, true>(state, key);
192 }
193
195 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
196 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && Arch.has(polyfill))
197 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 64, Arch> vaesenclast(
199 return detail::x86_vaes_constant::round<false, true>(state, key);
200 }
201
203 template<isa<x86> Arch, class... Args>
204 void vaesenclast(Args...) = delete;
205
207 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
208 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
209 constexpr simd<std::uint8_t, 16, Arch> vaesdec(
210 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> key) noexcept {
211 if consteval {
212 return detail::x86_vaes_constant::round<true, false>(state, key);
213 } else {
214 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
215 detail::x86_vaes::vaesdec<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
216 }
217 }
218
220 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
221 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
222 [[nodiscard]] consteval simd<std::uint8_t, 16, Arch> vaesdec(
224 return detail::x86_vaes_constant::round<true, false>(state, key);
225 }
226
228 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
229 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
230 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> vaesdec(
232 return detail::x86_vaes_constant::round<true, false>(state, key);
233 }
234
236 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
237 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
240 if consteval {
241 return detail::x86_vaes_constant::round<true, false>(state, key);
242 } else {
243 return detail::x86_instruction_result<simd<std::uint8_t, 32, Arch>>(
244 detail::x86_vaes::vaesdec<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
245 }
246 }
247
249 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
250 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && !Arch.has(polyfill))
251 [[nodiscard]] consteval simd<std::uint8_t, 32, Arch> vaesdec(
253 return detail::x86_vaes_constant::round<true, false>(state, key);
254 }
255
257 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
258 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && Arch.has(polyfill))
259 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 32, Arch> vaesdec(
261 return detail::x86_vaes_constant::round<true, false>(state, key);
262 }
263
265 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
266 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
269 if consteval {
270 return detail::x86_vaes_constant::round<true, false>(state, key);
271 } else {
272 return detail::x86_instruction_result<simd<std::uint8_t, 64, Arch>>(
273 detail::x86_vaes::vaesdec<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
274 }
275 }
276
278 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
279 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && !Arch.has(polyfill))
280 [[nodiscard]] consteval simd<std::uint8_t, 64, Arch> vaesdec(
282 return detail::x86_vaes_constant::round<true, false>(state, key);
283 }
284
286 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
287 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && Arch.has(polyfill))
288 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 64, Arch> vaesdec(
290 return detail::x86_vaes_constant::round<true, false>(state, key);
291 }
292
294 template<isa<x86> Arch, class... Args>
295 void vaesdec(Args...) = delete;
296
298 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
299 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
300 constexpr simd<std::uint8_t, 16, Arch> vaesdeclast(
301 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> key) noexcept {
302 if consteval {
303 return detail::x86_vaes_constant::round<true, true>(state, key);
304 } else {
305 return detail::x86_instruction_result<simd<std::uint8_t, 16, Arch>>(
306 detail::x86_vaes::vaesdeclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
307 }
308 }
309
311 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
312 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && !Arch.has(polyfill))
315 return detail::x86_vaes_constant::round<true, true>(state, key);
316 }
317
319 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx)) &&
320 requires { sizeof(simd<std::uint8_t, 16, Arch>); } && Arch.has(polyfill))
321 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 16, Arch> vaesdeclast(
323 return detail::x86_vaes_constant::round<true, true>(state, key);
324 }
325
327 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
328 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
331 if consteval {
332 return detail::x86_vaes_constant::round<true, true>(state, key);
333 } else {
334 return detail::x86_instruction_result<simd<std::uint8_t, 32, Arch>>(
335 detail::x86_vaes::vaesdeclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
336 }
337 }
338
340 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
341 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && !Arch.has(polyfill))
344 return detail::x86_vaes_constant::round<true, true>(state, key);
345 }
346
348 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx)) &&
349 requires { sizeof(simd<std::uint8_t, 32, Arch>); } && Arch.has(polyfill))
350 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 32, Arch> vaesdeclast(
352 return detail::x86_vaes_constant::round<true, true>(state, key);
353 }
354
356 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
357 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
360 if consteval {
361 return detail::x86_vaes_constant::round<true, true>(state, key);
362 } else {
363 return detail::x86_instruction_result<simd<std::uint8_t, 64, Arch>>(
364 detail::x86_vaes::vaesdeclast<Arch>(detail::x86_integer_register(state), detail::x86_integer_register(key)));
365 }
366 }
367
369 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
370 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && !Arch.has(polyfill))
373 return detail::x86_vaes_constant::round<true, true>(state, key);
374 }
375
377 template<isa<x86> Arch> requires(!(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f)) &&
378 requires { sizeof(simd<std::uint8_t, 64, Arch>); } && Arch.has(polyfill))
379 [[nodiscard]] hint_inline constexpr simd<std::uint8_t, 64, Arch> vaesdeclast(
381 return detail::x86_vaes_constant::round<true, true>(state, key);
382 }
383
385 template<isa<x86> Arch, class... Args>
386 void vaesdeclast(Args...) = delete;
387
389}
390#endif
constexpr simd< std::uint8_t, 16, Arch > vaesenc(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > key) noexcept
One AES encryption round.
constexpr simd< std::uint8_t, 16, Arch > vaesenclast(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > key) noexcept
One final AES encryption round.
constexpr simd< std::uint8_t, 16, Arch > vaesdec(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > key) noexcept
One AES decryption round.
constexpr simd< std::uint8_t, 16, Arch > vaesdeclast(simd< std::uint8_t, 16, Arch > state, simd< std::uint8_t, 16, Arch > key) noexcept
One final AES decryption round.
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
Standard-library adaptations documented here for SIMD value types.
Omitted architecture arguments use the native.simd provider's baseline.