Botan
3.7.1
Crypto and TLS for C&
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Variables
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerations
a
c
d
e
f
g
h
k
l
m
n
o
p
r
s
t
u
v
w
Enumerator
c
d
f
i
m
n
r
s
t
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
f
h
i
m
n
o
p
r
s
t
u
v
w
Enumerations
b
c
d
e
k
m
n
o
p
s
t
x
Enumerator
_
a
b
c
d
e
f
h
k
l
m
n
p
q
r
s
t
u
w
x
Related Symbols
b
c
d
e
f
k
o
p
s
t
x
Files
File List
File Members
All
_
a
b
c
d
e
f
i
k
m
n
o
p
q
s
t
u
w
x
y
z
Functions
b
c
Variables
Typedefs
b
c
e
p
t
Enumerations
Enumerator
b
c
d
e
k
n
Macros
_
a
b
c
f
m
n
q
s
t
w
src
lib
pubkey
classic_mceliece
cmce_field_ordering.h
Go to the documentation of this file.
1
/*
2
* Classic McEliece Field Ordering Generation
3
* (C) 2023 Jack Lloyd
4
* 2023,2024 Fabian Albert, Amos Treiber - Rohde & Schwarz Cybersecurity
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
**/
8
9
#ifndef BOTAN_CMCE_FIELD_ORDERING_H_
10
#define BOTAN_CMCE_FIELD_ORDERING_H_
11
12
#include <botan/internal/cmce_parameters.h>
13
#include <botan/internal/cmce_types.h>
14
15
#include <numeric>
16
17
namespace
Botan
{
18
19
/**
20
* @brief Represents a field ordering for the Classic McEliece cryptosystem.
21
*
22
* Field ordering corresponds to the permutation pi defining the alpha sequence in
23
* the Classic McEliece specification (see Classic McEliece ISO Sec. 8.2.).
24
*/
25
class
BOTAN_TEST_API
Classic_McEliece_Field_Ordering
{
26
public
:
27
/**
28
* @brief Creates a field ordering from a random bit sequence. Corresponds to
29
* the algorithm described in Classic McEliece ISO Sec. 8.2.
30
*
31
* @param params The McEliece parameters.
32
* @param random_bits The random bit sequence.
33
* @return The field ordering.
34
*/
35
static
std::optional<Classic_McEliece_Field_Ordering> create_field_ordering(
36
const
Classic_McEliece_Parameters
& params,
StrongSpan<const CmceOrderingBits>
random_bits);
37
38
/**
39
* @brief Create the field ordering from the control bits of a benes network.
40
*
41
* @param params The McEliece parameters.
42
* @param control_bits The control bits of the benes network.
43
* @return The field ordering.
44
*/
45
static
Classic_McEliece_Field_Ordering
create_from_control_bits(
const
Classic_McEliece_Parameters
& params,
46
const
secure_bitvector
& control_bits);
47
48
/**
49
* @brief Returns the field ordering as a vector of all alphas from alpha_0 to alpha_{n-1}.
50
*
51
* @param n The number of alphas to return.
52
* @return the vector of n alphas.
53
*/
54
std::vector<Classic_McEliece_GF> alphas(
size_t
n)
const
;
55
56
/**
57
* @brief Generates the control bits of the benes network corresponding to the field ordering.
58
*
59
* @return the control bits.
60
*/
61
secure_bitvector
alphas_control_bits()
const
;
62
63
/**
64
* @brief The pi values representing the field ordering.
65
*
66
* @return pi values.
67
*/
68
CmcePermutation
&
pi_ref
() {
return
m_pi; }
69
70
/**
71
* @brief The pi values representing the field ordering.
72
*
73
* @return pi values.
74
*/
75
const
CmcePermutation
&
pi_ref
()
const
{
return
m_pi; }
76
77
/**
78
* @brief Constant time comparison of two field orderings.
79
*
80
* @param other The other field ordering.
81
* @return Mask of equality value
82
*/
83
CT::Mask<uint16_t>
ct_is_equal
(
const
Classic_McEliece_Field_Ordering
& other)
const
{
84
BOTAN_ARG_CHECK
(other.
pi_ref
().size() == pi_ref().size(),
"Field orderings must have the same size"
);
85
return
CT::is_equal(pi_ref().data(), other.
pi_ref
().data(), pi_ref().size());
86
}
83
CT::Mask<uint16_t>
ct_is_equal
(
const
Classic_McEliece_Field_Ordering
& other)
const
{
…
}
87
88
/**
89
* @brief Permute the field ordering with the given pivots.
90
*
91
* For example: If the pivot vector is 10101, the first, third and fifth element of the field ordering
92
* are permuted to positions 0, 1 and 2, respectively. The remaining elements are put at the end.
93
*
94
* The permutation is done for the elements from position m*t - mu,..., m*t + mu (excl.).
95
* This function implements Classic McEliece ISO Sec. 7.2.3 Steps 4-5.
96
*
97
* @param params The McEliece parameters.
98
* @param pivots The pivot vector.
99
*/
100
void
permute_with_pivots(
const
Classic_McEliece_Parameters
& params,
const
CmceColumnSelection
& pivots);
101
102
void
_const_time_poison
()
const
{ CT::poison(m_pi); }
103
104
void
_const_time_unpoison
()
const
{ CT::unpoison(m_pi); }
105
106
private
:
107
Classic_McEliece_Field_Ordering
(
CmcePermutation
pi,
CmceGfMod
poly_f) : m_pi(std::move(pi)), m_poly_f(poly_f) {}
108
109
private
:
110
CmcePermutation m_pi;
111
CmceGfMod m_poly_f;
112
};
25
class
BOTAN_TEST_API
Classic_McEliece_Field_Ordering
{
…
};
113
114
}
// namespace Botan
115
116
#endif
BOTAN_TEST_API
#define BOTAN_TEST_API
Definition
api.h:39
BOTAN_ARG_CHECK
#define BOTAN_ARG_CHECK(expr, msg)
Definition
assert.h:29
Botan::CT::Mask
Definition
ct_utils.h:379
Botan::Classic_McEliece_Field_Ordering
Represents a field ordering for the Classic McEliece cryptosystem.
Definition
cmce_field_ordering.h:25
Botan::Classic_McEliece_Field_Ordering::ct_is_equal
CT::Mask< uint16_t > ct_is_equal(const Classic_McEliece_Field_Ordering &other) const
Constant time comparison of two field orderings.
Definition
cmce_field_ordering.h:83
Botan::Classic_McEliece_Field_Ordering::pi_ref
const CmcePermutation & pi_ref() const
The pi values representing the field ordering.
Definition
cmce_field_ordering.h:75
Botan::Classic_McEliece_Field_Ordering::pi_ref
CmcePermutation & pi_ref()
The pi values representing the field ordering.
Definition
cmce_field_ordering.h:68
Botan::Classic_McEliece_Field_Ordering::_const_time_poison
void _const_time_poison() const
Definition
cmce_field_ordering.h:102
Botan::Classic_McEliece_Field_Ordering::_const_time_unpoison
void _const_time_unpoison() const
Definition
cmce_field_ordering.h:104
Botan::Classic_McEliece_Parameters
Definition
cmce_parameters.h:29
Botan::StrongSpan
Definition
strong_type.h:638
Botan::Strong< secure_vector< uint16_t >, struct CmcePermutation_ >
Botan::bitvector_base
Definition
bitvector.h:231
Botan
Definition
alg_id.cpp:13
Generated by
1.12.0