12#include <botan/internal/cmce_poly.h>
13#include <botan/internal/ct_utils.h>
14#include <botan/internal/stl_util.h>
24 for(
auto it = m_coef.rbegin(); it != m_coef.rend(); ++it) {
34 std::vector<Classic_McEliece_GF> prod(m_t * 2 - 1, {
CmceGfElem(0), m_poly_f});
36 for(
size_t i = 0; i < m_t; ++i) {
37 for(
size_t j = 0; j < m_t; ++j) {
42 for(
size_t i = (m_t - 1) * 2; i >= m_t; --i) {
43 for(
const auto& [idx, coef] : m_position_map) {
44 prod.at(i - m_t + idx) += coef * prod.at(i);
48 prod.erase(prod.begin() + m_t, prod.end());
54 std::span<const uint8_t> bytes)
const {
56 return create_element_from_coef(
load_le<std::vector<CmceGfElem>>(bytes));
59Classic_McEliece_Polynomial Classic_McEliece_Polynomial_Ring::create_element_from_coef(
60 const std::vector<CmceGfElem>& coeff_vec)
const {
61 std::vector<Classic_McEliece_GF> coeff_vec_gf;
63 std::transform(coeff_vec.begin(), coeff_vec.end(), std::back_inserter(coeff_vec_gf), [&](
auto& coeff) {
64 return Classic_McEliece_GF(coeff & coeff_mask, m_poly_f);
66 return Classic_McEliece_Polynomial(coeff_vec_gf);
76 auto polynomial = create_element_from_bytes(seed);
77 std::vector<Classic_McEliece_Polynomial> mat;
79 mat.push_back(create_element_from_coef(
concat<std::vector<CmceGfElem>>(
82 mat.push_back(polynomial);
84 for(
size_t j = 2; j <=
degree(); ++j) {
85 mat.push_back(
multiply(mat.at(j - 1), polynomial));
89 for(
size_t j = 0; j <
degree(); ++j) {
90 for(
size_t k = j + 1; k <
degree(); ++k) {
93 for(
size_t c = j; c <
degree() + 1; ++c) {
94 mat.at(c).coef_at(j) += cond.if_set_return(mat.at(c).coef_at(k));
98 const bool is_zero_at_diagonal = mat.at(j).coef_at(j).is_zero();
100 if(is_zero_at_diagonal) {
105 auto inv = mat.at(j).coef_at(j).inv();
107 for(
size_t c = j; c <
degree() + 1; ++c) {
108 mat.at(c).coef_at(j) *= inv;
111 for(
size_t k = 0; k <
degree(); ++k) {
113 const auto t = mat.at(j).coef_at(k);
115 for(
size_t c = j; c <
degree() + 1; ++c) {
116 mat.at(c).coef_at(k) += mat.at(c).coef_at(j) * t;
122 auto minimal_poly_coeffs = mat.at(
degree()).coef();
131 const auto& all_coeffs =
coef();
133 auto coeffs_to_store = std::span(all_coeffs).first(all_coeffs.size() - 1);
136 for(
const auto&
coef : coeffs_to_store) {
147 std::vector<Classic_McEliece_GF> coeff_vec_gf;
148 std::transform(coef_vec.begin(), coef_vec.end(), std::back_inserter(coeff_vec_gf), [poly_f](
auto& coeff) {
149 return Classic_McEliece_GF(coeff, poly_f);
152 coeff_vec_gf.emplace_back(
CmceGfElem(1), poly_f);
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_DEBUG_ASSERT(expr)
#define BOTAN_ARG_CHECK(expr, msg)
Helper class to ease in-place marshalling of concatenated fixed-length values.
constexpr std::span< uint8_t > next(size_t bytes)
constexpr bool full() const
Represents an element of the finite field GF(q) for q = 2^m.
static size_t log_q_from_mod(CmceGfMod modulus)
Get m.
CmceGfMod modulus() const
Get the modulus f(z) of GF(q) as a GF_Mod.
Representation of a minimal polynomial in GF(q)[y].
secure_vector< uint8_t > serialize() const
Serialize the polynomial to bytes according to ISO Section 9.2.9.
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.
Classic_McEliece_Minimal_Polynomial(std::vector< Classic_McEliece_GF > coef)
Classic_McEliece_Polynomial multiply(const Classic_McEliece_Polynomial &a, const Classic_McEliece_Polynomial &b) const
size_t degree() const
The degree of polynomials in this ring (and of F(y)).
std::optional< Classic_McEliece_Minimal_Polynomial > compute_minimal_polynomial(StrongSpan< const CmceIrreducibleBits > seed) const
Compute the minimal polynomial g of polynomial created from a seed.
Representation of a Classic McEliece polynomial.
const std::vector< Classic_McEliece_GF > & coef() const
Get the entire coefficients vector 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).
Classic_McEliece_GF & coef_at(size_t i)
Get the coefficient of the i-th monomial as a reference (from low to high degree).
static GF_Mask is_zero(Classic_McEliece_GF v)
constexpr void unpoison(const T *p, size_t n)
Strong< uint16_t, struct CmceGfMod_ > CmceGfMod
Represents a GF(q) modulus.
Strong< uint16_t, struct CmceGfElem_ > CmceGfElem
Represents a GF(q) element.
constexpr auto store_le(ParamTs &&... params)
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
constexpr auto concat(Rs &&... ranges)
constexpr auto load_le(ParamTs &&... params)
std::vector< T, secure_allocator< T > > secure_vector
Represents a non-zero coefficient of the modulus F(y) (which is in GF(q)[y]).
Classic_McEliece_GF coeff