Skip to content

Commit

Permalink
StrongAdapter<> for bitvector
Browse files Browse the repository at this point in the history
  • Loading branch information
reneme committed Jan 23, 2024
1 parent 6b64f54 commit 2a3e60f
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 58 deletions.
3 changes: 2 additions & 1 deletion src/lib/pubkey/classic_mceliece/cmce_decaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ std::pair<CT::Mask<uint8_t>, secure_bitvector> Classic_McEliece_Decryptor::decod
BOTAN_ASSERT(big_c.size() == m_key->params().m() * m_key->params().t(), "Correct ciphertext input size");
big_c.resize(m_key->params().n());

auto syndrome = compute_goppa_syndrome(m_key->params(), m_key->g(), m_key->field_ordering(), big_c.as_locked());
auto syndrome =
compute_goppa_syndrome(m_key->params(), m_key->g(), m_key->field_ordering(), big_c.as<secure_bitvector>());
auto locator = berlekamp_massey(m_key->params(), syndrome);

std::vector<Classic_McEliece_GF> images;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pubkey/classic_mceliece/cmce_field_ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ void Classic_McEliece_Field_Ordering::permute_with_pivots(const Classic_McEliece
for(size_t p_idx = 1; p_idx <= Classic_McEliece_Parameters::mu(); ++p_idx) {
size_t p_counter = 0;
for(size_t col = 0; col < Classic_McEliece_Parameters::nu(); ++col) {
auto mask_is_pivot_set = CT::Mask<size_t>::expand(pivots.get().at(col).as<size_t>());
p_counter += CT::Mask<size_t>::expand(pivots.get().at(col).as<size_t>()).if_set_return(1);
auto mask_is_pivot_set = CT::Mask<size_t>::expand(pivots.at(col).as<size_t>());
p_counter += CT::Mask<size_t>::expand(pivots.at(col).as<size_t>()).if_set_return(1);
auto mask_is_current_pivot = CT::Mask<size_t>::is_equal(p_idx, p_counter);
(mask_is_pivot_set & mask_is_current_pivot)
.conditional_swap(m_pi.get().at(col_offset + col), m_pi.get().at(col_offset + p_idx - 1));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pubkey/classic_mceliece/cmce_keys_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::shared_ptr<Classic_McEliece_PublicKeyInternal> Classic_McEliece_PublicKeyIn
throw Decoding_Error("Cannot create public key from private key. Private key is invalid.");
}
auto& [pk_matrix, pivot] = pk_matrix_and_pivot.value();
if(!pivot.get().subvector(0, pivot.size() / 2).all() || !pivot.get().subvector(pivot.size() / 2).none()) {
if(!pivot.subvector(0, pivot.size() / 2).all() || !pivot.subvector(pivot.size() / 2).none()) {
// There should not be a pivot other than 0xff ff ff ff 00 00 00 00. Otherwise
// the gauss algorithm failed effectively.
throw Decoding_Error("Cannot create public key from private key. Private key is invalid.");
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pubkey/classic_mceliece/cmce_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ std::optional<Column_Selection> move_columns(std::vector<secure_bitvector>& mat,
for(auto pivot_idx : pivot_indices) {
for(size_t i = 0; i < Classic_McEliece_Parameters::nu(); ++i) {
auto mask_is_at_current_idx = Botan::CT::Mask<size_t>::is_equal(i, pivot_idx);
pivots.get().at(i) = mask_is_at_current_idx.select(1, pivots.get().at(i).as<size_t>());
pivots.at(i) = mask_is_at_current_idx.select(1, pivots.at(i).as<size_t>());
}
}

Expand Down Expand Up @@ -252,6 +252,6 @@ bitvector Classic_McEliece_Matrix::mul(const Classic_McEliece_Parameters& params
}

BOTAN_ASSERT_NOMSG(pk_slicer.empty());
return s.as_unlocked();
return s.as<bitvector>();
}
} // namespace Botan
Loading

0 comments on commit 2a3e60f

Please sign in to comment.