6 #ifndef CRYPTOPP_GF2N_H 7 #define CRYPTOPP_GF2N_H 41 PolynomialMod2(
const PolynomialMod2& t);
51 {Decode(encodedPoly, byteCount);}
55 {Decode(encodedPoly, byteCount);}
60 {Randomize(rng, bitcount);}
67 static PolynomialMod2
CRYPTOPP_API Trinomial(
size_t t0,
size_t t1,
size_t t2);
70 static PolynomialMod2
CRYPTOPP_API Pentanomial(
size_t t0,
size_t t1,
size_t t2,
size_t t3,
size_t t4);
92 void Encode(
byte *output,
size_t outputLen)
const;
97 void Decode(
const byte *input,
size_t inputLen);
110 unsigned int BitCount()
const;
113 unsigned int ByteCount()
const;
115 unsigned int WordCount()
const;
118 bool GetBit(
size_t n)
const {
return GetCoefficient(n)!=0;}
123 signed int Degree()
const {
return (
signed int)(BitCount()-1U);}
130 int operator[](
unsigned int i)
const {
return GetCoefficient(i);}
135 bool Equals(
const PolynomialMod2 &rhs)
const;
140 PolynomialMod2& operator=(
const PolynomialMod2& t);
143 PolynomialMod2& operator&=(
const PolynomialMod2& t);
145 PolynomialMod2& operator^=(
const PolynomialMod2& t);
147 PolynomialMod2&
operator+=(
const PolynomialMod2& t) {
return *
this ^= t;}
149 PolynomialMod2&
operator-=(
const PolynomialMod2& t) {
return *
this ^= t;}
151 PolynomialMod2& operator*=(
const PolynomialMod2& t);
153 PolynomialMod2& operator/=(
const PolynomialMod2& t);
155 PolynomialMod2& operator%=(
const PolynomialMod2& t);
157 PolynomialMod2& operator<<=(
unsigned int);
159 PolynomialMod2& operator>>=(
unsigned int);
165 void SetBit(
size_t i,
int value = 1);
167 void SetByte(
size_t n,
byte value);
178 bool operator!()
const;
188 PolynomialMod2 And(
const PolynomialMod2 &
b)
const;
191 PolynomialMod2 Xor(
const PolynomialMod2 &b)
const;
193 PolynomialMod2
Plus(
const PolynomialMod2 &b)
const {
return Xor(b);}
195 PolynomialMod2
Minus(
const PolynomialMod2 &b)
const {
return Xor(b);}
197 PolynomialMod2 Times(
const PolynomialMod2 &b)
const;
199 PolynomialMod2 DividedBy(
const PolynomialMod2 &b)
const;
201 PolynomialMod2 Modulo(
const PolynomialMod2 &b)
const;
204 PolynomialMod2
operator>>(
unsigned int n)
const;
206 PolynomialMod2
operator<<(
unsigned int n)
const;
211 unsigned int Parity()
const;
215 bool IsIrreducible()
const;
218 PolynomialMod2
Doubled()
const {
return Zero();}
220 PolynomialMod2 Squared()
const;
223 bool IsUnit()
const {
return Equals(One());}
228 static PolynomialMod2
CRYPTOPP_API Gcd(
const PolynomialMod2 &
a,
const PolynomialMod2 &n);
230 PolynomialMod2 InverseMod(
const PolynomialMod2 &)
const;
233 static void CRYPTOPP_API Divide(PolynomialMod2 &r, PolynomialMod2 &q,
const PolynomialMod2 &a,
const PolynomialMod2 &
d);
238 friend std::ostream&
operator<<(std::ostream& out,
const PolynomialMod2 &a);
249 inline bool operator==(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b)
250 {
return a.Equals(b);}
252 inline bool operator!=(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b)
255 inline bool operator> (
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b)
256 {
return a.Degree() > b.Degree();}
258 inline bool operator>=(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b)
259 {
return a.Degree() >= b.Degree();}
261 inline bool operator< (
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b)
262 {
return a.Degree() < b.Degree();}
264 inline bool operator<=(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b)
265 {
return a.Degree() <= b.Degree();}
267 inline CryptoPP::PolynomialMod2
operator&(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.And(b);}
269 inline CryptoPP::PolynomialMod2
operator^(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.Xor(b);}
271 inline CryptoPP::PolynomialMod2
operator+(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.Plus(b);}
273 inline CryptoPP::PolynomialMod2
operator-(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.Minus(b);}
275 inline CryptoPP::PolynomialMod2
operator*(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.Times(b);}
277 inline CryptoPP::PolynomialMod2
operator/(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.DividedBy(b);}
279 inline CryptoPP::PolynomialMod2
operator%(
const CryptoPP::PolynomialMod2 &
a,
const CryptoPP::PolynomialMod2 &
b) {
return a.Modulo(b);}
303 {
CRYPTOPP_ASSERT(a.Degree() < m_modulus.Degree() && b.Degree() < m_modulus.Degree());
return a.Equals(b);}
312 {
return (
unsigned int)
BitsToBytes(MaxElementBitLength());}
330 GF2NT(
unsigned int t0,
unsigned int t1,
unsigned int t2);
338 {
return Reduced(a.Squared());}
354 GF2NPP(
unsigned int t0,
unsigned int t1,
unsigned int t2,
unsigned int t3,
unsigned int t4)
355 :
GF2NP(
PolynomialMod2::Pentanomial(t0, t1, t2, t3, t4)), t0(t0), t1(t1), t2(t2), t3(t3) {}
Base class for all exceptions thrown by the library.
void swap(PolynomialMod2 &a)
Utility functions for the Crypto++ library.
PolynomialMod2 Doubled() const
is always zero since we're working modulo 2
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
unsigned int MaxElementByteLength() const
GF(2^n) with Trinomial Basis.
CryptoPP::PolynomialMod2 operator+(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
PolynomialMod2 Plus(const PolynomialMod2 &b) const
int GetCoefficient(size_t i) const
return coefficient for x^i
#define NAMESPACE_BEGIN(x)
#define CRYPTOPP_DLL_TEMPLATE_CLASS
const Element & Square(const Element &a) const
Square an element in the group.
bool Equal(const Element &a, const Element &b) const
Compare two elements for equality.
Abstract base classes that provide a uniform interface to this library.
CryptoPP::PolynomialMod2 operator^(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
signed int Degree() const
the zero polynomial will return a degree of -1
PolynomialMod2 operator+() const
std::hash for asio::adress
Interface for random number generators.
Classes for performing mathematics over different fields.
GF2NPP(unsigned int t0, unsigned int t1, unsigned int t2, unsigned int t3, unsigned int t4)
Polynomial with Coefficients in GF(2)
PolynomialMod2 MultiplicativeInverse() const
return inverse if *this is a unit, otherwise return 0
Excpetion thrown when divide by zero is encountered.
PolynomialMod2(BufferedTransformation &encodedPoly, size_t byteCount)
Construct a PolynomialMod2 from big-endian form stored in a BufferedTransformation.
Classes and functions for secure memory allocations.
PolynomialMod2 & operator+=(const PolynomialMod2 &t)
int operator[](unsigned int i) const
return coefficient for x^i
CryptoPP::PolynomialMod2 operator*(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
bool operator<=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
compares degree
const unsigned int WORD_BITS
bool IsUnit() const
only 1 is a unit
bool operator!=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
CRYPTOPP_DLL GF2NP *CRYPTOPP_API BERDecodeGF2NP(BufferedTransformation &bt)
bool operator==(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
virtual void DEREncode(BufferedTransformation &bt) const
CryptoPP::PolynomialMod2 operator/(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
PolynomialMod2 Minus(const PolynomialMod2 &b) const
EuclideanDomainOf< PolynomialMod2 >::Element Element
CryptoPP::PolynomialMod2 operator%(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
unsigned int RandomizationParameter
void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB)
void SetCoefficient(size_t i, int value)
unsigned int MinEncodedSize() const
minimum number of bytes to encode this polynomial
PolynomialMod2(const byte *encodedPoly, size_t byteCount)
Construct a PolynomialMod2 from big-endian byte array.
unsigned int Parity(T value)
Returns the parity of a value.
bool GetBit(size_t n) const
return the n-th bit, n=0 being the least significant bit
#define CRYPTOPP_ASSERT(exp)
virtual GF2NP * Clone() const
std::ostream & operator<<(std::ostream &_out, bytes const &_e)
Classes and functions for working with ANS.1 objects.
CryptoPP::PolynomialMod2 operator-(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
GF(2^n) with Pentanomial Basis.
NAMESPACE_END void swap(CryptoPP::PolynomialMod2 &a, CryptoPP::PolynomialMod2 &b)
bool IsUnit(const Element &a) const
Determines whether an element is a unit in the group.
bool operator>=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
compares degree
GF(2^n) with Polynomial Basis.
#define CRYPTOPP_UNUSED(x)
void Multiply(word *R, word *T, const word *A, const word *B, size_t N)
bool operator>(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
compares degree
std::istream & operator>>(std::istream &in, Integer &a)
CryptoPP::PolynomialMod2 operator&(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
PolynomialMod2(RandomNumberGenerator &rng, size_t bitcount)
Create a uniformly distributed random polynomial.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
PolynomialMod2 & operator-=(const PolynomialMod2 &t)
unsigned int CoefficientCount() const
degree + 1
bool operator<(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
compares degree
PolynomialMod2 operator-() const
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
unsigned int MaxElementBitLength() const