aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-06-29 22:11:46 -0400
committerJack Lloyd <[email protected]>2019-06-29 22:11:46 -0400
commitcf09338f297ce9c26c14ddb5226d9e6e94b63a88 (patch)
tree7c4d0aa73ac3ffb7da94128d2342633403280c50
parent99e60d6367f8f085d3bd5503c5446727b138b00e (diff)
parenta3e2ed375ad6a94228febf9d38379e0ab7e8215c (diff)
Merge GH #2011 Fix some MSVC and LGTM warnings
-rw-r--r--src/cli/cli.cpp16
-rw-r--r--src/cli/cli.h4
-rw-r--r--src/cli/tls_client.cpp2
-rw-r--r--src/cli/tls_http_server.cpp2
-rw-r--r--src/cli/tls_proxy.cpp2
-rw-r--r--src/cli/tls_server.cpp2
-rw-r--r--src/lib/pubkey/mce/code_based_key_gen.cpp93
-rw-r--r--src/lib/pubkey/mce/gf2m_small_m.h5
-rw-r--r--src/lib/pubkey/mce/mce_internal.h6
-rw-r--r--src/lib/pubkey/mce/polyn_gf2m.cpp100
-rw-r--r--src/lib/pubkey/mce/polyn_gf2m.h4
11 files changed, 132 insertions, 104 deletions
diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp
index 25edd5df2..1fc5ed116 100644
--- a/src/cli/cli.cpp
+++ b/src/cli/cli.cpp
@@ -128,6 +128,22 @@ size_t Command::get_arg_sz(const std::string& opt_name) const
return m_args->get_arg_sz(opt_name);
}
+uint16_t Command::get_arg_u16(const std::string& opt_name) const
+ {
+ const size_t val = get_arg_sz(opt_name);
+ if(static_cast<uint16_t>(val) != val)
+ throw CLI_Usage_Error("Argument " + opt_name + " has value out of allowed range");
+ return static_cast<uint16_t>(val);
+ }
+
+uint32_t Command::get_arg_u32(const std::string& opt_name) const
+ {
+ const size_t val = get_arg_sz(opt_name);
+ if(static_cast<uint32_t>(val) != val)
+ throw CLI_Usage_Error("Argument " + opt_name + " has value out of allowed range");
+ return static_cast<uint32_t>(val);
+ }
+
std::vector<std::string> Command::get_arg_list(const std::string& what) const
{
return m_args->get_arg_list(what);
diff --git a/src/cli/cli.h b/src/cli/cli.h
index 838fb9eb3..2a7bef483 100644
--- a/src/cli/cli.h
+++ b/src/cli/cli.h
@@ -147,6 +147,10 @@ class Command
size_t get_arg_sz(const std::string& opt_name) const;
+ uint16_t get_arg_u16(const std::string& opt_name) const;
+
+ uint32_t get_arg_u32(const std::string& opt_name) const;
+
std::vector<std::string> get_arg_list(const std::string& what) const;
/*
diff --git a/src/cli/tls_client.cpp b/src/cli/tls_client.cpp
index 26e1f4b25..e241df1e8 100644
--- a/src/cli/tls_client.cpp
+++ b/src/cli/tls_client.cpp
@@ -91,7 +91,7 @@ class TLS_Client final : public Command, public Botan::TLS::Callbacks
const std::string sessions_db = get_arg("session-db");
const std::string host = get_arg("host");
- const uint16_t port = static_cast<uint16_t>(get_arg_sz("port"));
+ const uint16_t port = get_arg_u16("port");
const std::string transport = get_arg("type");
const std::string next_protos = get_arg("next-protocols");
std::string policy_file = get_arg("policy");
diff --git a/src/cli/tls_http_server.cpp b/src/cli/tls_http_server.cpp
index 0ff1632af..b4d117586 100644
--- a/src/cli/tls_http_server.cpp
+++ b/src/cli/tls_http_server.cpp
@@ -529,7 +529,7 @@ class TLS_HTTP_Server final : public Command
void go() override
{
- const size_t listen_port = get_arg_sz("port");
+ const uint16_t listen_port = get_arg_u16("port");
const std::string server_crt = get_arg("server_cert");
const std::string server_key = get_arg("server_key");
diff --git a/src/cli/tls_proxy.cpp b/src/cli/tls_proxy.cpp
index 596e4105c..9299a0e38 100644
--- a/src/cli/tls_proxy.cpp
+++ b/src/cli/tls_proxy.cpp
@@ -465,7 +465,7 @@ class TLS_Proxy final : public Command
void go() override
{
- const size_t listen_port = get_arg_sz("listen_port");
+ const uint16_t listen_port = get_arg_u16("listen_port");
const std::string target = get_arg("target_host");
const std::string target_port = get_arg("target_port");
diff --git a/src/cli/tls_server.cpp b/src/cli/tls_server.cpp
index c6832582b..77afd397d 100644
--- a/src/cli/tls_server.cpp
+++ b/src/cli/tls_server.cpp
@@ -62,7 +62,7 @@ class TLS_Server final : public Command, public Botan::TLS::Callbacks
{
const std::string server_crt = get_arg("cert");
const std::string server_key = get_arg("key");
- const int port = get_arg_sz("port");
+ const uint16_t port = get_arg_u16("port");
const size_t max_clients = get_arg_sz("max-clients");
const std::string transport = get_arg("type");
const std::string dump_traces_to = get_arg("dump-traces");
diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp
index dad06f0c0..8d662cb24 100644
--- a/src/lib/pubkey/mce/code_based_key_gen.cpp
+++ b/src/lib/pubkey/mce/code_based_key_gen.cpp
@@ -22,37 +22,43 @@ namespace {
class binary_matrix final
{
public:
- binary_matrix(uint32_t m_rown, uint32_t m_coln);
+ binary_matrix(size_t m_rown, size_t m_coln);
- void row_xor(uint32_t a, uint32_t b);
+ void row_xor(size_t a, size_t b);
secure_vector<int> row_reduced_echelon_form();
/**
* return the coefficient out of F_2
*/
- uint32_t coef(uint32_t i, uint32_t j)
+ uint32_t coef(size_t i, size_t j)
{
return (m_elem[(i) * m_rwdcnt + (j) / 32] >> (j % 32)) & 1;
}
- void set_coef_to_one(uint32_t i, uint32_t j)
+ void set_coef_to_one(size_t i, size_t j)
{
m_elem[(i) * m_rwdcnt + (j) / 32] |= (static_cast<uint32_t>(1) << ((j) % 32)) ;
}
- void toggle_coeff(uint32_t i, uint32_t j)
+ void toggle_coeff(size_t i, size_t j)
{
m_elem[(i) * m_rwdcnt + (j) / 32] ^= (static_cast<uint32_t>(1) << ((j) % 32)) ;
}
- //private:
- uint32_t m_rown; // number of rows.
- uint32_t m_coln; // number of columns.
- uint32_t m_rwdcnt; // number of words in a row
+ size_t rows() const { return m_rown; }
+
+ size_t columns() const { return m_coln; }
+
+ private:
+ size_t m_rown; // number of rows.
+ size_t m_coln; // number of columns.
+ size_t m_rwdcnt; // number of words in a row
+ public:
+ // TODO this should be private
std::vector<uint32_t> m_elem;
};
-binary_matrix::binary_matrix (uint32_t rown, uint32_t coln)
+binary_matrix::binary_matrix(size_t rown, size_t coln)
{
m_coln = coln;
m_rown = rown;
@@ -60,39 +66,41 @@ binary_matrix::binary_matrix (uint32_t rown, uint32_t coln)
m_elem = std::vector<uint32_t>(m_rown * m_rwdcnt);
}
-void binary_matrix::row_xor(uint32_t a, uint32_t b)
+void binary_matrix::row_xor(size_t a, size_t b)
{
- uint32_t i;
- for(i=0;i<m_rwdcnt;i++)
+ for(size_t i = 0; i != m_rwdcnt; i++)
{
- m_elem[a*m_rwdcnt+i]^=m_elem[b*m_rwdcnt+i];
+ m_elem[a*m_rwdcnt+i] ^= m_elem[b*m_rwdcnt+i];
}
}
//the matrix is reduced from LSB...(from right)
secure_vector<int> binary_matrix::row_reduced_echelon_form()
{
- uint32_t i, failcnt, findrow, max=m_coln - 1;
-
secure_vector<int> perm(m_coln);
- for(i=0;i<m_coln;i++)
+ for(size_t i = 0; i != m_coln; i++)
{
- perm[i]=i;//initialize permutation.
+ perm[i] = i;//initialize permutation.
}
- failcnt = 0;
- for(i=0;i<m_rown;i++,max--)
+ uint32_t failcnt = 0;
+
+ uint32_t max = m_coln - 1;
+ for(size_t i = 0; i != m_rown; i++, max--)
{
- findrow=0;
- for(uint32_t j=i;j<m_rown;j++)
+ uint32_t findrow = 0;
+ for(size_t j = i; j != m_rown; j++)
{
- if(coef(j,max))
+ if(coef(j, max))
{
- if (i!=j)//not needed as ith row is 0 and jth row is 1.
- row_xor(i,j);//xor to the row.(swap)?
+ if(i != j) //not needed as ith row is 0 and jth row is 1.
+ {
+ row_xor(i ,j);//xor to the row.(swap)?
+ }
+
findrow=1;
break;
- }//largest value found (end if)
+ } //largest value found (end if)
}
if(!findrow)//if no row with a 1 found then swap last column and the column with no 1 down.
@@ -110,7 +118,7 @@ secure_vector<int> binary_matrix::row_reduced_echelon_form()
else
{
perm[i+m_coln - m_rown] = max;
- for(uint32_t j=i+1;j<m_rown;j++)//fill the column downwards with 0's
+ for(size_t j=i+1;j<m_rown;j++)//fill the column downwards with 0's
{
if(coef(j,(max)))
{
@@ -132,7 +140,7 @@ secure_vector<int> binary_matrix::row_reduced_echelon_form()
void randomize_support(std::vector<gf2m>& L, RandomNumberGenerator& rng)
{
- for(uint32_t i = 0; i != L.size(); ++i)
+ for(size_t i = 0; i != L.size(); ++i)
{
gf2m rnd = random_gf2m(rng);
@@ -149,21 +157,20 @@ std::unique_ptr<binary_matrix> generate_R(std::vector<gf2m> &L, polyn_gf2m* g, s
//m- The extension degree of the GF
//g- The generator polynomial.
gf2m x,y;
- uint32_t i,j,k,r,n;
+ uint32_t r;
std::vector<int> Laux(code_length);
- n=code_length;
r=t*sp_field->get_extension_degree();
- binary_matrix H(r, n) ;
+ binary_matrix H(r, code_length);
- for(i=0;i< n;i++)
+ for(size_t i = 0; i != code_length; i++)
{
x = g->eval(lex_to_gray(L[i]));//evaluate the polynomial at the point L[i].
x = sp_field->gf_inv(x);
y = x;
- for(j=0;j<t;j++)
+ for(size_t j=0;j<t;j++)
{
- for(k=0;k<sp_field->get_extension_degree();k++)
+ for(size_t k=0;k<sp_field->get_extension_degree();k++)
{
if(y & (1<<k))
{
@@ -182,10 +189,10 @@ std::unique_ptr<binary_matrix> generate_R(std::vector<gf2m> &L, polyn_gf2m* g, s
throw Invalid_State("could not bring matrix in row reduced echelon form");
}
- std::unique_ptr<binary_matrix> result(new binary_matrix(n-r,r)) ;
- for (i = 0; i < (*result).m_rown; ++i)
+ std::unique_ptr<binary_matrix> result(new binary_matrix(code_length-r, r)) ;
+ for(size_t i = 0; i < result->rows(); ++i)
{
- for (j = 0; j < (*result).m_coln; ++j)
+ for(size_t j = 0; j < result->columns(); ++j)
{
if (H.coef(j,perm[i]))
{
@@ -193,11 +200,12 @@ std::unique_ptr<binary_matrix> generate_R(std::vector<gf2m> &L, polyn_gf2m* g, s
}
}
}
- for (i = 0; i < code_length; ++i)
+ for(size_t i = 0; i < code_length; ++i)
{
Laux[i] = L[perm[i]];
}
- for (i = 0; i < code_length; ++i)
+
+ for(size_t i = 0; i < code_length; ++i)
{
L[i] = static_cast<gf2m>(Laux[i]);
}
@@ -205,7 +213,7 @@ std::unique_ptr<binary_matrix> generate_R(std::vector<gf2m> &L, polyn_gf2m* g, s
}
}
-McEliece_PrivateKey generate_mceliece_key( RandomNumberGenerator & rng, uint32_t ext_deg, uint32_t code_length, uint32_t t)
+McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator & rng, size_t ext_deg, size_t code_length, size_t t)
{
const size_t codimension = t * ext_deg;
@@ -213,7 +221,8 @@ McEliece_PrivateKey generate_mceliece_key( RandomNumberGenerator & rng, uint32_t
{
throw Invalid_Argument("invalid McEliece parameters");
}
- std::shared_ptr<GF2m_Field> sp_field ( new GF2m_Field(ext_deg ));
+
+ std::shared_ptr<GF2m_Field> sp_field(new GF2m_Field(ext_deg));
//pick the support.........
std::vector<gf2m> L(code_length);
@@ -278,7 +287,7 @@ McEliece_PrivateKey generate_mceliece_key( RandomNumberGenerator & rng, uint32_t
{
Linv[L[i]] = static_cast<gf2m>(i);
}
- std::vector<uint8_t> pubmat (R->m_elem.size() * 4);
+ std::vector<uint8_t> pubmat(R->m_elem.size() * 4);
for(size_t i = 0; i < R->m_elem.size(); i++)
{
store_le(R->m_elem[i], &pubmat[i*4]);
diff --git a/src/lib/pubkey/mce/gf2m_small_m.h b/src/lib/pubkey/mce/gf2m_small_m.h
index e35f14be5..a74094930 100644
--- a/src/lib/pubkey/mce/gf2m_small_m.h
+++ b/src/lib/pubkey/mce/gf2m_small_m.h
@@ -185,7 +185,7 @@ class BOTAN_PUBLIC_API(2,0) GF2m_Field
return m_gf_multiplicative_order;
}
- gf2m get_extension_degree() const
+ size_t get_extension_degree() const
{
return m_gf_extension_degree;
}
@@ -206,7 +206,8 @@ class BOTAN_PUBLIC_API(2,0) GF2m_Field
return static_cast<gf2m>(((d) & gf_ord()) + ((d) >> get_extension_degree()));
}
- gf2m m_gf_extension_degree, m_gf_multiplicative_order;
+ const size_t m_gf_extension_degree;
+ const gf2m m_gf_multiplicative_order;
const std::vector<gf2m>& m_gf_log_table;
const std::vector<gf2m>& m_gf_exp_table;
};
diff --git a/src/lib/pubkey/mce/mce_internal.h b/src/lib/pubkey/mce/mce_internal.h
index f20442588..62dafcc5a 100644
--- a/src/lib/pubkey/mce/mce_internal.h
+++ b/src/lib/pubkey/mce/mce_internal.h
@@ -42,9 +42,9 @@ void mceliece_encrypt(secure_vector<uint8_t>& ciphertext_out,
RandomNumberGenerator& rng);
McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator &rng,
- uint32_t ext_deg,
- uint32_t code_length,
- uint32_t t);
+ size_t ext_deg,
+ size_t code_length,
+ size_t t);
}
diff --git a/src/lib/pubkey/mce/polyn_gf2m.cpp b/src/lib/pubkey/mce/polyn_gf2m.cpp
index 8c58ef69a..763e0f293 100644
--- a/src/lib/pubkey/mce/polyn_gf2m.cpp
+++ b/src/lib/pubkey/mce/polyn_gf2m.cpp
@@ -91,13 +91,13 @@ gf2m random_code_element(unsigned code_length, RandomNumberGenerator& rng)
polyn_gf2m::polyn_gf2m(polyn_gf2m const& other)
:m_deg(other.m_deg),
coeff(other.coeff),
- msp_field(other.msp_field)
+ m_sp_field(other.m_sp_field)
{ }
polyn_gf2m::polyn_gf2m( int d, std::shared_ptr<GF2m_Field> sp_field)
:m_deg(-1),
coeff(d+1),
- msp_field(sp_field)
+ m_sp_field(sp_field)
{
}
@@ -123,8 +123,8 @@ void polyn_gf2m::realloc(uint32_t new_size)
this->coeff = secure_vector<gf2m>(new_size);
}
-polyn_gf2m::polyn_gf2m(const uint8_t* mem, uint32_t mem_len, std::shared_ptr<GF2m_Field> sp_field)
- :m_deg(-1), msp_field(sp_field)
+polyn_gf2m::polyn_gf2m(const uint8_t* mem, uint32_t mem_len, std::shared_ptr<GF2m_Field> sp_field) :
+ m_deg(-1), m_sp_field(sp_field)
{
if(mem_len % sizeof(gf2m))
{
@@ -150,14 +150,12 @@ polyn_gf2m::polyn_gf2m(const uint8_t* mem, uint32_t mem_len, std::shared_ptr<GF2
}
-polyn_gf2m::polyn_gf2m( std::shared_ptr<GF2m_Field> sp_field )
- : m_deg(-1),
- coeff(1),
- msp_field(sp_field)
+polyn_gf2m::polyn_gf2m( std::shared_ptr<GF2m_Field> sp_field) :
+ m_deg(-1), coeff(1), m_sp_field(sp_field)
{}
polyn_gf2m::polyn_gf2m(int degree, const unsigned char* mem, uint32_t mem_byte_len, std::shared_ptr<GF2m_Field> sp_field)
- :msp_field(sp_field)
+ :m_sp_field(sp_field)
{
uint32_t j, k, l;
gf2m a;
@@ -168,7 +166,7 @@ polyn_gf2m::polyn_gf2m(int degree, const unsigned char* mem, uint32_t mem_byte_
throw Botan::Decoding_Error("memory vector for polynomial has wrong size");
}
this->coeff = secure_vector<gf2m>(degree+1);
- gf2m ext_deg = this->msp_field->get_extension_degree();
+ gf2m ext_deg = this->m_sp_field->get_extension_degree();
for (l = 0; l < polyn_size; l++)
{
k = (l * ext_deg) / 8;
@@ -255,7 +253,7 @@ static gf2m eval_aux(const gf2m * /*restrict*/ coeff, gf2m a, int d, std::shared
gf2m polyn_gf2m::eval(gf2m a)
{
- return eval_aux(&this->coeff[0], a, this->m_deg, this->msp_field);
+ return eval_aux(&this->coeff[0], a, this->m_deg, this->m_sp_field);
}
@@ -263,10 +261,10 @@ gf2m polyn_gf2m::eval(gf2m a)
void polyn_gf2m::remainder(polyn_gf2m &p, const polyn_gf2m & g)
{
int i, j, d;
- std::shared_ptr<GF2m_Field> msp_field = g.msp_field;
+ std::shared_ptr<GF2m_Field> m_sp_field = g.m_sp_field;
d = p.get_degree() - g.get_degree();
if (d >= 0) {
- gf2m la = msp_field->gf_inv_rn(g.get_lead_coef());
+ gf2m la = m_sp_field->gf_inv_rn(g.get_lead_coef());
const int p_degree = p.get_degree();
@@ -274,10 +272,10 @@ void polyn_gf2m::remainder(polyn_gf2m &p, const polyn_gf2m & g)
for (i = p_degree; d >= 0; --i, --d) {
if (p[i] != 0) {
- gf2m lb = msp_field->gf_mul_rrn(la, p[i]);
+ gf2m lb = m_sp_field->gf_mul_rrn(la, p[i]);
for (j = 0; j < g.get_degree(); ++j)
{
- p[j+d] ^= msp_field->gf_mul_zrz(lb, g[j]);
+ p[j+d] ^= m_sp_field->gf_mul_zrz(lb, g[j]);
}
(*&p).set_coef( i, 0);
}
@@ -326,7 +324,7 @@ polyn_gf2m polyn_gf2m::sqmod( const std::vector<polyn_gf2m> & sq, int d)
{
int i, j;
gf2m la;
- std::shared_ptr<GF2m_Field> sp_field = this->msp_field;
+ std::shared_ptr<GF2m_Field> sp_field = this->m_sp_field;
polyn_gf2m result(d - 1, sp_field);
// terms of low degree
@@ -391,29 +389,29 @@ polyn_gf2m polyn_gf2m::gcd(polyn_gf2m const& p1, polyn_gf2m const& p2)
// Returns the degree of the smallest factor
void polyn_gf2m::degppf(const polyn_gf2m & g, int* p_result)
{
- int i, d;
polyn_gf2m s(g.get_sp_field());
- d = g.get_degree();
+ const size_t ext_deg = g.m_sp_field->get_extension_degree();
+ const int d = g.get_degree();
std::vector<polyn_gf2m> u = polyn_gf2m::sqmod_init(g);
- polyn_gf2m p( d - 1, g.msp_field);
+ polyn_gf2m p(d - 1, g.m_sp_field);
- p.set_degree( 1);
- (*&p).set_coef( 1, 1);
+ p.set_degree(1);
+ (*&p).set_coef(1, 1);
(*p_result) = d;
- for (i = 1; i <= (d / 2) * g.msp_field->get_extension_degree(); ++i)
+ for(size_t i = 1; i <= (d / 2) * ext_deg; ++i)
{
polyn_gf2m r = p.sqmod(u, d);
- if ((i % g.msp_field->get_extension_degree()) == 0)
+ if ((i % ext_deg) == 0)
{
r[1] ^= 1;
r.get_degree(); // The degree may change
s = polyn_gf2m::gcd( g, r);
- if (s.get_degree() > 0)
+ if(s.get_degree() > 0)
{
- (*p_result) = i / g.msp_field->get_extension_degree();
+ (*p_result) = i / ext_deg;
break;
}
r[1] ^= 1;
@@ -450,7 +448,7 @@ void polyn_gf2m::patchup_deg_secure( uint32_t trgt_deg, volatile gf2m patch_elem
std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn_gf2m & p, const polyn_gf2m & g, int break_deg)
{
- std::shared_ptr<GF2m_Field> msp_field = g.msp_field;
+ std::shared_ptr<GF2m_Field> m_sp_field = g.m_sp_field;
int i, j, dr, du, delta;
gf2m a;
polyn_gf2m aux;
@@ -461,10 +459,10 @@ std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn
BOTAN_ASSERT(dr > 3, "Valid polynomial");
- polyn_gf2m r0(dr, g.msp_field);
- polyn_gf2m r1(dr - 1, g.msp_field);
- polyn_gf2m u0(dr - 1, g.msp_field);
- polyn_gf2m u1(dr - 1, g.msp_field);
+ polyn_gf2m r0(dr, g.m_sp_field);
+ polyn_gf2m r1(dr - 1, g.m_sp_field);
+ polyn_gf2m u0(dr - 1, g.m_sp_field);
+ polyn_gf2m u1(dr - 1, g.m_sp_field);
r0 = g;
r1 = p;
@@ -490,19 +488,19 @@ std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn
for (j = delta; j >= 0; --j)
{
- a = msp_field->gf_div(r0[dr + j], r1[dr]);
+ a = m_sp_field->gf_div(r0[dr + j], r1[dr]);
if (a != 0)
{
- gf2m la = msp_field->gf_log(a);
+ gf2m la = m_sp_field->gf_log(a);
// u0(z) <- u0(z) + a * u1(z) * z^j
for (i = 0; i <= du; ++i)
{
- u0[i + j] ^= msp_field->gf_mul_zrz(la, u1[i]);
+ u0[i + j] ^= m_sp_field->gf_mul_zrz(la, u1[i]);
}
// r0(z) <- r0(z) + a * r1(z) * z^j
for (i = 0; i <= dr; ++i)
{
- r0[i + j] ^= msp_field->gf_mul_zrz(la, r1[i]);
+ r0[i + j] ^= m_sp_field->gf_mul_zrz(la, r1[i]);
}
}
} // end loop over j
@@ -573,7 +571,7 @@ std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn
*/
// Condition for the coefficient to Y to be cancelled out by the
// addition of Y before the square root computation:
- int cond_u1 = msp_field->gf_mul(u0.coeff[1], msp_field->gf_inv(r0.coeff[0])) == 1;
+ int cond_u1 = m_sp_field->gf_mul(u0.coeff[1], m_sp_field->gf_inv(r0.coeff[0])) == 1;
// Condition sigma_3 = 0:
int cond_u3 = u0.coeff[3] == 0;
@@ -588,7 +586,7 @@ std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn
{
uint32_t mask = 0;
int cond_r= r0.get_degree() == 0;
- int cond_u1 = msp_field->gf_mul(u0.coeff[1], msp_field->gf_inv(r0.coeff[0])) == 1;
+ int cond_u1 = m_sp_field->gf_mul(u0.coeff[1], m_sp_field->gf_inv(r0.coeff[0])) == 1;
int cond_u3 = u0.coeff[3] == 0;
int cond_u5 = u0.coeff[5] == 0;
@@ -602,7 +600,7 @@ std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn
{
uint32_t mask = 0;
int cond_r= r0.get_degree() == 0;
- int cond_u1 = msp_field->gf_mul(u0[1], msp_field->gf_inv(r0[0])) == 1;
+ int cond_u1 = m_sp_field->gf_mul(u0[1], m_sp_field->gf_inv(r0[0])) == 1;
int cond_u3 = u0.coeff[3] == 0;
int cond_u5 = u0.coeff[5] == 0;
@@ -641,7 +639,7 @@ std::pair<polyn_gf2m, polyn_gf2m> polyn_gf2m::eea_with_coefficients( const polyn
polyn_gf2m::polyn_gf2m(int t, Botan::RandomNumberGenerator& rng, std::shared_ptr<GF2m_Field> sp_field)
:m_deg(t),
coeff(t+1),
- msp_field(sp_field)
+ m_sp_field(sp_field)
{
(*this).set_coef( t, 1);
int degree = 0;
@@ -663,13 +661,13 @@ void polyn_gf2m::poly_shiftmod( const polyn_gf2m & g)
{
throw Invalid_Argument("shiftmod cannot be called on polynomials of degree 1 or less");
}
- std::shared_ptr<GF2m_Field> field = g.msp_field;
+ std::shared_ptr<GF2m_Field> field = g.m_sp_field;
int t = g.get_degree();
gf2m a = field->gf_div(this->coeff[t-1], g.coeff[t]);
for (int i = t - 1; i > 0; --i)
{
- this->coeff[i] = this->coeff[i - 1] ^ this->msp_field->gf_mul(a, g.coeff[i]);
+ this->coeff[i] = this->coeff[i - 1] ^ this->m_sp_field->gf_mul(a, g.coeff[i]);
}
this->coeff[0] = field->gf_mul(a, g.coeff[0]);
}
@@ -678,7 +676,7 @@ std::vector<polyn_gf2m> polyn_gf2m::sqrt_mod_init(const polyn_gf2m & g)
{
uint32_t i, t;
uint32_t nb_polyn_sqrt_mat;
- std::shared_ptr<GF2m_Field> msp_field = g.msp_field;
+ std::shared_ptr<GF2m_Field> m_sp_field = g.m_sp_field;
std::vector<polyn_gf2m> result;
t = g.get_degree();
nb_polyn_sqrt_mat = t/2;
@@ -691,7 +689,7 @@ std::vector<polyn_gf2m> polyn_gf2m::sqrt_mod_init(const polyn_gf2m & g)
(*&p).set_coef( 1, 1);
// q(z) = 0, p(z) = z
- for (i = 0; i < t * msp_field->get_extension_degree() - 1; ++i)
+ for (i = 0; i < t * m_sp_field->get_extension_degree() - 1; ++i)
{
// q(z) <- p(z)^2 mod g(z)
polyn_gf2m q = p.sqmod(sq_aux, t);
@@ -725,7 +723,7 @@ std::vector<polyn_gf2m> syndrome_init(polyn_gf2m const& generator, std::vector<g
gf2m a;
- std::shared_ptr<GF2m_Field> msp_field = generator.msp_field;
+ std::shared_ptr<GF2m_Field> m_sp_field = generator.m_sp_field;
std::vector<polyn_gf2m> result;
t = generator.get_degree();
@@ -735,25 +733,25 @@ std::vector<polyn_gf2m> syndrome_init(polyn_gf2m const& generator, std::vector<g
for(j=0;j<n;j++)
{
- result.push_back(polyn_gf2m( t-1, msp_field));
+ result.push_back(polyn_gf2m( t-1, m_sp_field));
(*&result[j]).set_coef(t-1,1);
for(i=t-2;i>=0;i--)
{
(*&result[j]).set_coef(i, (generator)[i+1] ^
- msp_field->gf_mul(lex_to_gray(support[j]),result[j][i+1]));
+ m_sp_field->gf_mul(lex_to_gray(support[j]),result[j][i+1]));
}
- a = ((generator)[0] ^ msp_field->gf_mul(lex_to_gray(support[j]),result[j][0]));
+ a = ((generator)[0] ^ m_sp_field->gf_mul(lex_to_gray(support[j]),result[j][0]));
for(i=0;i<t;i++)
{
- (*&result[j]).set_coef(i, msp_field->gf_div(result[j][i],a));
+ (*&result[j]).set_coef(i, m_sp_field->gf_div(result[j][i],a));
}
}
return result;
}
polyn_gf2m::polyn_gf2m(const secure_vector<uint8_t>& encoded, std::shared_ptr<GF2m_Field> sp_field )
- :msp_field(sp_field)
+ :m_sp_field(sp_field)
{
if(encoded.size() % 2)
{
@@ -782,8 +780,8 @@ secure_vector<uint8_t> polyn_gf2m::encode() const
for(unsigned i = 0; i < len; i++)
{
// "big endian" encoding of the GF(2^m) elements
- result.push_back(coeff[i] >> 8);
- result.push_back(coeff[i]);
+ result.push_back(get_byte(0, coeff[i]));
+ result.push_back(get_byte(1, coeff[i]));
}
return result;
}
@@ -791,7 +789,7 @@ secure_vector<uint8_t> polyn_gf2m::encode() const
void polyn_gf2m::swap(polyn_gf2m& other)
{
std::swap(this->m_deg, other.m_deg);
- std::swap(this->msp_field, other.msp_field);
+ std::swap(this->m_sp_field, other.m_sp_field);
std::swap(this->coeff, other.coeff);
}
diff --git a/src/lib/pubkey/mce/polyn_gf2m.h b/src/lib/pubkey/mce/polyn_gf2m.h
index 757a5883e..f2d3ac53c 100644
--- a/src/lib/pubkey/mce/polyn_gf2m.h
+++ b/src/lib/pubkey/mce/polyn_gf2m.h
@@ -73,7 +73,7 @@ class polyn_gf2m
polyn_gf2m(int t, RandomNumberGenerator& rng, std::shared_ptr<GF2m_Field> sp_field);
std::shared_ptr<GF2m_Field> get_sp_field() const
- { return msp_field; }
+ { return m_sp_field; }
gf2m& operator[](size_t i) { return coeff[i]; }
@@ -153,7 +153,7 @@ class polyn_gf2m
secure_vector<gf2m> coeff;
// public member variable:
- std::shared_ptr<GF2m_Field> msp_field;
+ std::shared_ptr<GF2m_Field> m_sp_field;
};
gf2m random_gf2m(RandomNumberGenerator& rng);