Botan
3.11.1
Crypto and TLS for C&
src
lib
utils
gfni_utils.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_GFNI_UTILS_H_
8
#define BOTAN_SIMD_GFNI_UTILS_H_
9
10
#include <botan/types.h>
11
#include <stdexcept>
12
#include <string_view>
13
14
namespace
Botan
{
15
16
// Helper for defining GFNI constants
17
consteval
uint64_t
gfni_matrix
(std::string_view s) {
18
uint64_t matrix = 0;
19
size_t
bit_cnt = 0;
20
uint8_t row = 0;
21
22
for
(
const
char
c : s) {
23
if
(c ==
' '
|| c ==
'\n'
) {
24
continue
;
25
}
26
if
(c !=
'0'
&& c !=
'1'
) {
27
throw
std::runtime_error(
"gfni_matrix: invalid bit value"
);
28
}
29
30
if
(c ==
'1'
) {
31
row |= 0x80 >> (7 - bit_cnt % 8);
32
}
33
bit_cnt++;
34
35
if
(bit_cnt % 8 == 0) {
36
matrix <<= 8;
37
matrix |= row;
38
row = 0;
39
}
40
}
41
42
if
(bit_cnt != 64) {
43
throw
std::runtime_error(
"gfni_matrix: invalid bit count"
);
44
}
45
46
return
matrix;
47
}
48
49
}
// namespace Botan
50
51
#endif
Botan
Definition
alg_id.cpp:13
Botan::gfni_matrix
consteval uint64_t gfni_matrix(std::string_view s)
Definition
gfni_utils.h:17
Generated by
1.15.0