native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
aes.h
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2#pragma once
3
5
6#include "native/config.h"
7#include "native/attributes.h"
8#include "native/isa.h"
9
10#if NATIVE_HOST_X86
11#include <immintrin.h>
12#endif
13
14#if NATIVE_HOST_X86 || defined(NATIVE_DOXYGEN)
15namespace native::detail::x86_aes {
16
17 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
19 __m128i aesenc(__m128i state, __m128i round_key) noexcept {
20 return _mm_aesenc_si128(state, round_key);
21 }
22
23 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
25 __m128i aesenclast(__m128i state, __m128i round_key) noexcept {
26 return _mm_aesenclast_si128(state, round_key);
27 }
28
29 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
31 __m128i aesdec(__m128i state, __m128i round_key) noexcept {
32 return _mm_aesdec_si128(state, round_key);
33 }
34
35 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
37 __m128i aesdeclast(__m128i state, __m128i round_key) noexcept {
38 return _mm_aesdeclast_si128(state, round_key);
39 }
40
41 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes))
43 __m128i aesimc(__m128i state) noexcept {
44 return _mm_aesimc_si128(state);
45 }
46
47 template<isa<x86> Arch, unsigned Imm8> requires(Arch.has(x86_feature::aes) && Imm8 <= 255)
49 __m128i aeskeygenassist(__m128i state) noexcept {
50 return _mm_aeskeygenassist_si128(state, Imm8);
51 }
52
53 template<isa<x86> Arch, class... Args>
54 void aesenc(Args...) = delete;
55
56 template<isa<x86> Arch, class... Args>
57 void aesenclast(Args...) = delete;
58
59 template<isa<x86> Arch, class... Args>
60 void aesdec(Args...) = delete;
61
62 template<isa<x86> Arch, class... Args>
63 void aesdeclast(Args...) = delete;
64
65 template<isa<x86> Arch, class... Args>
66 void aesimc(Args...) = delete;
67
68 template<isa<x86> Arch, unsigned Imm8, class... Args>
69 void aeskeygenassist(Args...) = delete;
70}
71#endif
Compiler attributes for host code, with shader-safe shared modifiers.
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.