From 9e9737413159e150122872dcad5b77af28a8f7fa Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 5 Apr 2012 13:52:42 +0200 Subject: [PATCH] goppa generator matrix --- include/codecrypt.h | 10 ++++++---- lib/matrix.cpp | 29 +++++++++++++++++++++++++---- lib/permutation.cpp | 8 ++++---- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/include/codecrypt.h b/include/codecrypt.h index 6669479..48dcba8 100644 --- a/include/codecrypt.h +++ b/include/codecrypt.h @@ -74,7 +74,9 @@ public: void unit (uint); bool get_left_square (matrix&); bool strip_left_square (matrix&); + void extend_left_compact (matrix&); bool goppa_systematic_form (matrix&, permutation&, prng&); + bool goppa_systematic_form (matrix&, const permutation&); }; /* @@ -86,12 +88,12 @@ class permutation : public std::vector protected: _ccr_declare_vector_item public: - void compute_inversion (permutation&); + void compute_inversion (permutation&) const; void generate_random (uint n, prng&); - void permute (const bvector&, bvector&); - void permute (const matrix&, matrix&); - void permute_rows (const matrix&, matrix&); + void permute (const bvector&, bvector&) const; + void permute (const matrix&, matrix&) const; + void permute_rows (const matrix&, matrix&) const; }; /* diff --git a/lib/matrix.cpp b/lib/matrix.cpp index f44b695..b8b0e29 100644 --- a/lib/matrix.cpp +++ b/lib/matrix.cpp @@ -127,16 +127,37 @@ bool matrix::strip_left_square (matrix&r) return true; } -bool matrix::goppa_systematic_form (matrix&m, permutation&p, prng&rng) +void matrix::extend_left_compact (matrix&r) +{ + uint i; + uint h = height(), w = width(); + r.resize (h + w); + for (i = 0; i < h; ++i) { + r[i].resize (h, 0); + r[i][i] = 1; + } + for (i = 0; i < w; ++i) { + r[h+i] = item (i); + } +} + +bool matrix::goppa_systematic_form (matrix&g, permutation&p, prng&rng) +{ + p.generate_random (width(), rng); + return goppa_systematic_form (g, p); +} + +bool matrix::goppa_systematic_form (matrix&g, const permutation&p) { matrix t, sinv, s; - p.generate_random (width(), rng); p.permute (*this, t); t.get_left_square (sinv); if (!sinv.compute_inversion (s) ) return false; //meant to be retried. s.mult (t); - s.strip_left_square (m); - return 0; + s.strip_left_square (t); //matrix pingpong. optimize it. + t.compute_transpose (s); + s.extend_left_compact (g); + return true; } diff --git a/lib/permutation.cpp b/lib/permutation.cpp index 53dd303..253b5ad 100644 --- a/lib/permutation.cpp +++ b/lib/permutation.cpp @@ -3,7 +3,7 @@ using namespace ccr; -void permutation::compute_inversion (permutation&r) +void permutation::compute_inversion (permutation&r) const { r.resize (size(), 0); for (uint i = 0; i < size(); ++i) @@ -27,19 +27,19 @@ void permutation::generate_random (uint size, prng&rng) } } -void permutation::permute (const bvector&a, bvector&r) +void permutation::permute (const bvector&a, bvector&r) const { r.resize (a.size() ); for (uint i = 0; i < size(); ++i) r[item (i) ] = a[i]; } -void permutation::permute (const matrix&a, matrix&r) +void permutation::permute (const matrix&a, matrix&r) const { r.resize (a.size() ); for (uint i = 0; i < size(); ++i) r[item (i) ] = a[i]; } -void permutation::permute_rows (const matrix&a, matrix&r) +void permutation::permute_rows (const matrix&a, matrix&r) const { r.resize (a.size() ); for (uint i = 0; i < a.size(); ++i) permute (a[i], r[i]);