12 #ifndef CRYPTOPP_INTEGER_H 13 #define CRYPTOPP_INTEGER_H 31 #if defined(CRYPTOPP_WORD128_AVAILABLE) 123 explicit Integer(
const char *str);
133 explicit Integer(
const wchar_t *str);
169 static const Integer & CRYPTOPP_API Zero();
173 static const Integer & CRYPTOPP_API One();
177 static const Integer & CRYPTOPP_API Two();
200 static Integer CRYPTOPP_API Power2(
size_t e);
208 size_t MinEncodedSize(
Signedness sign=UNSIGNED)
const;
217 void Encode(byte *output,
size_t outputLen,
Signedness sign=UNSIGNED)
const;
245 size_t OpenPGPEncode(byte *output,
size_t bufferSize)
const;
258 void Decode(
const byte *input,
size_t inputLen,
Signedness sign=UNSIGNED);
270 void BERDecode(
const byte *input,
size_t inputLen);
291 void OpenPGPDecode(
const byte *input,
size_t inputLen);
302 bool IsConvertableToLong()
const;
306 signed long ConvertToLong()
const;
310 unsigned int BitCount()
const;
313 unsigned int ByteCount()
const;
316 unsigned int WordCount()
const;
320 bool GetBit(
size_t i)
const;
326 lword GetBits(
size_t i,
size_t n)
const;
348 bool IsEven()
const {
return GetBit(0) == 0;}
351 bool IsOdd()
const {
return GetBit(0) == 1;}
367 Integer& operator/=(
const Integer& t) {
return *
this = DividedBy(t);}
372 Integer& operator/=(word t) {
return *
this = DividedBy(t);}
416 if (!GenerateRandomNoThrow(rng, params))
422 void SetBit(
size_t n,
bool value=1);
426 void SetByte(
size_t n, byte value);
444 bool operator!()
const;
454 Integer operator++(
int) {
Integer temp = *
this; ++*
this;
return temp;}
456 Integer operator--(
int) {
Integer temp = *
this; --*
this;
return temp;}
466 int Compare(
const Integer& a)
const;
481 Integer DividedBy(word b)
const;
484 word Modulo(word b)
const;
497 Integer Doubled()
const {
return Plus(*
this);}
504 bool IsSquare()
const;
509 Integer MultiplicativeInverse()
const;
514 static void CRYPTOPP_API Divide(word &r,
Integer &q,
const Integer &a, word d);
526 word InverseMod(word n)
const;
535 friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in,
Integer &a);
547 friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out,
const Integer &a);
550 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 559 Integer(word value,
size_t length);
560 int PositiveCompare(
const Integer &t)
const;
565 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 568 friend class HalfMontgomeryRepresentation;
578 inline bool operator==(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)==0;}
580 inline bool operator!=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)!=0;}
582 inline bool operator> (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)> 0;}
584 inline bool operator>=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)>=0;}
586 inline bool operator< (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)< 0;}
588 inline bool operator<=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)<=0;}
590 inline CryptoPP::Integer
operator+(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Plus(b);}
592 inline CryptoPP::Integer operator-(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Minus(b);}
595 inline CryptoPP::Integer
operator*(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.
Times(b);}
597 inline CryptoPP::Integer operator/(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.DividedBy(b);}
600 inline CryptoPP::Integer
operator%(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.
Modulo(b);}
602 inline CryptoPP::Integer operator/(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.DividedBy(b);}
605 inline CryptoPP::word
operator%(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.
Modulo(b);}
611 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
Base class for all exceptions thrown by the library.
bool operator>=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
bool operator>(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
void SetNegative()
Sets the Integer to negative.
bool NotZero() const
Determines if the Integer is non-0.
inline ::Integer operator*(const ::Integer &a, const ::Integer &b)
ByteOrder
Provides the byte ordering.
void SetPositive()
Sets the Integer to positive.
inline ::Integer operator%(const ::Integer &a, const ::Integer &b)
Secure memory block with allocator and cleanup.
Abstract base classes that provide a uniform interface to this library.
Signedness
Used when importing and exporting integers.
bool IsNegative() const
Determines if the Integer is negative.
Ring of congruence classes modulo n.
Interface for random number generators.
bool IsPositive() const
Determines if the Integer is positive.
bool NotNegative() const
Determines if the Integer is non-negative.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Sign
Used internally to represent the integer.
Classes and functions for secure memory allocations.
bool operator!=(const OID &lhs, const OID &rhs)
Compare two OIDs for inequality.
Integer Modulo(const Integer &b) const
Integer Times(const Integer &b) const
a number with no special properties
bool IsZero() const
Determines if the Integer is 0.
Exception thrown when an error is encountered decoding an OpenPGP integer.
Interface for encoding and decoding ASN1 objects.
Performs static intialization of the Integer class.
Multiple precision integer with arithmetic operations.
OID operator+(const OID &lhs, unsigned long rhs)
Append a value to an OID.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
RandomNumberType
Properties of a random integer.
bool IsEven() const
Determines if the Integer is even parity.
Integer & operator*=(const Integer &t)
Exception thrown when division by 0 is encountered.
Exception thrown when a random number cannot be found that satisfies the condition.
Performs modular arithmetic in Montgomery representation for increased speed.
bool NotPositive() const
Determines if the Integer is non-positive.
Crypto++ library namespace.
Integer & operator%=(word t)
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
Integer & operator%=(const Integer &t)
bool operator<=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
bool IsOdd() const
Determines if the Integer is odd parity.
Interface for retrieving values given their names.