vector helpers

This commit is contained in:
Mirek Kratochvil 2012-04-05 15:20:01 +02:00
parent b22e2177fe
commit 5ba94ca423
3 changed files with 58 additions and 12 deletions

View file

@ -77,6 +77,9 @@ public:
void extend_left_compact (matrix&); void extend_left_compact (matrix&);
bool create_goppa_generator (matrix&, permutation&, prng&); bool create_goppa_generator (matrix&, permutation&, prng&);
bool create_goppa_generator (matrix&, const permutation&); bool create_goppa_generator (matrix&, const permutation&);
bool mult_vecT_left (const bvector&, bvector&);
bool mult_vec_right (const bvector&, bvector&);
}; };
/* /*
@ -158,6 +161,13 @@ public:
int prepare(); int prepare();
int decrypt (const bvector&, bvector&); int decrypt (const bvector&, bvector&);
int sign (const bvector&, bvector&, uint, uint, prng&); int sign (const bvector&, bvector&, uint, uint, prng&);
uint cipher_size() {
return Pinv.size();
}
uint plain_size() {
return Sinv.width();
}
}; };
class pubkey class pubkey
@ -168,6 +178,13 @@ public:
int encrypt (const bvector&, bvector&, prng&); int encrypt (const bvector&, bvector&, prng&);
int verify (const bvector&, const bvector&, uint, uint); int verify (const bvector&, const bvector&, uint, uint);
uint cipher_size() {
return G.width();
}
uint plain_size() {
return G.height();
}
}; };
int generate (pubkey&, privkey&, prng&, uint m, uint t); int generate (pubkey&, privkey&, prng&, uint m, uint t);

View file

@ -161,3 +161,31 @@ bool matrix::create_goppa_generator (matrix&g, const permutation&p)
s.extend_left_compact (g); s.extend_left_compact (g);
return true; return true;
} }
bool matrix::mult_vecT_left (const bvector&a, bvector&r)
{
uint w = width(), h = height();
if (a.size() != h) return false;
r.resize (w, 0);
for (uint i = 0; i < w; ++i) {
bool t = 0;
for (uint j = 0; j < h; ++j)
t ^= item (i) [j] & a[j];
r[i] = t;
}
return true;
}
bool matrix::mult_vec_right (const bvector&a, bvector&r)
{
uint w = width(), h = height();
if (a.size() != w) return false;
r.resize (h, 0);
for (uint i = 0; i < h; ++i) {
bool t = 0;
for (uint j = 0; j < w; ++j)
t ^= item (j) [i] & a[j];
r[i] = t;
}
return true;
}

View file

@ -7,35 +7,36 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
ostream& operator<<(ostream&o, ccr::polynomial p) ostream& operator<< (ostream&o, ccr::polynomial p)
{ {
o << "polynomial degree " << p.degree() << ':' << endl; o << "polynomial degree " << p.degree() << ':' << endl;
for(int i=0,e=p.degree();i<=e;++i) o << p[i] << ' '; for (int i = 0, e = p.degree(); i <= e; ++i) o << p[i] << ' ';
o << endl; o << endl;
return o; return o;
} }
ostream& operator<<(ostream&o, ccr::permutation p) ostream& operator<< (ostream&o, ccr::permutation p)
{ {
o << "permutation over " << p.size() << " elements:" << endl; o << "permutation over " << p.size() << " elements:" << endl;
for(uint i=0;i<p.size();++i) o << p[i] << ' '; for (uint i = 0; i < p.size(); ++i) o << p[i] << ' ';
o << endl; o << endl;
return o; return o;
} }
ostream& operator<<(ostream&o, ccr::gf2m f) ostream& operator<< (ostream&o, ccr::gf2m f)
{ {
o << "GF(2^"<<f.m<<") of "<<f.n<<" elements, modulus "<<f.poly << endl; o << "GF(2^" << f.m << ") of " << f.n << " elements, modulus " << f.poly << endl;
return o; return o;
} }
ostream& operator<<(ostream&o, ccr::matrix m) ostream& operator<< (ostream&o, ccr::matrix m)
{ {
uint i,j,h,w; uint i, j, h, w;
h=m.height();w=m.width(); h = m.height();
o << "binary "<<h<<"x"<<w<<" matrix:" << endl; w = m.width();
for(i=0;i<h;++i) { o << "binary " << h << "x" << w << " matrix:" << endl;
for(j=0;j<w;++j) o << m[j][i]; for (i = 0; i < h; ++i) {
for (j = 0; j < w; ++j) o << m[j][i];
o << endl; o << endl;
} }
return o; return o;