polynomial fixes
irreducibility, goppa check matrix
This commit is contained in:
parent
b4381c473e
commit
781ea21513
|
@ -134,6 +134,7 @@ public:
|
||||||
void strip();
|
void strip();
|
||||||
int degree() const;
|
int degree() const;
|
||||||
bool zero() const;
|
bool zero() const;
|
||||||
|
bool one() const;
|
||||||
void shift (uint);
|
void shift (uint);
|
||||||
|
|
||||||
uint eval (uint, gf2m&) const;
|
uint eval (uint, gf2m&) const;
|
||||||
|
|
|
@ -21,6 +21,12 @@ bool polynomial::zero() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool polynomial::one() const
|
||||||
|
{
|
||||||
|
if (degree() != 0) return false;
|
||||||
|
return item (0) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
void polynomial::add (const polynomial&f, gf2m&fld)
|
void polynomial::add (const polynomial&f, gf2m&fld)
|
||||||
{
|
{
|
||||||
int df = f.degree();
|
int df = f.degree();
|
||||||
|
@ -107,14 +113,17 @@ bool polynomial::is_irreducible (gf2m&fld) const
|
||||||
|
|
||||||
uint d = degree();
|
uint d = degree();
|
||||||
for (uint i = 1; i <= d / 2; ++i) {
|
for (uint i = 1; i <= d / 2; ++i) {
|
||||||
|
for (uint j = 0; j < fld.m; ++j) {
|
||||||
|
t = xi;
|
||||||
|
t.mult (xi, fld);
|
||||||
|
t.mod (*this, fld);
|
||||||
|
xi.swap (t);
|
||||||
|
}
|
||||||
t = xi;
|
t = xi;
|
||||||
t.mult (xi, fld); //because mult would destroy xi on xi.mult(xi)
|
|
||||||
t.mod (*this, fld);
|
|
||||||
xi = t;
|
|
||||||
t.add (xmodf, fld);
|
t.add (xmodf, fld);
|
||||||
|
|
||||||
t = t.gcd (*this, fld);
|
t = t.gcd (*this, fld);
|
||||||
if (t.degree() > 0) //gcd(f,x^2^i - x mod f) is polynomial
|
if (t.degree() > 0) //gcd(f,x^2^i - x mod f) != const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -124,7 +133,7 @@ void polynomial::generate_random_irreducible (uint s, gf2m&fld, prng& rng)
|
||||||
{
|
{
|
||||||
resize (s + 1);
|
resize (s + 1);
|
||||||
item (s) = 1; //degree s
|
item (s) = 1; //degree s
|
||||||
item (0) = 1 + rng.random (fld.n - 1); //not divisible by x^1
|
item (0) = 1 + rng.random (fld.n - 1);
|
||||||
for (uint i = 1; i < s; ++i) item (i) = rng.random (fld.n);
|
for (uint i = 1; i < s; ++i) item (i) = rng.random (fld.n);
|
||||||
while (!is_irreducible (fld) ) {
|
while (!is_irreducible (fld) ) {
|
||||||
uint pos = rng.random (s);
|
uint pos = rng.random (s);
|
||||||
|
@ -216,32 +225,26 @@ void polynomial::compute_goppa_check_matrix (matrix&r, gf2m&fld)
|
||||||
{
|
{
|
||||||
if (degree() < 0) return; //wrongly initialized polynomial
|
if (degree() < 0) return; //wrongly initialized polynomial
|
||||||
uint t = degree();
|
uint t = degree();
|
||||||
vector<vector<uint> > yz, h;
|
vector<vector<uint> > h;
|
||||||
uint i, j, k;
|
uint i, j;
|
||||||
yz.resize (t);
|
|
||||||
h.resize (t);
|
//construction from Sendrier's slides with maximal support L=[0..fld.n)
|
||||||
for (i = 0; i < t; ++i) {
|
h.resize (fld.n);
|
||||||
yz[i].resize (fld.n);
|
for (i = 0; i < fld.n; ++i) {
|
||||||
h[i].resize (fld.n, 0);
|
h[i].resize (t);
|
||||||
|
h[i][0] = fld.inv (eval (i, fld) );
|
||||||
|
if(h[i][0]==0) std::cout << "BLE" << std::endl;
|
||||||
}
|
}
|
||||||
//create Y*Z
|
//compute support powers
|
||||||
for (i = 0; i < fld.n; ++i) yz[0][i] = fld.inv (eval (i, fld) );
|
for (j = 0; j < fld.n; ++j) for (i = 1; i < t; ++i)
|
||||||
for (i = 1; i < t; ++i) for (j = 0; j < fld.n; ++j)
|
h[j][i] = fld.mult (h[j][i-1], j);
|
||||||
yz[i][j] = fld.mult (yz[i-1][j], j);
|
|
||||||
//X*Y*Z = h
|
|
||||||
for (i = 0; i < t; ++i)
|
|
||||||
for (j = 0; j < fld.n; ++j)
|
|
||||||
for (k = 0; k <= i; ++k)
|
|
||||||
h[i][j] = fld.add (h[i][j], fld.mult
|
|
||||||
(yz[k][j],
|
|
||||||
item (t + k - i) ) );
|
|
||||||
|
|
||||||
//now convert to binary
|
//now convert to binary
|
||||||
r.resize (fld.n);
|
r.resize (fld.n);
|
||||||
for (i = 0; i < fld.n; ++i) {
|
for (i = 0; i < fld.n; ++i) {
|
||||||
r[i].resize (fld.m * t, 0);
|
r[i].resize (fld.m * t);
|
||||||
for (j = 0; j < fld.m * t; ++j)
|
for (j = 0; j < fld.m * t; ++j)
|
||||||
r[i][j] = (h[j/fld.m][i] >> (j % fld.m) ) & 1;
|
r[i][j] = (h[i][j/fld.m] >> (j % fld.m) ) & 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +281,6 @@ void polynomial::div (polynomial&p, polynomial&m, gf2m&fld)
|
||||||
polynomial r0, r1, s0, s1, s2, q1, q2;
|
polynomial r0, r1, s0, s1, s2, q1, q2;
|
||||||
|
|
||||||
r0 = m;
|
r0 = m;
|
||||||
|
|
||||||
r1 = p;
|
r1 = p;
|
||||||
r1.mod (m, fld);
|
r1.mod (m, fld);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue