From ec5b6c36b19d9defc1dbadfe52c3e7470c86f5bc Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 2 Apr 2012 19:16:32 +0200 Subject: [PATCH] polynomial squaring --- include/codecrypt.h | 2 +- lib/polynomial.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/codecrypt.h b/include/codecrypt.h index 4ae962d..66b401e 100644 --- a/include/codecrypt.h +++ b/include/codecrypt.h @@ -100,7 +100,7 @@ public: polynomial gcd (polynomial); bool is_irreducible(); void generate_random_irreducible (uint n, prng&); - vector operator<< (uint); + void compute_mod_squaring_matrix (matrix&); }; /* diff --git a/lib/polynomial.cpp b/lib/polynomial.cpp index 7481a1a..333f21f 100644 --- a/lib/polynomial.cpp +++ b/lib/polynomial.cpp @@ -118,3 +118,20 @@ void polynomial::generate_random_irreducible (uint s, prng & rng) } } +void polynomial::compute_mod_squaring_matrix (matrix&r) +{ + int d = degree(); + if (d < 0) return; + r.resize (d); + polynomial col, t; + for (int i = 0; i < d; ++i) { + col.clear(); + col.resize (i + 1, 0); + col[i] = 1; + t = col; + col.mult (t); + col.mod (*this); + col.resize (d, 0); + r[i] = col; + } +}