Crypto++
5.6.5
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file. 1 #ifndef CRYPTOPP_GF2N_H
2 #define CRYPTOPP_GF2N_H
30 typedef unsigned int RandomizationParameter;
49 {Decode(encodedPoly, byteCount);}
53 {Decode(encodedPoly, byteCount);}
57 {Randomize(rng, bitcount);}
62 static PolynomialMod2 CRYPTOPP_API Trinomial(
size_t t0,
size_t t1,
size_t t2);
64 static PolynomialMod2 CRYPTOPP_API Pentanomial(
size_t t0,
size_t t1,
size_t t2,
size_t t3,
size_t t4);
84 void Encode(
byte *output,
size_t outputLen)
const;
89 void Decode(
const byte *input,
size_t inputLen);
103 unsigned int BitCount()
const;
105 unsigned int ByteCount()
const;
107 unsigned int WordCount()
const;
110 bool GetBit(
size_t n)
const {
return GetCoefficient(n)!=0;}
115 signed int Degree()
const {
return (
signed int)(BitCount()-1U);}
120 {
return (i/WORD_BITS < reg.size()) ? int(reg[i/WORD_BITS] >> (i % WORD_BITS)) & 1 : 0;}
122 int operator[](
unsigned int i)
const {
return GetCoefficient(i);}
125 bool IsZero()
const {
return !*
this;}
157 void SetBit(
size_t i,
int value = 1);
159 void SetByte(
size_t n,
byte value);
162 void SetCoefficient(
size_t i,
int value) {SetBit(i, value);}
171 bool operator!()
const;
204 unsigned int Parity()
const;
207 bool IsIrreducible()
const;
215 bool IsUnit()
const {
return Equals(One());}
231 friend std::ostream& operator<<(std::ostream& out,
const PolynomialMod2 &a);
241 inline bool operator==(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
242 {
return a.Equals(b);}
244 inline bool operator!=(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
247 inline bool operator> (
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
248 {
return a.Degree() > b.Degree();}
250 inline bool operator>=(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
251 {
return a.Degree() >= b.Degree();}
253 inline bool operator< (
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
254 {
return a.Degree() < b.Degree();}
256 inline bool operator<=(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b)
257 {
return a.Degree() <= b.Degree();}
259 inline CryptoPP::PolynomialMod2 operator&(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.And(b);}
261 inline CryptoPP::PolynomialMod2 operator^(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Xor(b);}
263 inline CryptoPP::PolynomialMod2
operator+(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Plus(b);}
265 inline CryptoPP::PolynomialMod2 operator-(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Minus(b);}
267 inline CryptoPP::PolynomialMod2
operator*(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Times(b);}
269 inline CryptoPP::PolynomialMod2 operator/(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.DividedBy(b);}
271 inline CryptoPP::PolynomialMod2 operator%(
const CryptoPP::PolynomialMod2 &a,
const CryptoPP::PolynomialMod2 &b) {
return a.Modulo(b);}
287 virtual GF2NP * Clone()
const {
return new GF2NP(*
this);}
294 bool Equal(
const Element &a,
const Element &b)
const
295 {
CRYPTOPP_ASSERT(a.Degree() < m_modulus.Degree() && b.Degree() < m_modulus.Degree());
return a.Equals(b);}
300 unsigned int MaxElementBitLength()
const
303 unsigned int MaxElementByteLength()
const
304 {
return (
unsigned int)
BitsToBytes(MaxElementBitLength());}
306 Element SquareRoot(
const Element &a)
const;
308 Element HalfTrace(
const Element &a)
const;
311 Element SolveQuadraticEquation(
const Element &a)
const;
322 GF2NT(
unsigned int t0,
unsigned int t1,
unsigned int t2);
324 GF2NP * Clone()
const {
return new GF2NT(*
this);}
327 const Element&
Multiply(
const Element &a,
const Element &b)
const;
329 const Element&
Square(
const Element &a)
const
330 {
return Reduced(a.Squared());}
335 const Element& Reduced(
const Element &a)
const;
346 GF2NPP(
unsigned int t0,
unsigned int t1,
unsigned int t2,
unsigned int t3,
unsigned int t4)
353 unsigned int t0, t1, t2, t3;
363 template<>
inline void swap(CryptoPP::PolynomialMod2 &a, CryptoPP::PolynomialMod2 &b)
int operator[](unsigned int i) const
return coefficient for x^i
PolynomialMod2 Doubled() const
is always zero since we're working modulo 2
Polynomial with Coefficients in GF(2)
Classes and functions for secure memory allocations.
PolynomialMod2(const byte *encodedPoly, size_t byteCount)
convert from big-endian byte array
unsigned int MinEncodedSize() const
minimum number of bytes to encode this polynomial
const Element & MultiplicativeInverse(const Element &a) const
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
PolynomialMod2(RandomNumberGenerator &rng, size_t bitcount)
create a random polynomial uniformly distributed over all polynomials with degree less than bitcount
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
PolynomialMod2 MultiplicativeInverse() const
return inverse if *this is a unit, otherwise return 0
bool IsUnit(const Element &a) const
Determines whether an element is a unit in the group.
Interface for random number generators.
bool operator>(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
Base class for all exceptions thrown by the library.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Utility functions for the Crypto++ library.
signed int Degree() const
the zero polynomial will return a degree of -1
bool operator<=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
static PolynomialMod2 Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4)
return x^t0 + x^t1 + x^t2 + x^t3 + x^t4
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
const Element & Square(const Element &a) const
Square an element in the group.
int GetCoefficient(size_t i) const
return coefficient for x^i
GF(2^n) with Polynomial Basis.
GF(2^n) with Pentanomial Basis.
Classes and functions for working with ANS.1 objects.
bool IsUnit() const
only 1 is a unit
bool GetBit(size_t n) const
return the n-th bit, n=0 being the least significant bit
unsigned int CoefficientCount() const
degree + 1
PolynomialMod2(BufferedTransformation &encodedPoly, size_t byteCount)
convert from big-endian form stored in a BufferedTransformation
bool Equal(const Element &a, const Element &b) const
Compare two elements for equality.
const Element & Multiply(const Element &a, const Element &b) const
Classes for performing mathematics over different fields.
Crypto++ library namespace.
bool operator>=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
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 inequality.
unsigned int Parity(T value)
Returns the parity of a value.
inline ::Integer operator*(const ::Integer &a, const ::Integer &b)
Abstract base classes that provide a uniform interface to this library.
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
GF(2^n) with Trinomial Basis.