check matrix
This commit is contained in:
parent
171c660d3d
commit
19225c3665
|
@ -120,13 +120,15 @@ public:
|
||||||
void strip();
|
void strip();
|
||||||
int degree() const;
|
int degree() const;
|
||||||
bool zero() const;
|
bool zero() const;
|
||||||
|
uint eval (uint, gf2m&) const;
|
||||||
void add (const polynomial&, gf2m&);
|
void add (const polynomial&, gf2m&);
|
||||||
void mod (const polynomial&, gf2m&);
|
void mod (const polynomial&, gf2m&);
|
||||||
void mult (const polynomial&, gf2m&);
|
void mult (const polynomial&, gf2m&);
|
||||||
polynomial gcd (polynomial, gf2m&);
|
polynomial gcd (polynomial, gf2m&);
|
||||||
bool is_irreducible (gf2m&);
|
bool is_irreducible (gf2m&) const;
|
||||||
void generate_random_irreducible (uint s, gf2m&, prng&);
|
void generate_random_irreducible (uint s, gf2m&, prng&);
|
||||||
bool compute_square_root_matrix (std::vector<polynomial>&, gf2m&);
|
bool compute_square_root_matrix (std::vector<polynomial>&, gf2m&);
|
||||||
|
void compute_goppa_check_matrix (matrix&, gf2m&);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -3,14 +3,6 @@
|
||||||
|
|
||||||
using namespace ccr;
|
using namespace ccr;
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
void dump (const polynomial&t)
|
|
||||||
{
|
|
||||||
for (uint i = 0; i < t.size(); ++i) cout << t[i] << ' ';
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int polynomial::degree() const
|
int polynomial::degree() const
|
||||||
{
|
{
|
||||||
int r = -1;
|
int r = -1;
|
||||||
|
@ -45,6 +37,7 @@ void polynomial::mod (const polynomial&f, gf2m&fld)
|
||||||
for (d = degree(); d >= df; --d)
|
for (d = degree(); d >= df; --d)
|
||||||
if (item (d) ) {
|
if (item (d) ) {
|
||||||
uint t = fld.mult (item (d), hi);
|
uint t = fld.mult (item (d), hi);
|
||||||
|
|
||||||
for (int i = 0; i <= df; ++i)
|
for (int i = 0; i <= df; ++i)
|
||||||
item (i + d - df) = fld.add (item (i + d - df),
|
item (i + d - df) = fld.add (item (i + d - df),
|
||||||
fld.mult (t, f[i]) );
|
fld.mult (t, f[i]) );
|
||||||
|
@ -82,7 +75,7 @@ polynomial polynomial::gcd (polynomial b, gf2m&fld)
|
||||||
return polynomial();
|
return polynomial();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool polynomial::is_irreducible (gf2m&fld)
|
bool polynomial::is_irreducible (gf2m&fld) const
|
||||||
{
|
{
|
||||||
//Ben-Or irreducibility test
|
//Ben-Or irreducibility test
|
||||||
polynomial xi; //x^(2^i) in our case
|
polynomial xi; //x^(2^i) in our case
|
||||||
|
@ -103,7 +96,7 @@ bool polynomial::is_irreducible (gf2m&fld)
|
||||||
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) != 1
|
if (t.degree() > 0) //gcd(f,x^2^i - x mod f) is polynomial
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -191,3 +184,45 @@ for(int c=0;c<d;++c) {\
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint polynomial::eval (uint x, gf2m&fld) const
|
||||||
|
{
|
||||||
|
uint r = 0;
|
||||||
|
//horner
|
||||||
|
for (int i = degree(); i >= 0; --i)
|
||||||
|
r = fld.add (item (i), fld.mult (r, x) );
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void polynomial::compute_goppa_check_matrix (matrix&r, gf2m&fld)
|
||||||
|
{
|
||||||
|
if (degree() < 0) return; //wrongly initialized polynomial
|
||||||
|
uint t = degree();
|
||||||
|
vector<vector<uint> > yz, h;
|
||||||
|
uint i, j, k;
|
||||||
|
yz.resize (t);
|
||||||
|
h.resize (t);
|
||||||
|
for (i = 0; i < t; ++i) {
|
||||||
|
yz[i].resize (fld.n);
|
||||||
|
h[i].resize (fld.n, 0);
|
||||||
|
}
|
||||||
|
//create Y*Z
|
||||||
|
for (i = 0; i < fld.n; ++i) yz[0][i] = fld.inv (eval (i, fld) );
|
||||||
|
for (i = 1; i < t; ++i) for (j = 0; j < fld.n; ++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
|
||||||
|
r.resize (fld.n);
|
||||||
|
for (i = 0; i < fld.n; ++i) {
|
||||||
|
r[i].resize (fld.m * t, 0);
|
||||||
|
for (j = 0; j < fld.m * t; ++j)
|
||||||
|
r[i][j] = (h[j/fld.m][i] >> (j % fld.m) ) & 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue