diff --git a/include/codecrypt.h b/include/codecrypt.h index d3efb74..0d248b8 100644 --- a/include/codecrypt.h +++ b/include/codecrypt.h @@ -78,6 +78,8 @@ public: void unit (uint); bool get_left_square (matrix&); bool strip_left_square (matrix&); + bool get_right_square (matrix&); + bool strip_right_square (matrix&); void extend_left_compact (matrix&); bool create_goppa_generator (matrix&, permutation&, prng&); bool create_goppa_generator (matrix&, const permutation&); diff --git a/lib/matrix.cpp b/lib/matrix.cpp index 13e0ee7..adef1f3 100644 --- a/lib/matrix.cpp +++ b/lib/matrix.cpp @@ -127,6 +127,24 @@ bool matrix::strip_left_square (matrix&r) return true; } +bool matrix::get_right_square (matrix&r) +{ + uint h = height(); + if (width() < h) return false; + r.resize (h); + for (uint i = 0; i < h; ++i) r[i] = item (h + i); + return true; +} + +bool matrix::strip_right_square (matrix&r) +{ + uint h = height(), w = width(); + if (w < h) return false; + r.resize (w - h); + for (uint i = 0; i < w - h; ++i) r[i] = item (i); + return true; +} + void matrix::extend_left_compact (matrix&r) { uint i; diff --git a/lib/polynomial.cpp b/lib/polynomial.cpp index 6edb8f9..81cf886 100644 --- a/lib/polynomial.cpp +++ b/lib/polynomial.cpp @@ -225,19 +225,29 @@ void polynomial::compute_goppa_check_matrix (matrix&r, gf2m&fld) { if (degree() < 0) return; //wrongly initialized polynomial uint t = degree(); - vector > h; - uint i, j; + vector > vd, h; + uint i, j, k; - //construction from Sendrier's slides with maximal support L=[0..fld.n) - h.resize (fld.n); + //construction from Barreto's slides with maximal support L=[0..fld.n) + vd.resize (fld.n); for (i = 0; i < fld.n; ++i) { - h[i].resize (t); - h[i][0] = fld.inv (eval (i, fld) ); - if(h[i][0]==0) std::cout << "BLE" << std::endl; + vd[i].resize (t); + vd[i][0] = fld.inv (eval (i, fld) ); } //compute support powers for (j = 0; j < fld.n; ++j) for (i = 1; i < t; ++i) - h[j][i] = fld.mult (h[j][i-1], j); + vd[j][i] = fld.mult (vd[j][i-1], j); + + //multiply by goppa coefficients (compute t*vd) + h.resize (fld.n); + for (i = 0; i < fld.n; ++i) { + h[i].resize (t, 0); + for (j = 0; j < t; ++j) //computing the element h[i][j] + for (k = 0; k <= j; ++k) //k = column index of t + h[i][j] = fld.add (h[i][j], + fld.mult (item (t - j + k), + vd[i][k]) ); + } //now convert to binary r.resize (fld.n);