Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
FAlbertDev committed Feb 5, 2024
1 parent f5cae78 commit 1089ca3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/lib/pubkey/classic_mceliece/cmce_poly.cpp
Expand Up @@ -38,7 +38,7 @@ std::vector<GF_Elem> load_le_gf_vec(std::span<const uint8_t> bytes) {
} // namespace

Classic_McEliece_GF Classic_McEliece_Polynomial::operator()(Classic_McEliece_GF a) const {
BOTAN_ASSERT(a.modulus() == coef_at(0).modulus(), "Unmatching Galois fields");
BOTAN_ASSERT(a.modulus() == coef_at(0).modulus(), "Galois fields match");

Classic_McEliece_GF r(GF_Elem(0), a.modulus());
for(auto it = m_coef.rbegin(); it != m_coef.rend(); ++it) {
Expand Down Expand Up @@ -67,7 +67,7 @@ Classic_McEliece_Polynomial Classic_McEliece_Polynomial_Ring::multiply(const Cla

prod.erase(prod.begin() + m_t, prod.end());

return Classic_McEliece_Polynomial(prod);
return Classic_McEliece_Polynomial(std::move(prod));
}

Classic_McEliece_Polynomial Classic_McEliece_Polynomial_Ring::create_element_from_bytes(
Expand Down Expand Up @@ -100,7 +100,7 @@ std::optional<Classic_McEliece_Minimal_Polynomial> Classic_McEliece_Polynomial_R
mat.push_back(create_element_from_coef(concat_as<std::vector<GF_Elem>>(
std::vector<GF_Elem>{GF_Elem(1)}, std::vector<GF_Elem>(degree() - 1, GF_Elem(0)))));

mat.emplace_back(polynomial);
mat.push_back(polynomial);

for(size_t j = 2; j <= degree(); ++j) {
mat.push_back(multiply(mat.at(j - 1), polynomial));
Expand Down Expand Up @@ -129,7 +129,7 @@ std::optional<Classic_McEliece_Minimal_Polynomial> Classic_McEliece_Polynomial_R

for(size_t k = 0; k < degree(); ++k) {
if(k != j) {
auto t = mat.at(j).coef_at(k);
const auto t = mat.at(j).coef_at(k);

for(size_t c = j; c < degree() + 1; ++c) {
mat.at(c).coef_at(k) += mat.at(c).coef_at(j) * t;
Expand All @@ -149,11 +149,11 @@ secure_vector<uint8_t> Classic_McEliece_Minimal_Polynomial::serialize() const {
BOTAN_ASSERT_NOMSG(!coef().empty());
auto& all_coeffs = coef();
// Store all except coef for monomial x^t since polynomial is monic (ISO Spec Section 9.2.9)
auto coeffs_to_store = std::span(all_coeffs).subspan(0, all_coeffs.size() - 1);
auto coeffs_to_store = std::span(all_coeffs).first(all_coeffs.size() - 1);
secure_vector<uint8_t> bytes(sizeof(uint16_t) * coeffs_to_store.size());
BufferStuffer bytes_stuf(bytes);
for(auto& coef : coeffs_to_store) {
store_le(coef.elem().get(), bytes_stuf.next(sizeof(GF_Elem)).data());
store_le(bytes_stuf.next<sizeof(GF_Elem)>(), coef.elem().get());
}
BOTAN_ASSERT_NOMSG(bytes_stuf.full());
return bytes;
Expand Down
6 changes: 2 additions & 4 deletions src/lib/pubkey/classic_mceliece/cmce_poly.h
Expand Up @@ -90,14 +90,12 @@ class BOTAN_TEST_API Classic_McEliece_Minimal_Polynomial : public Classic_McElie
static Classic_McEliece_Minimal_Polynomial from_bytes(std::span<const uint8_t> bytes, GF_Mod poly_f);
};

// Stores all auxiliary information and logic of FF_(q^t) via FF_q[y]/F(y)
/**
* @brief Represents the polynomial ring GF(q)[y]/F(y) where F(y) is the modulus polynomial in
* GF(q)[y] of degree t.
*
* This class contains a modulus polynomial F(y) and the GF(q) modulus f(z). It is used
* to create and operate with Classic_McEliece_Polynomials.
*
*/
class BOTAN_TEST_API Classic_McEliece_Polynomial_Ring {
public:
Expand All @@ -122,8 +120,8 @@ class BOTAN_TEST_API Classic_McEliece_Polynomial_Ring {
* @param poly_f The modulus f(z) of GF(q).
* @param t The polynomial degree of the ring (and of F(y)).
*/
Classic_McEliece_Polynomial_Ring(const std::vector<Big_F_Coefficient>& poly_big_f_coef, GF_Mod poly_f, size_t t) :
m_position_map(poly_big_f_coef), m_t(t), m_poly_f(poly_f) {}
Classic_McEliece_Polynomial_Ring(std::vector<Big_F_Coefficient> poly_big_f_coef, GF_Mod poly_f, size_t t) :
m_position_map(std::move(poly_big_f_coef)), m_t(t), m_poly_f(poly_f) {}

GF_Mod poly_f() const { return m_poly_f; }

Expand Down
1 change: 0 additions & 1 deletion src/lib/pubkey/classic_mceliece/info.txt
Expand Up @@ -7,7 +7,6 @@ name -> "Classic McEliece"
</module_info>

<requires>
xof
shake
shake_xof
</requires>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/bit_ops.h
Expand Up @@ -212,7 +212,7 @@ inline constexpr T majority(T a, T b, T c) {
* instruction, if available. This is the SWAR (SIMD within a register)
* algorithm. See: https://nimrod.blog/posts/algorithms-behind-popcount/#swar-algorithm
*
* Note: C++20 provides std::popcount(), but there's no gurantee that this
* Note: C++20 provides std::popcount(), but there's no guarantee that this
* is implemented in constant-time.
*
* @param x an unsigned integer
Expand Down

0 comments on commit 1089ca3

Please sign in to comment.