6 #ifndef CRYPTOPP_IMPORTS 22 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 23 # pragma GCC diagnostic ignored "-Wconversion" 24 # pragma GCC diagnostic ignored "-Wsign-conversion" 53 const size_t nbytes = nbits/8 + 1;
56 buf[0] = (
byte)
Crop(buf[0], nbits % 8);
160 for (
size_t i=inputLen; i > 0; i--)
170 for (
size_t i=outputLen; i > 0; i--)
264 for (
int i=b.
Degree(); i>=0; i--)
275 static const word map[16] = {0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85};
279 for (
unsigned i=0; i<
reg.
size(); i++)
284 result.
reg[2*i] |= map[(
reg[i] >> (j/2)) % 16] << j;
287 result.reg[2*i+1] |= map[(
reg[i] >> (j/2 + WORD_BITS/2)) % 16] << j;
299 int degree = divisor.
Degree();
306 for (
int i=dividend.
Degree(); i>=0; i--)
309 remainder.
reg[0] |= dividend[i];
310 if (remainder[degree])
312 remainder -= divisor;
334 #if defined(CRYPTOPP_DEBUG) 353 *r = (u << 1) | carry;
376 *r = (u << shiftBits) | carry;
385 const size_t carryIndex =
reg.
size();
387 reg[carryIndex] = carry;
394 for (i = (
int)
reg.
size()-1; i>=shiftWords; i--)
395 reg[i] =
reg[i-shiftWords];
422 *r = (u >> shiftBits) | carry;
430 for (i=0; i<
reg.
size()-shiftWords; i++)
431 reg[i] =
reg[i+shiftWords];
453 for (
unsigned i=0; i<
reg.
size(); i++)
454 if (
reg[i])
return false;
462 for (i=0; i<smallerSize; i++)
463 if (
reg[i] != rhs.
reg[i])
return false;
465 for (i=smallerSize; i<
reg.
size(); i++)
466 if (
reg[i] != 0)
return false;
468 for (i=smallerSize; i<rhs.
reg.
size(); i++)
469 if (rhs.
reg[i] != 0)
return false;
477 long f = out.flags() & std::ios::basefield;
499 return out <<
'0' << suffix;
504 static const char upper[]=
"0123456789ABCDEF";
505 static const char lower[]=
"0123456789abcdef";
506 const char*
const vec = (out.flags() & std::ios::uppercase) ? upper : lower;
508 for (i=0; i*bits < a.
BitCount(); i++)
511 for (
int j=0; j<bits; j++)
512 digit |= a[i*bits+j] << j;
519 if (i && (i%block)==0)
523 return out << suffix;
544 for (
int i=1; i<=d/2; i++)
563 for (
unsigned int i=1; i<
m; i++)
572 for (
unsigned int i=1; i<=(
m-1)/2; i++)
588 for (
unsigned int i=1; i<=
m-1; i++)
595 }
while (w.IsZero());
622 size_t bcLen=1, fgLen=
m_modulus.reg.size();
673 if (f[fgLen-1]==0 && g[fgLen-1]==0)
676 if (f[fgLen-1] < g[fgLen-1])
699 const unsigned int shift = t1 + j;
701 temp ^= (shift < WORD_BITS) ? (((temp >> j) & 1) << shift) : 0;
715 b[
t0/WORD_BITS-1] ^= temp;
731 const unsigned int shift = t1 + j;
733 temp ^= (shift < WORD_BITS) ? (((temp >> j) & 1) << shift) : 0;
750 b[
t0/WORD_BITS-1] ^= temp;
762 for (
int i=
m-1; i>=0; i--)
773 XorWords(r.reg.begin(), a.reg, aSize);
809 b[i-(
t0-
t1)/WORD_BITS] ^= temp;
815 word temp = b[i] & ~mask;
824 b[i-(
t0-
t1)/WORD_BITS-1] ^= temp << (WORD_BITS - (
t0-
t1)%WORD_BITS);
829 b[i-(
t0-
t1)/WORD_BITS] ^= temp;
850 ASN1::characteristic_two_field().DEREncode(seq);
853 ASN1::tpBasis().DEREncode(parameters);
862 ASN1::characteristic_two_field().DEREncode(seq);
865 ASN1::ppBasis().DEREncode(parameters);
880 if (
OID(seq) != ASN1::characteristic_two_field())
886 if (oid == ASN1::tpBasis())
892 else if (oid == ASN1::ppBasis())
PolynomialMod2 Squared() const
PolynomialMod2 Modulo(const PolynomialMod2 &b) const
lword RemainingLength() const
bool IsIrreducible() const
check for irreducibility
static const PolynomialMod2 &CRYPTOPP_API Zero()
The Zero polinomial.
Randomness Pool based on AES-256.
void CopyWords(word *r, const word *a, size_t n)
bool SafeConvert(T1 from, T2 &to)
Tests whether a conversion from -> to is safe to perform.
PolynomialMod2 & operator<<=(unsigned int)
void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const
encode value as big-endian octet string
Utility functions for the Crypto++ library.
PolynomialMod2()
Construct the zero polynomial.
const Element & Reduced(const Element &a) const
Restricts the instantiation of a class to one static object without locks.
const Element & MultiplicativeInverse(const Element &a) const
size_t CountWords(const word *X, size_t N)
void CleanNew(size_type newSize)
Change size without preserving contents.
Class file for Randomness Pool.
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
PolynomialMod2 operator<<(unsigned int n) const
size_t DEREncodeUnsigned(BufferedTransformation &out, T w, byte asnTag=INTEGER)
DER Encode unsigned value.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
bool Equals(const PolynomialMod2 &rhs) const
unsigned int MaxElementByteLength() const
PolynomialMod2 Times(const PolynomialMod2 &b) const
size_t BitsToWords(size_t bitCount)
Returns the number of words required for the specified number of bits.
unsigned int BytePrecision(const T &value)
Returns the number of 8-bit bytes or octets required for a value.
const Element & Square(const Element &a) const
void CleanGrow(size_type newSize)
Change size and preserve contents.
#define NAMESPACE_BEGIN(x)
Abstract base classes that provide a uniform interface to this library.
static const PolynomialMod2 &CRYPTOPP_API One()
The One polinomial.
unsigned int ByteCount() const
number of significant bytes = ceiling(BitCount()/8)
signed int Degree() const
the zero polynomial will return a degree of -1
void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag=INTEGER, T minValue=0, T maxValue=T(0xffffffff))
BER Decode unsigned value.
const Element & Multiply(const Element &a, const Element &b) const
Multiplies elements in the group.
size_type size() const
Provides the count of elements in the SecBlock.
Element SolveQuadraticEquation(const Element &a) const
ASN.1 object identifiers for algorthms and schemes.
void Randomize(RandomNumberGenerator &rng, size_t bitcount)
Classes for automatic resource management.
Library configuration file.
const Element & Mod(const Element &a, const Element &b) const
Performs a modular reduction in the ring.
Interface for random number generators.
size_t BytesToWords(size_t byteCount)
Returns the number of words required for the specified number of bytes.
void DEREncode(BufferedTransformation &bt) const
byte GetByte(size_t n) const
return the n-th byte
static PolynomialMod2 CRYPTOPP_API Monomial(size_t i)
Provides x^i.
Element & Accumulate(Element &a, const Element &b) const
Classes for performing mathematics over different fields.
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.
unsigned int BitCount() const
number of significant bits = Degree() + 1
static PolynomialMod2 CRYPTOPP_API Gcd(const PolynomialMod2 &a, const PolynomialMod2 &n)
greatest common divisor
Copy input to a memory buffer.
void DEREncodeElement(BufferedTransformation &out, const Element &a) const
void ShiftWordsLeftByWords(word *r, size_t n, size_t shiftWords)
const Element & Add(const Element &a, const Element &b) const
const unsigned int WORD_BITS
bool IsUnit() const
only 1 is a unit
PolynomialMod2 & operator=(const PolynomialMod2 &t)
PolynomialMod2 DividedBy(const PolynomialMod2 &b) const
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
EuclideanDomainOf< PolynomialMod2 >::Element Element
const Element & Multiply(const Element &a, const Element &b) const
bool IsDefiniteLength() const
GF2NP(const PolynomialMod2 &modulus)
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
void Encode(byte *output, size_t outputLen) const
encode in big-endian format
const Element & MultiplicativeInverse(const Element &a) const
Calculate the multiplicative inverse of an element in the group.
void SetWords(word *r, word a, size_t n)
PolynomialMod2 & operator^=(const PolynomialMod2 &t)
GF2NT(unsigned int t0, unsigned int t1, unsigned int t2)
Classes and functions for schemes over GF(2^n)
void ShiftWordsRightByWords(word *r, size_t n, size_t shiftWords)
unsigned int Parity(T value)
Returns the parity of a value.
const unsigned int WORD_SIZE
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
String-based implementation of Store interface.
#define CRYPTOPP_ASSERT(exp)
void SetByte(size_t n, byte value)
set the n-th byte to value
unsigned int WordCount() const
number of significant words = ceiling(ByteCount()/sizeof(word))
void BERDecodeError()
Raises a BERDecodeErr.
Classes and functions for working with ANS.1 objects.
PolynomialMod2 InverseMod(const PolynomialMod2 &) const
calculate multiplicative inverse of *this mod n
iterator begin()
Provides an iterator pointing to the first element in the memory block.
void DEREncode(BufferedTransformation &bt) const
Implementation of BufferedTransformation's attachment interface.
GF(2^n) with Pentanomial Basis.
void BERDecodeElement(BufferedTransformation &in, Element &a) const
static PolynomialMod2 CRYPTOPP_API AllOnes(size_t n)
Provides x^(n-1) + ...
void XorWords(word *r, const word *a, const word *b, size_t n)
GF(2^n) with Polynomial Basis.
uint8_t const size_t const size
#define CRYPTOPP_UNUSED(x)
void Decode(const byte *input, size_t inputLen)
void SetBit(size_t i, int value=1)
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))
PolynomialMod2 & operator>>=(unsigned int)
word ShiftWordsRightByBits(word *r, size_t n, unsigned int shiftBits)
std::vector< char * > parameters
void Grow(size_type newSize)
Change size and preserve contents.
PolynomialMod2 And(const PolynomialMod2 &b) const
void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length)
decode value as big-endian octet string
unsigned int Parity() const
sum modulo 2 of all coefficients
static PolynomialMod2 CRYPTOPP_API Trinomial(size_t t0, size_t t1, size_t t2)
Provides x^t0 + x^t1 + x^t2.
Element SquareRoot(const Element &a) const
PolynomialMod2 operator>>(unsigned int n) const
word ShiftWordsLeftByBits(word *r, size_t n, unsigned int shiftBits)
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.
unsigned int BitPrecision(const T &value)
Returns the number of bits required for a value.
GF2NP * BERDecodeGF2NP(BufferedTransformation &bt)
PolynomialMod2 * operator()() const
Element HalfTrace(const Element &a) const
void AndWords(word *r, const word *a, const word *b, size_t n)
PolynomialMod2 Xor(const PolynomialMod2 &b) const