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
4#include "native/isa_import.h"
5#include "native/x86/aes.h"
6#include "native/x86/aes_constant.h"
7
8export module native.x86.aes;
9export import native.x86.features;
10export import native.simd;
11
12// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
13
14#if NATIVE_HOST_X86 || defined(NATIVE_DOXYGEN)
15export namespace native {
28
30 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
32 constexpr simd<std::uint8_t, 16, Arch> aesenc(
33 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> round_key) noexcept {
34 if consteval {
35 return detail::x86_aes_constant::round<false, false>(state, round_key);
36 } else {
38 detail::x86_aes::aesenc<Arch>(state.to_native(), round_key.to_native()));
39 }
40 }
41
43 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
44 requires { sizeof(simd<std::uint8_t, 16, Arch>); })
47 return detail::x86_aes_constant::round<false, false>(state, round_key);
48 }
49
51 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
53 constexpr simd<std::uint8_t, 16, Arch> aesenclast(
54 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> round_key) noexcept {
55 if consteval {
56 return detail::x86_aes_constant::round<false, true>(state, round_key);
57 } else {
59 detail::x86_aes::aesenclast<Arch>(state.to_native(), round_key.to_native()));
60 }
61 }
62
64 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
65 requires { sizeof(simd<std::uint8_t, 16, Arch>); })
68 return detail::x86_aes_constant::round<false, true>(state, round_key);
69 }
70
72 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
74 constexpr simd<std::uint8_t, 16, Arch> aesdec(
75 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> round_key) noexcept {
76 if consteval {
77 return detail::x86_aes_constant::round<true, false>(state, round_key);
78 } else {
80 detail::x86_aes::aesdec<Arch>(state.to_native(), round_key.to_native()));
81 }
82 }
83
85 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
86 requires { sizeof(simd<std::uint8_t, 16, Arch>); })
89 return detail::x86_aes_constant::round<true, false>(state, round_key);
90 }
91
93 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
95 constexpr simd<std::uint8_t, 16, Arch> aesdeclast(
96 simd<std::uint8_t, 16, Arch> state, simd<std::uint8_t, 16, Arch> round_key) noexcept {
97 if consteval {
98 return detail::x86_aes_constant::round<true, true>(state, round_key);
99 } else {
101 detail::x86_aes::aesdeclast<Arch>(state.to_native(), round_key.to_native()));
102 }
103 }
104
106 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
107 requires { sizeof(simd<std::uint8_t, 16, Arch>); })
110 return detail::x86_aes_constant::round<true, true>(state, round_key);
111 }
112
114 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
116 constexpr simd<std::uint8_t, 16, Arch> aesimc(simd<std::uint8_t, 16, Arch> state) noexcept {
117 if consteval {
118 return detail::x86_aes_constant::inverse_mix(state);
119 } else {
120 return simd<std::uint8_t, 16, Arch>::from_native(detail::x86_aes::aesimc<Arch>(state.to_native()));
121 }
122 }
123
125 template<isa<x86> Arch> requires(!Arch.has(x86_feature::aes) &&
126 requires { sizeof(simd<std::uint8_t, 16, Arch>); })
128 return detail::x86_aes_constant::inverse_mix(state);
129 }
130
134 template<isa<x86> Arch, unsigned Imm8> requires(Arch.has(x86_feature::aes) && Imm8 <= 255)
136 constexpr simd<std::uint8_t, 16, Arch> aeskeygenassist(simd<std::uint8_t, 16, Arch> state) noexcept {
137 if consteval {
138 return detail::x86_aes_constant::keygen<Imm8>(state);
139 } else {
141 detail::x86_aes::aeskeygenassist<Arch, Imm8>(state.to_native()));
142 }
143 }
144
146 template<isa<x86> Arch, unsigned Imm8> requires(!Arch.has(x86_feature::aes) && Imm8 <= 255 &&
147 requires { sizeof(simd<std::uint8_t, 16, Arch>); })
149 return detail::x86_aes_constant::keygen<Imm8>(state);
150 }
151
153 template<isa<x86> Arch, class... Args>
154 void aesenc(Args...) = delete;
155
157 template<isa<x86> Arch, class... Args>
158 void aesenclast(Args...) = delete;
159
161 template<isa<x86> Arch, class... Args>
162 void aesdec(Args...) = delete;
163
165 template<isa<x86> Arch, class... Args>
166 void aesdeclast(Args...) = delete;
167
169 template<isa<x86> Arch, class... Args>
170 void aesimc(Args...) = delete;
171
173 template<isa<x86> Arch, unsigned Imm8, class... Args>
174 void aeskeygenassist(Args...) = delete;
175
177}
178#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.
#define native_inline
inline [[always_inline]]
Definition attributes.h:212
#define native_nodiscard
C++17 [[nodiscard]].
Definition attributes.h:189
#define native_const
[[const]] is not const
Definition attributes.h:108
#define native_target(x)
this indicates a required feature set for the current multiversioned function.
Definition attributes.h:476
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...
Standard-library adaptations documented here for SIMD value types.
Omitted architecture arguments use the native.simd provider's baseline.