Botan
3.6.1
Crypto and TLS for C&
src
lib
utils
simd
simd_avx2
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
14
namespace
Botan
{
15
16
#define BOTAN_GFNI_ISA "gfni,avx2"
17
18
// Helper for defining GFNI constants
19
consteval
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
51
template
<u
int
64_t A, u
int
8_t B>
52
BOTAN_FUNC_ISA_INLINE
(
BOTAN_GFNI_ISA
)
53
SIMD_8x32
gf2p8affine
(const
SIMD_8x32
& x) {
54
return
SIMD_8x32
(_mm256_gf2p8affine_epi64_epi8(x.raw(), _mm256_set1_epi64x(A), B));
55
}
56
57
template
<u
int
64_t A, u
int
8_t B>
58
BOTAN_FUNC_ISA_INLINE
(
BOTAN_GFNI_ISA
)
59
SIMD_8x32
gf2p8affineinv
(const
SIMD_8x32
& x) {
60
return
SIMD_8x32
(_mm256_gf2p8affineinv_epi64_epi8(x.raw(), _mm256_set1_epi64x(A), B));
61
}
62
63
BOTAN_FUNC_ISA_INLINE
(
BOTAN_GFNI_ISA
)
SIMD_8x32
gf2p8mul(
const
SIMD_8x32
& a,
const
SIMD_8x32
&
b
) {
64
return
SIMD_8x32
(_mm256_gf2p8mul_epi8(a.raw(),
b
.raw()));
65
}
66
67
}
// namespace Botan
68
69
#endif
Botan::SIMD_8x32
Definition
simd_avx2.h:17
BOTAN_FUNC_ISA_INLINE
#define BOTAN_FUNC_ISA_INLINE(isa)
Definition
compiler.h:98
Botan
Definition
alg_id.cpp:13
Botan::gf2p8affine
SIMD_8x32 gf2p8affine(const SIMD_8x32 &x)
Definition
simd_avx2_gfni.h:53
Botan::gfni_matrix
consteval uint64_t gfni_matrix(std::string_view s)
Definition
simd_avx2_gfni.h:19
Botan::b
const SIMD_8x32 & b
Definition
simd_avx2_gfni.h:63
Botan::gf2p8affineinv
SIMD_8x32 gf2p8affineinv(const SIMD_8x32 &x)
Definition
simd_avx2_gfni.h:59
BOTAN_GFNI_ISA
#define BOTAN_GFNI_ISA
Definition
simd_avx2_gfni.h:16
Generated by
1.12.0