Botan 3.14.1
Crypto and TLS for C&
Botan::Classic_McEliece_Minimal_Polynomial Class Referencefinal

Representation of a minimal polynomial in GF(q)[y]. More...

#include <cmce_poly.h>

Inheritance diagram for Botan::Classic_McEliece_Minimal_Polynomial:
Botan::Classic_McEliece_Polynomial

Public Member Functions

void _const_time_poison () const
void _const_time_unpoison () const
 Classic_McEliece_Minimal_Polynomial (std::vector< Classic_McEliece_GF > coef)
const std::vector< Classic_McEliece_GF > & coef () const
 Get the entire coefficients vector of the polynomial.
Classic_McEliece_GF & coef_at (size_t i)
 Get the coefficient of the i-th monomial as a reference (from low to high degree).
const Classic_McEliece_GF & coef_at (size_t i) const
 Get the coefficient of the i-th monomial (from low to high degree).
size_t degree () const
 Get the degree of the polynomial.
Classic_McEliece_GF operator() (Classic_McEliece_GF a) const
 Evaluate the polynomial P(x) at a given point a, i.e., compute P(a).
secure_vector< uint8_t > serialize () const
 Serialize the polynomial to bytes according to ISO Section 9.2.9.

Static Public Member Functions

static Classic_McEliece_Minimal_Polynomial from_bytes (std::span< const uint8_t > bytes, CmceGfMod poly_f)
 Create a polynomial from bytes according to ISO Section 9.2.9.

Detailed Description

Representation of a minimal polynomial in GF(q)[y].

It represents the monic irreducible degree-t polynomial of the goppa code.

Definition at line 80 of file cmce_poly.h.

Constructor & Destructor Documentation

◆ Classic_McEliece_Minimal_Polynomial()

Botan::Classic_McEliece_Minimal_Polynomial::Classic_McEliece_Minimal_Polynomial ( std::vector< Classic_McEliece_GF > coef)
inlineexplicit

Definition at line 82 of file cmce_poly.h.

82 :
const std::vector< Classic_McEliece_GF > & coef() const
Get the entire coefficients vector of the polynomial.
Definition cmce_poly.h:58
Classic_McEliece_Polynomial(std::vector< Classic_McEliece_GF > coef)
Construct a polynomial given its coefficients.
Definition cmce_poly.h:38

References Botan::Classic_McEliece_Polynomial::Classic_McEliece_Polynomial(), and Botan::Classic_McEliece_Polynomial::coef().

Referenced by from_bytes().

Member Function Documentation

◆ _const_time_poison()

void Botan::Classic_McEliece_Polynomial::_const_time_poison ( ) const
inlineinherited

Definition at line 67 of file cmce_poly.h.

67{ CT::poison(m_coef); }
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:56

References Botan::CT::poison().

◆ _const_time_unpoison()

void Botan::Classic_McEliece_Polynomial::_const_time_unpoison ( ) const
inlineinherited

Definition at line 69 of file cmce_poly.h.

69{ CT::unpoison(m_coef); }
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67

References Botan::CT::unpoison().

◆ coef()

const std::vector< Classic_McEliece_GF > & Botan::Classic_McEliece_Polynomial::coef ( ) const
inlineinherited

Get the entire coefficients vector of the polynomial.

Definition at line 58 of file cmce_poly.h.

58{ return m_coef; }

Referenced by Botan::Classic_McEliece_Minimal_Polynomial::Classic_McEliece_Minimal_Polynomial(), Classic_McEliece_Polynomial(), and Botan::Classic_McEliece_Minimal_Polynomial::serialize().

◆ coef_at() [1/2]

Classic_McEliece_GF & Botan::Classic_McEliece_Polynomial::coef_at ( size_t i)
inlineinherited

Get the coefficient of the i-th monomial as a reference (from low to high degree).

Definition at line 48 of file cmce_poly.h.

48{ return m_coef.at(i); }

Referenced by Botan::Classic_McEliece_Polynomial_Ring::multiply(), and operator()().

◆ coef_at() [2/2]

const Classic_McEliece_GF & Botan::Classic_McEliece_Polynomial::coef_at ( size_t i) const
inlineinherited

Get the coefficient of the i-th monomial (from low to high degree).

Definition at line 53 of file cmce_poly.h.

53{ return m_coef.at(i); }

◆ degree()

size_t Botan::Classic_McEliece_Polynomial::degree ( ) const
inlineinherited

Get the degree of the polynomial.

Note that the degree is given by the size of the coefficient vector, even if the leading coefficient is zero.

Definition at line 65 of file cmce_poly.h.

65{ return m_coef.size() + 1; }

◆ from_bytes()

Classic_McEliece_Minimal_Polynomial Botan::Classic_McEliece_Minimal_Polynomial::from_bytes ( std::span< const uint8_t > bytes,
CmceGfMod poly_f )
static

Create a polynomial from bytes according to ISO Section 9.2.9.

Definition at line 147 of file cmce_poly.cpp.

148 {
149 BOTAN_ASSERT_NOMSG(bytes.size() % 2 == 0);
150 const auto coef_vec = load_le<std::vector<CmceGfElem>>(bytes);
151
152 // Each coefficient is an element of GF(2^m); the unused high bits must be clear
153 const auto q_minus_1 = static_cast<uint16_t>((uint16_t(1) << Classic_McEliece_GF::log_q_from_mod(poly_f)) - 1);
154 auto in_range = CT::Mask<uint16_t>::set();
155 for(const auto& coeff : coef_vec) {
156 in_range &= CT::Mask<uint16_t>::is_lte(coeff.get(), q_minus_1);
157 }
158 if(!in_range.as_bool()) {
159 throw Decoding_Error("Classic McEliece polynomial coefficient is out of range");
160 }
161
162 std::vector<Classic_McEliece_GF> coeff_vec_gf;
163 std::transform(coef_vec.begin(), coef_vec.end(), std::back_inserter(coeff_vec_gf), [poly_f](auto& coeff) {
164 return Classic_McEliece_GF(coeff, poly_f);
165 });
166
167 coeff_vec_gf.emplace_back(CmceGfElem(1), poly_f); // x^t as polynomial is monic
168
169 return Classic_McEliece_Minimal_Polynomial(coeff_vec_gf);
170}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
static constexpr Mask< T > is_lte(T x, T y)
Definition ct_utils.h:468
static constexpr Mask< T > set()
Definition ct_utils.h:387
static size_t log_q_from_mod(CmceGfMod modulus)
Get m.
Definition cmce_gf.h:53
Classic_McEliece_Minimal_Polynomial(std::vector< Classic_McEliece_GF > coef)
Definition cmce_poly.h:82
Strong< uint16_t, struct CmceGfElem_ > CmceGfElem
Represents a GF(q) element.
Definition cmce_types.h:19
constexpr auto load_le(ParamTs &&... params)
Definition loadstor.h:495

References BOTAN_ASSERT_NOMSG, Classic_McEliece_Minimal_Polynomial(), Botan::CT::Mask< T >::is_lte(), Botan::load_le(), Botan::Classic_McEliece_GF::log_q_from_mod(), and Botan::CT::Mask< T >::set().

Referenced by Botan::Classic_McEliece_PrivateKeyInternal::from_bytes().

◆ operator()()

Classic_McEliece_GF Botan::Classic_McEliece_Polynomial::operator() ( Classic_McEliece_GF a) const
inherited

Evaluate the polynomial P(x) at a given point a, i.e., compute P(a).

Definition at line 22 of file cmce_poly.cpp.

22 {
23 BOTAN_DEBUG_ASSERT(a.modulus() == coef_at(0).modulus());
24
25 Classic_McEliece_GF r(CmceGfElem(0), a.modulus());
26 // TODO(Botan4) use std::ranges::reverse_view here once available (need newer Clang)
27 // NOLINTNEXTLINE(modernize-loop-convert)
28 for(auto it = m_coef.rbegin(); it != m_coef.rend(); ++it) {
29 r *= a;
30 r += *it;
31 }
32
33 return r;
34}
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:136
Classic_McEliece_GF & coef_at(size_t i)
Get the coefficient of the i-th monomial as a reference (from low to high degree).
Definition cmce_poly.h:48

References BOTAN_DEBUG_ASSERT, coef_at(), and Botan::Classic_McEliece_GF::modulus().

◆ serialize()

secure_vector< uint8_t > Botan::Classic_McEliece_Minimal_Polynomial::serialize ( ) const

Serialize the polynomial to bytes according to ISO Section 9.2.9.

Definition at line 133 of file cmce_poly.cpp.

133 {
134 BOTAN_ASSERT_NOMSG(!coef().empty());
135 const auto& all_coeffs = coef();
136 // Store all except coef for monomial x^t since polynomial is monic (ISO Spec Section 9.2.9)
137 const auto coeffs_to_store = std::span(all_coeffs).first(all_coeffs.size() - 1);
138 secure_vector<uint8_t> bytes(sizeof(uint16_t) * coeffs_to_store.size());
139 BufferStuffer bytes_stuf(bytes);
140 for(const auto& coef : coeffs_to_store) {
141 store_le(bytes_stuf.next<sizeof(CmceGfElem)>(), coef.elem().get());
142 }
143 BOTAN_ASSERT_NOMSG(bytes_stuf.full());
144 return bytes;
145}
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:736
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128

References BOTAN_ASSERT_NOMSG, Botan::Classic_McEliece_Polynomial::coef(), Botan::BufferStuffer::full(), Botan::BufferStuffer::next(), and Botan::store_le().


The documentation for this class was generated from the following files: