Botan 3.7.1
Crypto and TLS for C&
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
17namespace 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 */
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(
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 */
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 }
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};
113
114} // namespace Botan
115
116#endif
#define BOTAN_TEST_API
Definition api.h:39
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
Represents a field ordering for the Classic McEliece cryptosystem.
CT::Mask< uint16_t > ct_is_equal(const Classic_McEliece_Field_Ordering &other) const
Constant time comparison of two field orderings.
const CmcePermutation & pi_ref() const
The pi values representing the field ordering.
CmcePermutation & pi_ref()
The pi values representing the field ordering.