/* * This file is part of Codecrypt. * * Copyright (C) 2013-2016 Mirek Kratochvil * * Codecrypt is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at * your option) any later version. * * Codecrypt is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Codecrypt. If not, see . */ #ifndef _ccr_polynomial_h_ #define _ccr_polynomial_h_ #include #include "types.h" #include "sencode.h" #include "vector_item.h" /* * polynomial over GF(2^m) is effectively a vector with a_n binary values * with some added operations. */ class matrix; class gf2m; class prng; class polynomial : public std::vector { protected: _ccr_declare_vector_item public: void strip(); int degree() const; bool zero() const; bool one() const; void shift (uint); uint eval (uint, gf2m&) const; uint head() { int t; if ( (t = degree()) >= 0) return item (t); else return 0; } void add (const polynomial&, gf2m&); void mult (const polynomial&, gf2m&); void add_mult (const polynomial&, uint mult, gf2m&); void mod (const polynomial&, gf2m&); void div (polynomial&, polynomial&, gf2m&); void divmod (polynomial&, polynomial&, polynomial&, gf2m&); void square (gf2m&); void inv (polynomial&, gf2m&); void sqrt (std::vector&, gf2m&); polynomial gcd (polynomial, gf2m&); void ext_euclid (polynomial&, polynomial&, polynomial&, gf2m&, int); sencode* serialize(); bool unserialize (sencode*); }; #endif