12#include <botan/internal/cmce_poly.h>
13#include <botan/internal/ct_utils.h>
14#include <botan/internal/stl_util.h>
22 for(
auto it = m_coef.rbegin(); it != m_coef.rend(); ++it) {
32 std::vector<Classic_McEliece_GF> prod(m_t * 2 - 1, {
CmceGfElem(0), m_poly_f});
34 for(
size_t i = 0; i < m_t; ++i) {
35 for(
size_t j = 0; j < m_t; ++j) {
36 prod.at(i + j) += (a.
coef_at(i) *
b.coef_at(j));
40 for(
size_t i = (m_t - 1) * 2; i >= m_t; --i) {
41 for(
auto& [idx, coef] : m_position_map) {
42 prod.at(i - m_t + idx) += coef * prod.at(i);
46 prod.erase(prod.begin() + m_t, prod.end());
52 std::span<const uint8_t> bytes)
const {
54 return create_element_from_coef(
load_le<std::vector<CmceGfElem>>(bytes));
57Classic_McEliece_Polynomial Classic_McEliece_Polynomial_Ring::create_element_from_coef(
58 const std::vector<CmceGfElem>& coeff_vec)
const {
59 std::vector<Classic_McEliece_GF> coeff_vec_gf;
61 std::transform(coeff_vec.begin(), coeff_vec.end(), std::back_inserter(coeff_vec_gf), [&](
auto& coeff) {
62 return Classic_McEliece_GF(coeff & coeff_mask, m_poly_f);
64 return Classic_McEliece_Polynomial(coeff_vec_gf);
74 auto polynomial = create_element_from_bytes(seed);
75 std::vector<Classic_McEliece_Polynomial> mat;
77 mat.push_back(create_element_from_coef(
concat<std::vector<CmceGfElem>>(
80 mat.push_back(polynomial);
82 for(
size_t j = 2; j <=
degree(); ++j) {
83 mat.push_back(
multiply(mat.at(j - 1), polynomial));
87 for(
size_t j = 0; j <
degree(); ++j) {
88 for(
size_t k = j + 1; k <
degree(); ++k) {
91 for(
size_t c = j; c <
degree() + 1; ++c) {
92 mat.at(c).coef_at(j) += cond.if_set_return(mat.at(c).coef_at(k));
96 const bool is_zero_at_diagonal = mat.at(j).coef_at(j).is_zero();
98 if(is_zero_at_diagonal) {
103 auto inv = mat.at(j).coef_at(j).inv();
105 for(
size_t c = j; c <
degree() + 1; ++c) {
106 mat.at(c).coef_at(j) *= inv;
109 for(
size_t k = 0; k <
degree(); ++k) {
111 const auto t = mat.at(j).coef_at(k);
113 for(
size_t c = j; c <
degree() + 1; ++c) {
114 mat.at(c).coef_at(k) += mat.at(c).coef_at(j) * t;
120 auto minimal_poly_coeffs = mat.at(
degree()).coef();
129 auto& all_coeffs =
coef();
131 auto coeffs_to_store = std::span(all_coeffs).first(all_coeffs.size() - 1);
134 for(
auto&
coef : coeffs_to_store) {
145 std::vector<Classic_McEliece_GF> coeff_vec_gf;
146 std::transform(coef_vec.begin(), coef_vec.end(), std::back_inserter(coeff_vec_gf), [poly_f](
auto& coeff) {
147 return Classic_McEliece_GF(coeff, poly_f);
150 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 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