aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-02-06 01:55:59 +0000
committerlloyd <[email protected]>2015-02-06 01:55:59 +0000
commit1c198a86b3461adbc759a3a423d302c763255cd4 (patch)
treefd84f1642368f2c9360562f8520df8187df84dc7 /src
parentcb8606277d4b2f5ef1cf33e3d24b982ce1286373 (diff)
Remove static casts
Diffstat (limited to 'src')
-rw-r--r--src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp6
-rw-r--r--src/lib/pubkey/mce/gf2m_small_m.cpp8
-rw-r--r--src/lib/pubkey/mce/goppa_code.cpp2
-rw-r--r--src/lib/pubkey/mce/mceliece.cpp16
-rw-r--r--src/lib/pubkey/mce/polyn_gf2m.cpp12
-rw-r--r--src/lib/pubkey/mce/workfactor.cpp18
6 files changed, 28 insertions, 34 deletions
diff --git a/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp b/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
index 4f47de815..85da0ec1d 100644
--- a/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
+++ b/src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
@@ -181,7 +181,7 @@ void gf2m_decomp_rootfind_state::calc_next_Aij()
{
gf2m delta_offs = 5;
diff = this->m_j_gray ^ new_j_gray;
- while(((((gf2m)1) << delta_offs) & diff) == 0)
+ while(((static_cast<gf2m>(1) << delta_offs) & diff) == 0)
{
delta_offs++;
@@ -206,7 +206,7 @@ void gf2m_decomp_rootfind_state::calc_LiK(const polyn_gf2m & sigma)
{
u32bit Lik_pos_base = k * this->m_outer_summands;
gf2m alpha_l_k_tt2_ttj[4];
- alpha_l_k_tt2_ttj[0] = sp_field->gf_l_from_n( ((gf2m)1) << k);
+ alpha_l_k_tt2_ttj[0] = sp_field->gf_l_from_n(static_cast<gf2m>(1) << k);
alpha_l_k_tt2_ttj[1] = sp_field->gf_mul_rrr(alpha_l_k_tt2_ttj[0], alpha_l_k_tt2_ttj[0]);
alpha_l_k_tt2_ttj[2] = sp_field->gf_mul_rrr(alpha_l_k_tt2_ttj[1],alpha_l_k_tt2_ttj[1] );
@@ -220,7 +220,7 @@ void gf2m_decomp_rootfind_state::calc_LiK(const polyn_gf2m & sigma)
for(j = 0; j <= 3; j++)
{
gf2m f, x;
- u32bit f_ind = five_i + ((u32bit)1<<j);
+ u32bit f_ind = five_i + (static_cast<u32bit>(1) << j);
if(f_ind > d)
{
break;
diff --git a/src/lib/pubkey/mce/gf2m_small_m.cpp b/src/lib/pubkey/mce/gf2m_small_m.cpp
index d5007a082..4437378d3 100644
--- a/src/lib/pubkey/mce/gf2m_small_m.cpp
+++ b/src/lib/pubkey/mce/gf2m_small_m.cpp
@@ -104,10 +104,10 @@ Gf2m_Field::Gf2m_Field(size_t extdeg)
gf2m Gf2m_Field::gf_div(gf2m x, gf2m y)
{
- s32bit sub_res = ((s32bit)m_gf_log_table[x]) - ((s32bit) m_gf_log_table[y]);
- s32bit modq_res = ((s32bit)_gf_modq_1(sub_res));
- s32bit div_res = (((s32bit)x) ? ((s32bit) m_gf_exp_table[modq_res]) : 0 );
- return (gf2m) div_res;
+ s32bit sub_res = static_cast<s32bit>(m_gf_log_table[x]) - static_cast<s32bit>( m_gf_log_table[y]);
+ s32bit modq_res = static_cast<s32bit>(_gf_modq_1(sub_res));
+ s32bit div_res = static_cast<s32bit>(x) ? static_cast<s32bit>(m_gf_exp_table[modq_res]) : 0;
+ return static_cast<gf2m>(div_res);
}
// we suppose i >= 0. Par convention 0^0 = 1
diff --git a/src/lib/pubkey/mce/goppa_code.cpp b/src/lib/pubkey/mce/goppa_code.cpp
index 59e8ab97d..6f4b40226 100644
--- a/src/lib/pubkey/mce/goppa_code.cpp
+++ b/src/lib/pubkey/mce/goppa_code.cpp
@@ -141,7 +141,7 @@ secure_vector<byte> mceliece_decrypt(
u32bit t = key.get_goppa_polyn().get_degree();
polyn_gf2m syndrome_polyn(key.get_goppa_polyn().get_sp_field()); // init as zero polyn
const unsigned unused_pt_bits = dimension % 8;
- const unsigned char unused_pt_bits_mask = (1 << unused_pt_bits) - 1;
+ const byte unused_pt_bits_mask = (1 << unused_pt_bits) - 1;
if(ciphertext_len != (key.get_code_length()+7)/8)
{
diff --git a/src/lib/pubkey/mce/mceliece.cpp b/src/lib/pubkey/mce/mceliece.cpp
index 4986254b1..ed4d24467 100644
--- a/src/lib/pubkey/mce/mceliece.cpp
+++ b/src/lib/pubkey/mce/mceliece.cpp
@@ -21,12 +21,14 @@
namespace Botan {
namespace {
-void concat_vectors(unsigned char* x, const unsigned char* a, const unsigned char* b, u32bit dimension, u32bit codimension)
+
+void concat_vectors(byte* x, const byte* a, const byte* b, u32bit dimension, u32bit codimension)
{
if(dimension % 8 == 0)
{
- copy_mem(x, a, bit_size_to_byte_size(dimension));
- copy_mem(((unsigned char *) x) + bit_size_to_byte_size(dimension), b, bit_size_to_byte_size(codimension));
+ const size_t dim_bytes = bit_size_to_byte_size(dimension);
+ copy_mem(x, a, dim_bytes);
+ copy_mem(x + dim_bytes, b, bit_size_to_byte_size(codimension));
}
else
{
@@ -35,15 +37,15 @@ void concat_vectors(unsigned char* x, const unsigned char* a, const unsigned cha
j = 8 - i;
l = dimension / 8;
copy_mem(x, a, 1 * (dimension / 8));
- x[l] = ((byte) (a[l] & ((1 << i) - 1)));
+ x[l] = static_cast<byte>(a[l] & ((1 << i) - 1));
for(k = 0; k < codimension / 8; ++k)
{
- x[l] ^= ((byte) ( b[k] << i));
+ x[l] ^= static_cast<byte>(b[k] << i);
++l;
- x[l] = ((byte) (b[k] >> j));
+ x[l] = static_cast<byte>(b[k] >> j);
}
- x[l] ^= ((byte) ( b[k] << i));
+ x[l] ^= static_cast<byte>(b[k] << i);
}
}
diff --git a/src/lib/pubkey/mce/polyn_gf2m.cpp b/src/lib/pubkey/mce/polyn_gf2m.cpp
index 489332069..0f203ec11 100644
--- a/src/lib/pubkey/mce/polyn_gf2m.cpp
+++ b/src/lib/pubkey/mce/polyn_gf2m.cpp
@@ -74,8 +74,7 @@ gf2m random_code_element(unsigned code_length, Botan::RandomNumberGenerator& rng
gf2m result;
do
{
- rng.randomize((byte*)&result, sizeof(result));
-
+ rng.randomize(reinterpret_cast<byte*>(&result), sizeof(result));
result &= mask;
} while(result >= code_length); // rejection sampling
return result;
@@ -98,7 +97,7 @@ std::string polyn_gf2m::to_string() const
{
int d = get_degree();
std::string result;
- for(int i = 0; i < d + 1; i ++)
+ for(int i = 0; i <= d; i ++)
{
result += std::to_string(this->coeff[i]);
if(i != d)
@@ -280,12 +279,11 @@ void polyn_gf2m::remainder(polyn_gf2m &p, const polyn_gf2m & g)
std::vector<polyn_gf2m> polyn_gf2m::sqmod_init(const polyn_gf2m & g)
{
std::vector<polyn_gf2m> sq;
- int signed_deg = g.get_degree();
+ const int signed_deg = g.get_degree();
if(signed_deg <= 0)
- {
throw Invalid_Argument("cannot compute sqmod for such low degree");
- }
- u32bit d = (u32bit) signed_deg;
+
+ const u32bit d = static_cast<u32bit>(signed_deg);
u32bit t = g.m_deg;
// create t zero polynomials
u32bit i;
diff --git a/src/lib/pubkey/mce/workfactor.cpp b/src/lib/pubkey/mce/workfactor.cpp
index b0a990a3a..e7cf631d4 100644
--- a/src/lib/pubkey/mce/workfactor.cpp
+++ b/src/lib/pubkey/mce/workfactor.cpp
@@ -50,20 +50,19 @@ double nb_iter(size_t n, size_t k, size_t w, size_t p, size_t l)
double cout_iter(size_t n, size_t k, size_t p, size_t l)
{
- // x <- binomial(k/2,p)
double x = binomial(k / 2, p);
- // i <- log[2](binomial(k/2,p))
- size_t i = (size_t) (std::log(x) / std::log(2)); // normalement i < 2^31
- // res <- 2*p*(n-k-l)*binomial(k/2,p)^2/2^l
+ const size_t i = static_cast<size_t>(std::log(x) / std::log(2));
double res = 2 * p * (n - k - l) * ldexp(x * x, -l);
+
// x <- binomial(k/2,p)*2*(2*l+log[2](binomial(k/2,p)))
x *= 2 * (2 * l + i);
+
// res <- k*(n-k)/2 +
// binomial(k/2,p)*2*(2*l+log[2](binomial(k/2,p))) +
// 2*p*(n-k-l)*binomial(k/2,p)^2/2^l
res += x + k * ((n - k) / 2.0);
- return std::log(res) / std::log(2);
+ return std::log(res) / std::log(2); // convert to bits
}
double cout_total(size_t n, size_t k, size_t w, size_t p, size_t l)
@@ -76,18 +75,13 @@ double best_wf(size_t n, size_t k, size_t w, size_t p)
if(p >= k / 2)
return -1;
- // On part de l = u, en faisant croitre l.
- // On s'arrète dés que le work factor croit.
- // Puis on explore les valeurs <u, mais en tenant de la convexite'
-
double min = cout_total(n, k, w, p, 0);
+
for(size_t l = 1; l < n - k; ++l)
{
- double lwf = cout_total(n, k, w, p, l);
+ const double lwf = cout_total(n, k, w, p, l);
if(lwf < min)
- {
min = lwf;
- }
else
break;
}