9#include <botan/internal/cmce_keys_internal.h> 
   23std::optional<Classic_McEliece_KeyPair_Internal> try_generate_keypair(std::span<uint8_t> out_next_seed,
 
   29   auto big_e_xof = params.prg(seed);
 
   32   auto ordering_bits = big_e_xof->output<
CmceOrderingBits>((params.sigma2() * params.q()) / 8);
 
   33   auto irreducible_bits = big_e_xof->output<
CmceIrreducibleBits>((params.sigma1() * params.t()) / 8);
 
   34   big_e_xof->output(out_next_seed);
 
   43   auto g = params.poly_ring().compute_minimal_polynomial(irreducible_bits);
 
   49   auto pk_matrix_and_pivots =
 
   51   if(!pk_matrix_and_pivots) {
 
   54   auto& [pk_matrix, pivots] = pk_matrix_and_pivots.value();
 
   58      .private_key = std::make_shared<Classic_McEliece_PrivateKeyInternal>(
 
   59         params, std::move(seed), pivots, std::move(g.value()), std::move(field_ordering.value()), std::move(s)),
 
   60      .public_key = std::make_shared<Classic_McEliece_PublicKeyInternal>(params, std::move(pk_matrix))};
 
   83   auto control_bits = m_field_ordering.alphas_control_bits();
 
   93                   .ct_is_equal(m_field_ordering)
 
   95                "Control Bit Computation Check");
 
   97   return concat(m_delta.get(), m_c.get().to_bytes(), m_g.serialize(), control_bits.to_bytes(), m_s);
 
 
  101   auto prg = m_params.prg(m_delta);
 
  104   const auto ordering_bits = prg->output<
CmceOrderingBits>((m_params.sigma2() * m_params.q()) / 8);
 
  105   const auto irreducible_bits = prg->output<
CmceIrreducibleBits>((m_params.sigma1() * m_params.t()) / 8);
 
  113   if(
auto g = m_params.poly_ring().compute_minimal_polynomial(irreducible_bits)) {
 
  114      for(
size_t i = 0; i < 
g->degree() - 1; ++i) {
 
  123      field_ord_from_seed->permute_with_pivots(m_params, 
c());
 
  129   return ret.as_bool();
 
 
  135   if(!pk_matrix_and_pivot.has_value()) {
 
  136      throw Decoding_Error(
"Cannot create public key from private key. Private key is invalid.");
 
  138   auto& [pk_matrix, pivot] = pk_matrix_and_pivot.value();
 
  143      throw Decoding_Error(
"Cannot create public key from private key. Private key is invalid.");
 
  146   return std::make_shared<Classic_McEliece_PublicKeyInternal>(sk.
params(), std::move(pk_matrix));
 
 
  157      if(
auto keypair = try_generate_keypair(next_seed, params, std::move(current_seed))) {
 
  158         return keypair.value();
 
  160      current_seed = next_seed;
 
 
#define BOTAN_ASSERT_NOMSG(expr)
 
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
 
#define BOTAN_ASSERT(expr, assertion_made)
 
auto copy(const size_t count)
 
std::span< const uint8_t > take(const size_t count)
 
static constexpr Mask< T > expand(T v)
 
static constexpr Mask< T > is_equal(T x, T y)
 
static constexpr Mask< T > cleared()
 
static std::optional< Classic_McEliece_Field_Ordering > create_field_ordering(const Classic_McEliece_Parameters ¶ms, StrongSpan< const CmceOrderingBits > random_bits)
Creates a field ordering from a random bit sequence. Corresponds to the algorithm described in Classi...
 
static Classic_McEliece_Field_Ordering create_from_control_bits(const Classic_McEliece_Parameters ¶ms, const secure_bitvector &control_bits)
Create the field ordering from the control bits of a benes network.
 
static std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > create_matrix(const Classic_McEliece_Parameters ¶ms, const Classic_McEliece_Field_Ordering &field_ordering, const Classic_McEliece_Minimal_Polynomial &g)
Create the matrix H for a Classic McEliece instance given its parameters, field ordering and minimal ...
 
static std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > create_matrix_and_apply_pivots(const Classic_McEliece_Parameters ¶ms, Classic_McEliece_Field_Ordering &field_ordering, const Classic_McEliece_Minimal_Polynomial &g)
Create the matrix H for a Classic McEliece instance given its parameters, field ordering and minimal ...
 
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.
 
static constexpr size_t seed_len()
The byte length of the seed delta. See ISO 9.2.12.
 
Representation of a Classic McEliece private key.
 
const CmceRejectionSeed & s() const
The seed s for implicit rejection on decryption failure.
 
const Classic_McEliece_Field_Ordering & field_ordering() const
The field ordering alpha.
 
bool check_key() const
Checks the private key for consistency with the first component delta, i.e., recomputes s as a hash o...
 
secure_vector< uint8_t > serialize() const
Serializes the Classic McEliece private key as defined in Classic McEliece ISO Section 9....
 
const CmceKeyGenSeed & delta() const
The seed delta that was used to create the private key.
 
const Classic_McEliece_Parameters & params() const
The Classic McEliece parameters.
 
static Classic_McEliece_PrivateKeyInternal from_bytes(const Classic_McEliece_Parameters ¶ms, std::span< const uint8_t > sk_bytes)
Parses a Classic McEliece private key from a byte sequence.
 
Classic_McEliece_PrivateKeyInternal(const Classic_McEliece_Parameters ¶ms, CmceKeyGenSeed delta, CmceColumnSelection c, Classic_McEliece_Minimal_Polynomial g, Classic_McEliece_Field_Ordering alpha, CmceRejectionSeed s)
Construct a Classic McEliece private key.
 
const CmceColumnSelection & c() const
The column selection pivot vector c as defined in Classic McEliece ISO Section 9.2....
 
const Classic_McEliece_Minimal_Polynomial & g() const
The minimal polynomial g.
 
static std::shared_ptr< Classic_McEliece_PublicKeyInternal > create_from_private_key(const Classic_McEliece_PrivateKeyInternal &sk)
Create a Classic McEliece public key from a private key.
 
static GF_Mask is_equal(Classic_McEliece_GF a, Classic_McEliece_GF b)
 
decltype(auto) begin() noexcept(noexcept(this->m_span.begin()))
 
decltype(auto) end() noexcept(noexcept(this->m_span.end()))
 
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
 
decltype(auto) driveby_unpoison(T &&v)
 
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
 
Strong< secure_vector< uint8_t >, struct CmceOrderingBits_ > CmceOrderingBits
 
bitvector_base< secure_allocator > secure_bitvector
 
Strong< secure_vector< uint8_t >, struct CmceIrreducibleBits_ > CmceIrreducibleBits
 
bitvector_base< std::allocator > bitvector
 
Strong< secure_bitvector, struct CmceColumnSelection_ > CmceColumnSelection
Represents c of private key.
 
constexpr auto concat(Rs &&... ranges)
 
Strong< secure_vector< uint8_t >, struct CmceKeyGenSeed_ > CmceKeyGenSeed
Represents a delta (can be altered; final value stored in private key)
 
std::vector< T, secure_allocator< T > > secure_vector
 
Strong< secure_vector< uint8_t >, struct CmceRejectionSeed_ > CmceRejectionSeed
Represents s of private key.
 
Representation of a Classic McEliece key pair.
 
static Classic_McEliece_KeyPair_Internal generate(const Classic_McEliece_Parameters ¶ms, StrongSpan< const CmceInitialSeed > seed)
Generate a Classic McEliece key pair using the algorithm described in Classic McEliece ISO Section 8....