1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-16 11:58:16 +00:00
codecrypt/src/polynomial.h
2016-04-17 15:48:09 +02:00

71 lines
1.9 KiB
C++

/*
* This file is part of Codecrypt.
*
* Copyright (C) 2013-2016 Mirek Kratochvil <exa.exa@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _ccr_polynomial_h_
#define _ccr_polynomial_h_
#include <vector>
#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<uint>
{
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<polynomial>&, gf2m&);
polynomial gcd (polynomial, gf2m&);
void ext_euclid (polynomial&, polynomial&, polynomial&, gf2m&, int);
sencode* serialize();
bool unserialize (sencode*);
};
#endif