Botan 3.6.1
Crypto and TLS for C&
simd_avx2_gfni.h
Go to the documentation of this file.
1/*
2* (C) 2024 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_SIMD_AVX2_GFNI_H_
8#define BOTAN_SIMD_AVX2_GFNI_H_
9
10#include <botan/internal/simd_avx2.h>
11#include <stdexcept>
12#include <string_view>
13
14namespace Botan {
15
16#define BOTAN_GFNI_ISA "gfni,avx2"
17
18// Helper for defining GFNI constants
19consteval uint64_t gfni_matrix(std::string_view s) {
20 uint64_t matrix = 0;
21 size_t bit_cnt = 0;
22 uint8_t row = 0;
23
24 for(char c : s) {
25 if(c == ' ' || c == '\n') {
26 continue;
27 }
28 if(c != '0' && c != '1') {
29 throw std::runtime_error("gfni_matrix: invalid bit value");
30 }
31
32 if(c == '1') {
33 row |= 0x80 >> (7 - bit_cnt % 8);
34 }
35 bit_cnt++;
36
37 if(bit_cnt % 8 == 0) {
38 matrix <<= 8;
39 matrix |= row;
40 row = 0;
41 }
42 }
43
44 if(bit_cnt != 64) {
45 throw std::runtime_error("gfni_matrix: invalid bit count");
46 }
47
48 return matrix;
49}
50
51template <uint64_t A, uint8_t B>
54 return SIMD_8x32(_mm256_gf2p8affine_epi64_epi8(x.raw(), _mm256_set1_epi64x(A), B));
55}
56
57template <uint64_t A, uint8_t B>
60 return SIMD_8x32(_mm256_gf2p8affineinv_epi64_epi8(x.raw(), _mm256_set1_epi64x(A), B));
61}
62
64 return SIMD_8x32(_mm256_gf2p8mul_epi8(a.raw(), b.raw()));
65}
66
67} // namespace Botan
68
69#endif
#define BOTAN_FUNC_ISA_INLINE(isa)
Definition compiler.h:98
SIMD_8x32 gf2p8affine(const SIMD_8x32 &x)
consteval uint64_t gfni_matrix(std::string_view s)
const SIMD_8x32 & b
SIMD_8x32 gf2p8affineinv(const SIMD_8x32 &x)
#define BOTAN_GFNI_ISA