small fixes
This commit is contained in:
parent
b54fcb9bf3
commit
56ea9083fc
|
@ -15,12 +15,11 @@ namespace ccr
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* typedefs. uint and sint should be able to comfortably hold the field
|
* typedef. uint should be able to comfortably hold the field elements of
|
||||||
* elements of underlying calculations (esp. with polynomials. Switching to
|
* underlying calculations (esp. with polynomials. Switching to 64bits is
|
||||||
* 64bits is adviseable when computing with n=64K and larger.
|
* adviseable when computing with n=64K and larger.
|
||||||
*/
|
*/
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef int sint;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vector over GF(2). We rely on STL's vector<bool> == bit_vector
|
* vector over GF(2). We rely on STL's vector<bool> == bit_vector
|
||||||
|
@ -122,7 +121,7 @@ public:
|
||||||
|
|
||||||
uint add (uint, uint);
|
uint add (uint, uint);
|
||||||
uint mult (uint, uint);
|
uint mult (uint, uint);
|
||||||
uint exp (uint, sint);
|
uint exp (uint, int);
|
||||||
uint inv (uint);
|
uint inv (uint);
|
||||||
uint sq_root (uint);
|
uint sq_root (uint);
|
||||||
};
|
};
|
||||||
|
|
31
lib/gf2m.cpp
31
lib/gf2m.cpp
|
@ -9,9 +9,12 @@ using namespace ccr;
|
||||||
|
|
||||||
int gf2p_degree (uint p)
|
int gf2p_degree (uint p)
|
||||||
{
|
{
|
||||||
int r = -1;
|
int r = 0;
|
||||||
for (int i = 0; p; p >>= 1, ++i) r = i;
|
while (p) {
|
||||||
return r;
|
++r;
|
||||||
|
p >>= 1;
|
||||||
|
}
|
||||||
|
return r - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint gf2p_add (uint a, uint b)
|
inline uint gf2p_add (uint a, uint b)
|
||||||
|
@ -24,7 +27,7 @@ uint gf2p_mod (uint a, uint p)
|
||||||
if (!p) return 0;
|
if (!p) return 0;
|
||||||
int t, degp = gf2p_degree (p);
|
int t, degp = gf2p_degree (p);
|
||||||
while ( (t = gf2p_degree (a) ) >= degp) {
|
while ( (t = gf2p_degree (a) ) >= degp) {
|
||||||
a ^= p << (t - degp);
|
a ^= (p << (t - degp) );
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
@ -47,12 +50,12 @@ uint gf2p_modmult (uint a, uint b, uint p)
|
||||||
b = gf2p_mod (b, p);
|
b = gf2p_mod (b, p);
|
||||||
uint r = 0;
|
uint r = 0;
|
||||||
uint d = 1 << gf2p_degree (p);
|
uint d = 1 << gf2p_degree (p);
|
||||||
while (a) {
|
if (b) while (a) {
|
||||||
if (a & 1) r ^= b;
|
if (a & 1) r ^= b;
|
||||||
a >>= 1;
|
a >>= 1;
|
||||||
b <<= 1;
|
b <<= 1;
|
||||||
if (b >= d) b ^= p;
|
if (b >= d) b ^= p;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +64,7 @@ bool is_irreducible_gf2_poly (uint p)
|
||||||
if (!p) return false;
|
if (!p) return false;
|
||||||
int d = gf2p_degree (p) / 2;
|
int d = gf2p_degree (p) / 2;
|
||||||
uint test = 2; //x^1+0
|
uint test = 2; //x^1+0
|
||||||
for (int i = 0; i < d; ++i) {
|
for (int i = 0; i <= d; ++i) {
|
||||||
test = gf2p_modmult (test, test, p);
|
test = gf2p_modmult (test, test, p);
|
||||||
|
|
||||||
if (gf2p_gcd (test ^ 2 /* test - x^1 */, p) != 1)
|
if (gf2p_gcd (test ^ 2 /* test - x^1 */, p) != 1)
|
||||||
|
@ -84,12 +87,16 @@ bool gf2m::create (uint M)
|
||||||
m = M;
|
m = M;
|
||||||
n = 1 << m;
|
n = 1 << m;
|
||||||
if (!n) return false; //too big.
|
if (!n) return false; //too big.
|
||||||
|
poly = 0;
|
||||||
|
//FIXME fails for M>=12. Why?
|
||||||
for (uint t = (1 << m) + 1, e = 1 << (m + 1); t < e; t += 2)
|
for (uint t = (1 << m) + 1, e = 1 << (m + 1); t < e; t += 2)
|
||||||
if (is_irreducible_gf2_poly (t) ) {
|
if (is_irreducible_gf2_poly (t) ) {
|
||||||
poly = t;
|
poly = t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!poly) return false;
|
||||||
|
|
||||||
log.resize (n);
|
log.resize (n);
|
||||||
antilog.resize (n);
|
antilog.resize (n);
|
||||||
log[0] = n - 1;
|
log[0] = n - 1;
|
||||||
|
@ -115,7 +122,7 @@ uint gf2m::mult (uint a, uint b)
|
||||||
return gf2p_tablemult (a, b, n, log, antilog);
|
return gf2p_tablemult (a, b, n, log, antilog);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint gf2m::exp (uint a, sint k)
|
uint gf2m::exp (uint a, int k)
|
||||||
{
|
{
|
||||||
if (!a) return 0;
|
if (!a) return 0;
|
||||||
if (a == 1) return 1;
|
if (a == 1) return 1;
|
||||||
|
|
|
@ -15,10 +15,9 @@ int ccr::mce::generate (pubkey&pub, privkey&priv, prng&rng, uint m, uint t)
|
||||||
priv.g.generate_random_irreducible (t, priv.fld, rng);
|
priv.g.generate_random_irreducible (t, priv.fld, rng);
|
||||||
|
|
||||||
//check and generator matrix
|
//check and generator matrix
|
||||||
matrix generator;
|
|
||||||
permutation hp;
|
|
||||||
priv.g.compute_goppa_check_matrix (priv.h, priv.fld);
|
priv.g.compute_goppa_check_matrix (priv.h, priv.fld);
|
||||||
|
|
||||||
|
matrix generator;
|
||||||
for (;;) if (priv.h.create_goppa_generator
|
for (;;) if (priv.h.create_goppa_generator
|
||||||
(generator, priv.hperm, rng) ) break;
|
(generator, priv.hperm, rng) ) break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue