Botan 3.7.1
Crypto and TLS for C&
Botan::Classic_McEliece_Matrix Class Reference

Representation of the binary Classic McEliece matrix H, with H = (I_mt | T). More...

#include <cmce_matrix.h>

Public Member Functions

constexpr void _const_time_unpoison () const
 
const std::vector< uint8_t > & bytes () const
 The bytes of the submatrix T, with H=(I_mt, T) as defined in Classic McEliece ISO Section 9.2.7.
 
 Classic_McEliece_Matrix (const Classic_McEliece_Parameters &params, std::vector< uint8_t > mat_bytes)
 Create a Classic_McEliece_Matrix from bytes.
 
CmceCodeWord mul (const Classic_McEliece_Parameters &params, const CmceErrorVector &e) const
 Multiply the Classic McEliece matrix H with a bitvector e.
 

Static Public Member Functions

static std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > create_matrix (const Classic_McEliece_Parameters &params, 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 polynomial.
 
static std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > create_matrix_and_apply_pivots (const Classic_McEliece_Parameters &params, 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 polynomial.
 

Detailed Description

Representation of the binary Classic McEliece matrix H, with H = (I_mt | T).

Only the bytes of the submatrix T are stored.

Definition at line 26 of file cmce_matrix.h.

Constructor & Destructor Documentation

◆ Classic_McEliece_Matrix()

Botan::Classic_McEliece_Matrix::Classic_McEliece_Matrix ( const Classic_McEliece_Parameters & params,
std::vector< uint8_t > mat_bytes )
inline

Create a Classic_McEliece_Matrix from bytes.

Parameters
mat_bytesThe bytes of the submatrix T as defined in Classic McEliece ISO Section 9.2.7.

Definition at line 84 of file cmce_matrix.h.

84 :
85 m_mat_bytes(std::move(mat_bytes)) {
86 BOTAN_ARG_CHECK(m_mat_bytes.size() == params.pk_size_bytes(), "Invalid byte size for matrix");
87 if(params.pk_no_cols() % 8 == 0) {
88 return;
89 }
90 // Check padding of mat_bytes rows
91 BOTAN_ASSERT_NOMSG(m_mat_bytes.size() == params.pk_no_rows() * params.pk_row_size_bytes());
92 for(size_t row = 0; row < params.pk_no_rows(); ++row) {
93 uint8_t padded_byte = m_mat_bytes[(row + 1) * params.pk_row_size_bytes() - 1];
94 CT::unpoison(padded_byte);
95 BOTAN_ARG_CHECK(padded_byte >> (params.pk_no_cols() % 8) == 0, "Valid padding of unused bytes");
96 }
97 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:64

References BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, Botan::Classic_McEliece_Parameters::pk_no_cols(), Botan::Classic_McEliece_Parameters::pk_no_rows(), Botan::Classic_McEliece_Parameters::pk_row_size_bytes(), and Botan::Classic_McEliece_Parameters::pk_size_bytes().

Referenced by create_matrix().

Member Function Documentation

◆ _const_time_unpoison()

void Botan::Classic_McEliece_Matrix::_const_time_unpoison ( ) const
inlineconstexpr

Definition at line 108 of file cmce_matrix.h.

108{ CT::unpoison(m_mat_bytes); }

◆ bytes()

const std::vector< uint8_t > & Botan::Classic_McEliece_Matrix::bytes ( ) const
inline

The bytes of the submatrix T, with H=(I_mt, T) as defined in Classic McEliece ISO Section 9.2.7.

Returns
The matrix bytes

Definition at line 77 of file cmce_matrix.h.

77{ return m_mat_bytes; }

◆ create_matrix()

std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > Botan::Classic_McEliece_Matrix::create_matrix ( const Classic_McEliece_Parameters & params,
const Classic_McEliece_Field_Ordering & field_ordering,
const Classic_McEliece_Minimal_Polynomial & g )
static

Create the matrix H for a Classic McEliece instance given its parameters, field ordering and minimal polynomial.

Output is a pair of the matrix and the pivot vector c that was used to create it in the semi-systematic form as described in Classic McEliece ISO Section 9.2.11.

The update of alpha values as per Classic McEliece ISO Section 7.2.3 Step 5 is not performed by this method because it is only used for public key loading where the values are already permuted and field_ordering cannot be altered.

Parameters
paramsClassic McEliece parameters
field_orderingField ordering
gMinimal polynomial
Returns
Pair(the matrix H, pivot vector c)

Definition at line 243 of file cmce_matrix.cpp.

246 {
247 auto mat = init_matrix_with_alphas(params, field_ordering, g);
248 auto pivots = apply_gauss(params, mat);
249
250 auto gauss_failed = !pivots.has_value();
251 CT::unpoison(gauss_failed);
252 if(gauss_failed) {
253 return std::nullopt;
254 }
255
256 auto pk_mat_bytes = extract_pk_bytes_from_matrix(params, mat);
257 return std::make_pair(Classic_McEliece_Matrix(params, std::move(pk_mat_bytes)), pivots.value());
258}
Classic_McEliece_Matrix(const Classic_McEliece_Parameters &params, std::vector< uint8_t > mat_bytes)
Create a Classic_McEliece_Matrix from bytes.
Definition cmce_matrix.h:84

References Classic_McEliece_Matrix(), and Botan::CT::unpoison().

Referenced by Botan::Classic_McEliece_PublicKeyInternal::create_from_private_key(), and create_matrix_and_apply_pivots().

◆ create_matrix_and_apply_pivots()

std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > Botan::Classic_McEliece_Matrix::create_matrix_and_apply_pivots ( const Classic_McEliece_Parameters & params,
Classic_McEliece_Field_Ordering & field_ordering,
const Classic_McEliece_Minimal_Polynomial & g )
static

Create the matrix H for a Classic McEliece instance given its parameters, field ordering and minimal polynomial.

Output is a pair of the matrix and the pivot vector c that was used to create it in the semi-systematic form as described in Classic McEliece ISO Section 9.2.11.

This method directly updates the field ordering values as described in Classic McEliece ISO Section 7.2.3 Step 5 (for f parameter sets).

Parameters
paramsClassic McEliece parameters
field_orderingField ordering (will be updated)
gMinimal polynomial
Returns
Pair(the matrix H, pivot vector c)

Definition at line 261 of file cmce_matrix.cpp.

263 {
264 auto pk_matrix_and_pivots = create_matrix(params, field_ordering, g);
265
266 bool matrix_creation_failed = !pk_matrix_and_pivots.has_value();
267 CT::unpoison(matrix_creation_failed);
268 if(matrix_creation_failed) {
269 return std::nullopt;
270 }
271
272 auto& [_, pivots] = pk_matrix_and_pivots.value();
273
274 if(params.is_f()) {
275 field_ordering.permute_with_pivots(params, pivots);
276 }
277
278 return pk_matrix_and_pivots;
279}
static std::optional< std::pair< Classic_McEliece_Matrix, CmceColumnSelection > > create_matrix(const Classic_McEliece_Parameters &params, 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 ...

References create_matrix(), Botan::Classic_McEliece_Parameters::is_f(), Botan::Classic_McEliece_Field_Ordering::permute_with_pivots(), and Botan::CT::unpoison().

◆ mul()

CmceCodeWord Botan::Classic_McEliece_Matrix::mul ( const Classic_McEliece_Parameters & params,
const CmceErrorVector & e ) const

Multiply the Classic McEliece matrix H with a bitvector e.

Parameters
paramsClassic McEliece parameters
eThe bitvector e
Returns
H*e

Definition at line 281 of file cmce_matrix.cpp.

281 {
282 auto s = e.subvector<CmceCodeWord>(0, params.pk_no_rows());
283 auto e_T = e.subvector(params.pk_no_rows());
284 auto pk_slicer = BufferSlicer(m_mat_bytes);
285
286 for(size_t i = 0; i < params.pk_no_rows(); ++i) {
287 auto pk_current_bytes = pk_slicer.take(params.pk_row_size_bytes());
288 auto row = secure_bitvector(pk_current_bytes, params.n() - params.pk_no_rows());
289 row &= e_T;
290 s[i] ^= row.has_odd_hamming_weight().as_bool();
291 }
292
293 BOTAN_ASSERT_NOMSG(pk_slicer.empty());
294 return s;
295}
Strong< secure_bitvector, struct CmceCodeWord_ > CmceCodeWord
Represents C of decapsulation.
Definition cmce_types.h:52
bitvector_base< secure_allocator > secure_bitvector
Definition bitvector.h:1297

References BOTAN_ASSERT_NOMSG, Botan::Classic_McEliece_Parameters::n(), Botan::Classic_McEliece_Parameters::pk_no_rows(), Botan::Classic_McEliece_Parameters::pk_row_size_bytes(), and Botan::detail::Strong_Adapter< T >::subvector().


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