17#if CRYPTOPP_MSC_VERSION
19# pragma warning(disable: 4231 4275)
38 typedef unsigned int RandomizationParameter;
56 {Decode(encodedPoly, byteCount);}
60 {Decode(encodedPoly, byteCount);}
65 {Randomize(rng, bitcount);}
99 void Encode(
byte *output,
size_t outputLen)
const;
104 void Decode(
const byte *input,
size_t inputLen);
125 bool GetBit(
size_t n)
const {
return GetCoefficient(n)!=0;}
130 signed int Degree()
const {
return (
signed int)(BitCount()-1U);}
137 int operator[](
unsigned int i)
const {
return GetCoefficient(i);}
140 bool IsZero()
const {
return !*
this;}
172 void SetBit(
size_t i,
int value = 1);
177 void SetCoefficient(
size_t i,
int value) {SetBit(i, value);}
186 bool operator!()
const;
230 bool IsUnit()
const {
return Equals(One());}
257inline bool operator==(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
260inline bool operator!=(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
263inline bool operator> (
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
264{
return a.Degree() > b.Degree();}
266inline bool operator>=(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
267{
return a.Degree() >= b.Degree();}
269inline bool operator< (
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
270{
return a.Degree() < b.Degree();}
272inline bool operator<=(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
273{
return a.Degree() <= b.Degree();}
275inline CryptoPP::PolynomialMod2 operator&(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.And(b);}
277inline CryptoPP::PolynomialMod2 operator^(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Xor(b);}
279inline CryptoPP::PolynomialMod2
operator+(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Plus(b);}
281inline CryptoPP::PolynomialMod2 operator-(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Minus(b);}
283inline CryptoPP::PolynomialMod2 operator*(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Times(b);}
285inline CryptoPP::PolynomialMod2 operator/(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.DividedBy(b);}
287inline CryptoPP::PolynomialMod2 operator%(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Modulo(b);}
303 virtual GF2NP * Clone()
const {
return new GF2NP(*
this);}
310 bool Equal(
const Element &a,
const Element &b)
const
311 {
CRYPTOPP_ASSERT(a.Degree() < m_modulus.Degree() && b.Degree() < m_modulus.Degree());
return a.Equals(b);}
313 bool IsUnit(
const Element &a)
const
316 unsigned int MaxElementBitLength()
const
319 unsigned int MaxElementByteLength()
const
320 {
return (
unsigned int)
BitsToBytes(MaxElementBitLength());}
322 Element SquareRoot(
const Element &a)
const;
324 Element HalfTrace(
const Element &a)
const;
327 Element SolveQuadraticEquation(
const Element &a)
const;
338 GF2NT(
unsigned int t0,
unsigned int t1,
unsigned int t2);
340 GF2NP * Clone()
const {
return new GF2NT(*
this);}
343 const Element& Multiply(
const Element &a,
const Element &b)
const;
345 const Element&
Square(
const Element &a)
const
346 {
return Reduced(a.Squared());}
348 const Element& MultiplicativeInverse(
const Element &a)
const;
351 const Element& Reduced(
const Element &a)
const;
364 GF2NT233(
unsigned int t0,
unsigned int t1,
unsigned int t2);
368 const Element& Multiply(
const Element &a,
const Element &b)
const;
370 const Element&
Square(
const Element &a)
const;
378 GF2NPP(
unsigned int t0,
unsigned int t1,
unsigned int t2,
unsigned int t3,
unsigned int t4)
385 unsigned int t1, t2, t3;
395template<>
inline void swap(CryptoPP::PolynomialMod2 &a, CryptoPP::PolynomialMod2 &b)
402#if CRYPTOPP_MSC_VERSION
Classes for performing mathematics over different fields.
Classes and functions for working with ANS.1 objects.
std::ostream & operator<<(std::ostream &out, const OID &oid)
Print a OID value.
OID operator+(const OID &lhs, unsigned long rhs)
Append a value to an OID.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
bool operator!=(const OID &lhs, const OID &rhs)
Compare two OIDs for inequality.
Abstract Euclidean domain.
Base class for all exceptions thrown by the library.
GF(2^n) with Polynomial Basis.
GF(2^n) with Pentanomial Basis.
GF(2^n) for b233 and k233.
GF(2^n) with Trinomial Basis.
Exception thrown when divide by zero is encountered.
Polynomial with Coefficients in GF(2)
unsigned int MinEncodedSize() const
minimum number of bytes to encode this polynomial
void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const
encode value as big-endian octet string
PolynomialMod2 MultiplicativeInverse() const
return inverse if *this is a unit, otherwise return 0
void Encode(byte *output, size_t outputLen) const
encode in big-endian format
static PolynomialMod2 Monomial(size_t i)
Provides x^i.
signed int Degree() const
the zero polynomial will return a degree of -1
static const PolynomialMod2 & One()
The One polinomial.
bool IsIrreducible() const
check for irreducibility
PolynomialMod2(RandomNumberGenerator &rng, size_t bitcount)
Create a uniformly distributed random polynomial.
static PolynomialMod2 Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4)
Provides x^t0 + x^t1 + x^t2 + x^t3 + x^t4.
bool IsUnit() const
only 1 is a unit
PolynomialMod2(word value, size_t bitLength=WORD_BITS)
Construct a PolynomialMod2 from a word.
PolynomialMod2 Doubled() const
is always zero since we're working modulo 2
PolynomialMod2(const PolynomialMod2 &t)
Copy construct a PolynomialMod2.
void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length)
decode value as big-endian octet string
byte GetByte(size_t n) const
return the n-th byte
unsigned int BitCount() const
number of significant bits = Degree() + 1
unsigned int WordCount() const
number of significant words = ceiling(ByteCount()/sizeof(word))
static PolynomialMod2 AllOnes(size_t n)
Provides x^(n-1) + ... + x + 1.
static PolynomialMod2 Trinomial(size_t t0, size_t t1, size_t t2)
Provides x^t0 + x^t1 + x^t2.
unsigned int CoefficientCount() const
degree + 1
PolynomialMod2 InverseMod(const PolynomialMod2 &) const
calculate multiplicative inverse of *this mod n
PolynomialMod2(BufferedTransformation &encodedPoly, size_t byteCount)
Construct a PolynomialMod2 from big-endian form stored in a BufferedTransformation.
int operator[](unsigned int i) const
return coefficient for x^i
unsigned int Parity() const
sum modulo 2 of all coefficients
PolynomialMod2()
Construct the zero polynomial.
static const PolynomialMod2 & Zero()
The Zero polinomial.
unsigned int ByteCount() const
number of significant bytes = ceiling(BitCount()/8)
static void Divide(PolynomialMod2 &r, PolynomialMod2 &q, const PolynomialMod2 &a, const PolynomialMod2 &d)
calculate r and q such that (a == d*q + r) && (deg(r) < deg(d))
static PolynomialMod2 Gcd(const PolynomialMod2 &a, const PolynomialMod2 &n)
greatest common divisor
PolynomialMod2(const byte *encodedPoly, size_t byteCount)
Construct a PolynomialMod2 from big-endian byte array.
void SetByte(size_t n, byte value)
set the n-th byte to value
int GetCoefficient(size_t i) const
return coefficient for x^i
bool GetBit(size_t n) const
return the n-th bit, n=0 being the least significant bit
Interface for random number generators.
#define CRYPTOPP_API
Win32 calling convention.
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Instantiate templates in a dynamic library.
word64 word
Full word used for multiprecision integer arithmetic.
const unsigned int WORD_BITS
Size of a platform word in bits.
Abstract base classes that provide a uniform interface to this library.
bool operator>(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
bool operator>=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
bool operator<=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Utility functions for the Crypto++ library.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
Crypto++ library namespace.
Classes and functions for secure memory allocations.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.