diff --git a/src/gf2m.h b/src/gf2m.h index a3af554..5406aa6 100644 --- a/src/gf2m.h +++ b/src/gf2m.h @@ -61,6 +61,18 @@ public: return antilog[ (n - 1 - log[a]) % (n - 1)]; } + inline uint inv_square (uint a) { + if (!a) return 0; + return antilog[ (2 * (n - 1 - log[a]) ) + % (n - 1)]; + } + + inline uint div (uint a, uint b) { + if (! (a && b) ) return 0; + return antilog[ (n - 1 - log[b] + log[a]) + % (n - 1)]; + } + inline uint sq_root (uint a) { if (!a) return 0; uint t = log[a]; diff --git a/src/mce_qd.cpp b/src/mce_qd.cpp index 029669d..0fa56d1 100644 --- a/src/mce_qd.cpp +++ b/src/mce_qd.cpp @@ -411,8 +411,8 @@ int privkey::decrypt (const bvector & in, bvector & out, bvector & errors) synd.clear(); synd.resize (h_size, 0); for (i = 0; i < cipher_size(); ++i) if (in[i]) { - tmp = fld.inv (g.eval (permuted_support[i], fld) ); - tmp = fld.mult (tmp, tmp); //g(Li)^{-2} + tmp = fld.inv_square //g(Li)^{-2} + (g.eval (permuted_support[i], fld) ); synd[0] = fld.add (synd[0], tmp); for (j = 1; j < h_size; ++j) { tmp = fld.mult (tmp, permuted_support[i]); diff --git a/src/polynomial.cpp b/src/polynomial.cpp index 12df833..dedf38c 100644 --- a/src/polynomial.cpp +++ b/src/polynomial.cpp @@ -378,7 +378,7 @@ void polynomial::ext_euclid (polynomial&a_out, polynomial&b_out, A.swap (a); B.swap (b); while ( (j = A.degree() - a.degree() ) >= 0) { - h = fld.mult (A.head(), fld.inv (a.head() ) ); + h = fld.div (A.head(), a.head() ); tmp = a; tmp.shift (j); A.add_mult (tmp, h, fld);