Security Scol plugin
Classes | List of all members
PolynomialMod2 Class Reference

Polynomial with Coefficients in GF(2) More...

#include <gf2n.h>

Classes

class  DivideByZero
 Exception thrown when divide by zero is encountered. More...
 

ENUMS, EXCEPTIONS, and TYPEDEFS

typedef unsigned int RandomizationParameter
 

INPUT/OUTPUT

class GF2NT
 
class GF2NT233
 
std::ostream & operator<< (std::ostream &out, const PolynomialMod2 &a)
 

CREATORS

 PolynomialMod2 ()
 Construct the zero polynomial.
 
 PolynomialMod2 (const PolynomialMod2 &t)
 Copy construct a PolynomialMod2.
 
 PolynomialMod2 (word value, size_t bitLength=WORD_BITS)
 Construct a PolynomialMod2 from a word.
 
 PolynomialMod2 (const byte *encodedPoly, size_t byteCount)
 Construct a PolynomialMod2 from big-endian byte array.
 
 PolynomialMod2 (BufferedTransformation &encodedPoly, size_t byteCount)
 Construct a PolynomialMod2 from big-endian form stored in a BufferedTransformation.
 
 PolynomialMod2 (RandomNumberGenerator &rng, size_t bitcount)
 Create a uniformly distributed random polynomial.
 
static PolynomialMod2 CRYPTOPP_API Monomial (size_t i)
 Provides x^i.
 
static PolynomialMod2 CRYPTOPP_API Trinomial (size_t t0, size_t t1, size_t t2)
 Provides x^t0 + x^t1 + x^t2.
 
static PolynomialMod2 CRYPTOPP_API 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.
 
static PolynomialMod2 CRYPTOPP_API AllOnes (size_t n)
 Provides x^(n-1) + ... + x + 1.
 
static const PolynomialMod2 &CRYPTOPP_API Zero ()
 The Zero polinomial.
 
static const PolynomialMod2 &CRYPTOPP_API One ()
 The One polinomial.
 

ENCODE/DECODE

unsigned int MinEncodedSize () const
 minimum number of bytes to encode this polynomial
 
void Encode (byte *output, size_t outputLen) const
 
void Encode (BufferedTransformation &bt, size_t outputLen) const
 
void Decode (const byte *input, size_t inputLen)
 
void Decode (BufferedTransformation &bt, size_t inputLen)
 
void DEREncodeAsOctetString (BufferedTransformation &bt, size_t length) const
 encode value as big-endian octet string
 
void BERDecodeAsOctetString (BufferedTransformation &bt, size_t length)
 decode value as big-endian octet string
 

ACCESSORS

unsigned int BitCount () const
 number of significant bits = Degree() + 1
 
unsigned int ByteCount () const
 number of significant bytes = ceiling(BitCount()/8)
 
unsigned int WordCount () const
 number of significant words = ceiling(ByteCount()/sizeof(word))
 
bool GetBit (size_t n) const
 return the n-th bit, n=0 being the least significant bit
 
byte GetByte (size_t n) const
 return the n-th byte
 
signed int Degree () const
 the zero polynomial will return a degree of -1
 
unsigned int CoefficientCount () const
 degree + 1
 
int GetCoefficient (size_t i) const
 return coefficient for x^i
 
int operator[] (unsigned int i) const
 return coefficient for x^i
 
bool IsZero () const
 
bool Equals (const PolynomialMod2 &rhs) const
 

MANIPULATORS

PolynomialMod2operator= (const PolynomialMod2 &t)
 
PolynomialMod2operator&= (const PolynomialMod2 &t)
 
PolynomialMod2operator^= (const PolynomialMod2 &t)
 
PolynomialMod2operator+= (const PolynomialMod2 &t)
 
PolynomialMod2operator-= (const PolynomialMod2 &t)
 
PolynomialMod2operator*= (const PolynomialMod2 &t)
 
PolynomialMod2operator/= (const PolynomialMod2 &t)
 
PolynomialMod2operator%= (const PolynomialMod2 &t)
 
PolynomialMod2operator<<= (unsigned int)
 
PolynomialMod2operator>>= (unsigned int)
 
void Randomize (RandomNumberGenerator &rng, size_t bitcount)
 
void SetBit (size_t i, int value=1)
 
void SetByte (size_t n, byte value)
 set the n-th byte to value
 
void SetCoefficient (size_t i, int value)
 
void swap (PolynomialMod2 &a)
 

UNARY OPERATORS

bool operator! () const
 
PolynomialMod2 operator+ () const
 
PolynomialMod2 operator- () const
 

BINARY OPERATORS

PolynomialMod2 And (const PolynomialMod2 &b) const
 
PolynomialMod2 Xor (const PolynomialMod2 &b) const
 
PolynomialMod2 Plus (const PolynomialMod2 &b) const
 
PolynomialMod2 Minus (const PolynomialMod2 &b) const
 
PolynomialMod2 Times (const PolynomialMod2 &b) const
 
PolynomialMod2 DividedBy (const PolynomialMod2 &b) const
 
PolynomialMod2 Modulo (const PolynomialMod2 &b) const
 
PolynomialMod2 operator>> (unsigned int n) const
 
PolynomialMod2 operator<< (unsigned int n) const
 

OTHER ARITHMETIC FUNCTIONS

unsigned int Parity () const
 sum modulo 2 of all coefficients
 
bool IsIrreducible () const
 check for irreducibility
 
PolynomialMod2 Doubled () const
 is always zero since we're working modulo 2
 
PolynomialMod2 Squared () const
 
bool IsUnit () const
 only 1 is a unit
 
PolynomialMod2 MultiplicativeInverse () const
 return inverse if *this is a unit, otherwise return 0
 
PolynomialMod2 InverseMod (const PolynomialMod2 &) const
 calculate multiplicative inverse of *this mod n
 
static PolynomialMod2 CRYPTOPP_API Gcd (const PolynomialMod2 &a, const PolynomialMod2 &n)
 greatest common divisor
 
static void CRYPTOPP_API 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))
 

Detailed Description

Polynomial with Coefficients in GF(2)

Definition at line 26 of file gf2n.h.

Member Typedef Documentation

◆ RandomizationParameter

typedef unsigned int PolynomialMod2::RandomizationParameter

Definition at line 38 of file gf2n.h.

Constructor & Destructor Documentation

◆ PolynomialMod2() [1/6]

ANONYMOUS_NAMESPACE_END PolynomialMod2::PolynomialMod2 ( )

Construct the zero polynomial.

Definition at line 60 of file gf2n.cpp.

◆ PolynomialMod2() [2/6]

PolynomialMod2::PolynomialMod2 ( const PolynomialMod2 t)

Copy construct a PolynomialMod2.

Definition at line 76 of file gf2n.cpp.

◆ PolynomialMod2() [3/6]

PolynomialMod2::PolynomialMod2 ( word  value,
size_t  bitLength = WORD_BITS 
)

Construct a PolynomialMod2 from a word.

value should be encoded with the least significant bit as coefficient to x^0 and most significant bit as coefficient to x^(WORD_BITS-1) bitLength denotes how much memory to allocate initially

Definition at line 64 of file gf2n.cpp.

◆ PolynomialMod2() [4/6]

PolynomialMod2::PolynomialMod2 ( const byte encodedPoly,
size_t  byteCount 
)
inline

Construct a PolynomialMod2 from big-endian byte array.

Definition at line 55 of file gf2n.h.

◆ PolynomialMod2() [5/6]

PolynomialMod2::PolynomialMod2 ( BufferedTransformation encodedPoly,
size_t  byteCount 
)
inline

Construct a PolynomialMod2 from big-endian form stored in a BufferedTransformation.

Definition at line 59 of file gf2n.h.

◆ PolynomialMod2() [6/6]

PolynomialMod2::PolynomialMod2 ( RandomNumberGenerator rng,
size_t  bitcount 
)
inline

Create a uniformly distributed random polynomial.

Create a random polynomial uniformly distributed over all polynomials with degree less than bitcount

Definition at line 64 of file gf2n.h.

Member Function Documentation

◆ AllOnes()

PolynomialMod2 PolynomialMod2::AllOnes ( size_t  n)
static

Provides x^(n-1) + ... + x + 1.

Returns
x^(n-1) + ... + x + 1

Definition at line 91 of file gf2n.cpp.

◆ And()

PolynomialMod2 PolynomialMod2::And ( const PolynomialMod2 b) const

Definition at line 302 of file gf2n.cpp.

◆ BERDecodeAsOctetString()

void PolynomialMod2::BERDecodeAsOctetString ( BufferedTransformation bt,
size_t  length 
)

decode value as big-endian octet string

Definition at line 230 of file gf2n.cpp.

◆ BitCount()

unsigned int PolynomialMod2::BitCount ( ) const

number of significant bits = Degree() + 1

Definition at line 253 of file gf2n.cpp.

◆ ByteCount()

unsigned int PolynomialMod2::ByteCount ( ) const

number of significant bytes = ceiling(BitCount()/8)

Definition at line 244 of file gf2n.cpp.

◆ CoefficientCount()

unsigned int PolynomialMod2::CoefficientCount ( ) const
inline

degree + 1

Definition at line 130 of file gf2n.h.

◆ Decode() [1/2]

void PolynomialMod2::Decode ( BufferedTransformation bt,
size_t  inputLen 
)

Definition at line 201 of file gf2n.cpp.

◆ Decode() [2/2]

void PolynomialMod2::Decode ( const byte input,
size_t  inputLen 
)

Definition at line 189 of file gf2n.cpp.

◆ Degree()

signed int PolynomialMod2::Degree ( ) const
inline

the zero polynomial will return a degree of -1

Definition at line 128 of file gf2n.h.

◆ DEREncodeAsOctetString()

void PolynomialMod2::DEREncodeAsOctetString ( BufferedTransformation bt,
size_t  length 
) const

encode value as big-endian octet string

Definition at line 223 of file gf2n.cpp.

◆ Divide()

void PolynomialMod2::Divide ( PolynomialMod2 r,
PolynomialMod2 q,
const PolynomialMod2 a,
const PolynomialMod2 d 
)
static

calculate r and q such that (a == d*q + r) && (deg(r) < deg(d))

Definition at line 342 of file gf2n.cpp.

◆ DividedBy()

PolynomialMod2 PolynomialMod2::DividedBy ( const PolynomialMod2 b) const

Definition at line 367 of file gf2n.cpp.

◆ Doubled()

PolynomialMod2 PolynomialMod2::Doubled ( ) const
inline

is always zero since we're working modulo 2

Definition at line 223 of file gf2n.h.

◆ Encode() [1/2]

void PolynomialMod2::Encode ( BufferedTransformation bt,
size_t  outputLen 
) const

Definition at line 217 of file gf2n.cpp.

◆ Encode() [2/2]

void PolynomialMod2::Encode ( byte output,
size_t  outputLen 
) const

encode in big-endian format

if outputLen < MinEncodedSize, the most significant bytes will be dropped if outputLen > MinEncodedSize, the most significant bytes will be padded

Definition at line 195 of file gf2n.cpp.

◆ Equals()

bool PolynomialMod2::Equals ( const PolynomialMod2 rhs) const

Definition at line 507 of file gf2n.cpp.

◆ Gcd()

PolynomialMod2 PolynomialMod2::Gcd ( const PolynomialMod2 a,
const PolynomialMod2 n 
)
static

greatest common divisor

Definition at line 575 of file gf2n.cpp.

◆ GetBit()

bool PolynomialMod2::GetBit ( size_t  n) const
inline

return the n-th bit, n=0 being the least significant bit

Definition at line 123 of file gf2n.h.

◆ GetByte()

byte PolynomialMod2::GetByte ( size_t  n) const

return the n-th byte

Definition at line 114 of file gf2n.cpp.

◆ GetCoefficient()

int PolynomialMod2::GetCoefficient ( size_t  i) const
inline

return coefficient for x^i

Definition at line 132 of file gf2n.h.

◆ InverseMod()

PolynomialMod2 PolynomialMod2::InverseMod ( const PolynomialMod2 modulus) const

calculate multiplicative inverse of *this mod n

Definition at line 580 of file gf2n.cpp.

◆ IsIrreducible()

bool PolynomialMod2::IsIrreducible ( ) const

check for irreducibility

Definition at line 586 of file gf2n.cpp.

◆ IsUnit()

bool PolynomialMod2::IsUnit ( ) const
inline

only 1 is a unit

Definition at line 228 of file gf2n.h.

◆ IsZero()

bool PolynomialMod2::IsZero ( ) const
inline

Definition at line 138 of file gf2n.h.

◆ MinEncodedSize()

unsigned int PolynomialMod2::MinEncodedSize ( ) const
inline

minimum number of bytes to encode this polynomial

MinEncodedSize of 0 is 1

Definition at line 92 of file gf2n.h.

◆ Minus()

PolynomialMod2 PolynomialMod2::Minus ( const PolynomialMod2 b) const
inline

Definition at line 200 of file gf2n.h.

◆ Modulo()

PolynomialMod2 PolynomialMod2::Modulo ( const PolynomialMod2 b) const

Definition at line 374 of file gf2n.cpp.

◆ Monomial()

PolynomialMod2 PolynomialMod2::Monomial ( size_t  i)
static

Provides x^i.

Returns
x^i

Definition at line 129 of file gf2n.cpp.

◆ MultiplicativeInverse()

PolynomialMod2 PolynomialMod2::MultiplicativeInverse ( ) const
inline

return inverse if *this is a unit, otherwise return 0

Definition at line 230 of file gf2n.h.

◆ One()

const PolynomialMod2 & PolynomialMod2::One ( )
static

The One polinomial.

Returns
the one polynomial

Definition at line 177 of file gf2n.cpp.

◆ operator!()

bool PolynomialMod2::operator! ( ) const

Definition at line 500 of file gf2n.cpp.

◆ operator+()

PolynomialMod2 PolynomialMod2::operator+ ( ) const
inline

Definition at line 186 of file gf2n.h.

◆ operator+=()

PolynomialMod2 & PolynomialMod2::operator+= ( const PolynomialMod2 t)
inline

Definition at line 152 of file gf2n.h.

◆ operator-()

PolynomialMod2 PolynomialMod2::operator- ( ) const
inline

Definition at line 188 of file gf2n.h.

◆ operator-=()

PolynomialMod2 & PolynomialMod2::operator-= ( const PolynomialMod2 t)
inline

Definition at line 154 of file gf2n.h.

◆ operator<<()

PolynomialMod2 PolynomialMod2::operator<< ( unsigned int  n) const

Definition at line 488 of file gf2n.cpp.

◆ operator<<=()

PolynomialMod2 & PolynomialMod2::operator<<= ( unsigned int  n)

Definition at line 381 of file gf2n.cpp.

◆ operator=()

PolynomialMod2 & PolynomialMod2::operator= ( const PolynomialMod2 t)

Definition at line 271 of file gf2n.cpp.

◆ operator>>()

PolynomialMod2 PolynomialMod2::operator>> ( unsigned int  n) const

Definition at line 494 of file gf2n.cpp.

◆ operator>>=()

PolynomialMod2 & PolynomialMod2::operator>>= ( unsigned int  n)

Definition at line 452 of file gf2n.cpp.

◆ operator[]()

int PolynomialMod2::operator[] ( unsigned int  i) const
inline

return coefficient for x^i

Definition at line 135 of file gf2n.h.

◆ operator^=()

PolynomialMod2 & PolynomialMod2::operator^= ( const PolynomialMod2 t)

Definition at line 277 of file gf2n.cpp.

◆ Parity()

unsigned int PolynomialMod2::Parity ( ) const

sum modulo 2 of all coefficients

Definition at line 262 of file gf2n.cpp.

◆ Pentanomial()

PolynomialMod2 PolynomialMod2::Pentanomial ( size_t  t0,
size_t  t1,
size_t  t2,
size_t  t3,
size_t  t4 
)
static

Provides x^t0 + x^t1 + x^t2 + x^t3 + x^t4.

Returns
x^t0 + x^t1 + x^t2 + x^t3 + x^t4

Definition at line 145 of file gf2n.cpp.

◆ Plus()

PolynomialMod2 PolynomialMod2::Plus ( const PolynomialMod2 b) const
inline

Definition at line 198 of file gf2n.h.

◆ Randomize()

void PolynomialMod2::Randomize ( RandomNumberGenerator rng,
size_t  bitcount 
)

Definition at line 82 of file gf2n.cpp.

◆ SetBit()

void PolynomialMod2::SetBit ( size_t  i,
int  value = 1 
)

Definition at line 100 of file gf2n.cpp.

◆ SetByte()

void PolynomialMod2::SetByte ( size_t  n,
byte  value 
)

set the n-th byte to value

Definition at line 122 of file gf2n.cpp.

◆ SetCoefficient()

void PolynomialMod2::SetCoefficient ( size_t  i,
int  value 
)
inline

Definition at line 175 of file gf2n.h.

◆ Squared()

PolynomialMod2 PolynomialMod2::Squared ( ) const

Definition at line 322 of file gf2n.cpp.

◆ swap()

void PolynomialMod2::swap ( PolynomialMod2 a)
inline

Definition at line 178 of file gf2n.h.

◆ Times()

PolynomialMod2 PolynomialMod2::Times ( const PolynomialMod2 b) const

Definition at line 309 of file gf2n.cpp.

◆ Trinomial()

PolynomialMod2 PolynomialMod2::Trinomial ( size_t  t0,
size_t  t1,
size_t  t2 
)
static

Provides x^t0 + x^t1 + x^t2.

Returns
x^t0 + x^t1 + x^t2

Definition at line 136 of file gf2n.cpp.

◆ WordCount()

unsigned int PolynomialMod2::WordCount ( ) const

number of significant words = ceiling(ByteCount()/sizeof(word))

Definition at line 239 of file gf2n.cpp.

◆ Xor()

PolynomialMod2 PolynomialMod2::Xor ( const PolynomialMod2 b) const

Definition at line 284 of file gf2n.cpp.

◆ Zero()

const PolynomialMod2 & PolynomialMod2::Zero ( )
static

The Zero polinomial.

Returns
the zero polynomial

Definition at line 165 of file gf2n.cpp.

Friends And Related Symbol Documentation

◆ GF2NT

friend class GF2NT
friend

Definition at line 248 of file gf2n.h.

◆ GF2NT233

friend class GF2NT233
friend

Definition at line 249 of file gf2n.h.

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const PolynomialMod2 a 
)
friend

Definition at line 523 of file gf2n.cpp.


The documentation for this class was generated from the following files: