16 #ifndef CRYPTOPP_INTEGER_H
17 #define CRYPTOPP_INTEGER_H
112 Integer(Sign sign, lword value);
118 Integer(Sign sign, word highWord, word lowWord);
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;}
378 Integer& operator<<=(
size_t n);
380 Integer& operator>>=(
size_t n);
486 if (!GenerateRandomNoThrow(rng, params))
492 void SetBit(
size_t n,
bool value=1);
496 void SetByte(
size_t n,
byte value);
514 bool operator!()
const;
536 int Compare(
const Integer& a)
const;
551 Integer DividedBy(word b)
const;
554 word Modulo(word b)
const;
614 bool IsSquare()
const;
621 Integer MultiplicativeInverse()
const;
638 static void CRYPTOPP_API Divide(word &r,
Integer &q,
const Integer &a, word d);
670 word InverseMod(word n)
const;
679 friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in,
Integer &a);
691 friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out,
const Integer &a);
714 Integer(word value,
size_t length);
715 int PositiveCompare(
const Integer &t)
const;
720 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
723 friend class HalfMontgomeryRepresentation;
733 inline bool operator==(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)==0;}
735 inline bool operator!=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)!=0;}
737 inline bool operator> (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)> 0;}
739 inline bool operator>=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)>=0;}
741 inline bool operator< (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)< 0;}
743 inline bool operator<=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)<=0;}
745 inline CryptoPP::Integer
operator+(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Plus(b);}
747 inline CryptoPP::Integer
operator-(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Minus(b);}
750 inline CryptoPP::Integer
operator*(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Times(b);}
752 inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.DividedBy(b);}
755 inline CryptoPP::Integer
operator%(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Modulo(b);}
757 inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.DividedBy(b);}
760 inline CryptoPP::word
operator%(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.Modulo(b);}
774 inline CryptoPP::Integer
operator&(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.And(b);}
788 inline CryptoPP::Integer
operator|(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Or(b);}
802 inline CryptoPP::Integer
operator^(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Xor(b);}
808 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
Interface for encoding and decoding ASN1 objects.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
Base class for all exceptions thrown by the library.
Exception thrown when division by 0 is encountered.
Exception thrown when an error is encountered decoding an OpenPGP integer.
Exception thrown when a random number cannot be found that satisfies the condition.
Multiple precision integer with arithmetic operations.
Integer operator--(int)
Post-decrement.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random number.
bool IsPositive() const
Determines if the Integer is positive.
Integer operator++(int)
Post-increment.
Integer & operator%=(word t)
Remainder Assignment.
Integer & operator%=(const Integer &t)
Remainder Assignment.
Integer Doubled() const
Add this integer to itself.
bool NotZero() const
Determines if the Integer is non-0.
Integer operator>>(size_t n) const
Right-shift.
Integer & operator/=(word t)
Division Assignment.
Integer Squared() const
Multiply this integer by itself.
Integer & operator/=(const Integer &t)
Division Assignment.
bool NotPositive() const
Determines if the Integer is non-positive.
void SetNegative()
Sets the Integer to negative.
bool NotNegative() const
Determines if the Integer is non-negative.
void SetPositive()
Sets the Integer to positive.
Integer operator+() const
Addition.
RandomNumberType
Properties of a random integer.
@ ANY
a number with no special properties
Signedness
Used when importing and exporting integers.
@ UNSIGNED
an unsigned value
Integer operator<<(size_t n) const
Left-shift.
bool IsZero() const
Determines if the Integer is 0.
bool IsNegative() const
Determines if the Integer is negative.
Integer & operator*=(const Integer &t)
Multiplication Assignment.
Sign
Used internally to represent the integer.
bool IsOdd() const
Determines if the Integer is odd parity.
bool IsEven() const
Determines if the Integer is even parity.
Ring of congruence classes modulo n.
Performs modular arithmetic in Montgomery representation for increased speed.
Interface for retrieving values given their names.
Interface for random number generators.
Secure memory block with allocator and cleanup.
Abstract base classes that provide a uniform interface to this library.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
ByteOrder
Provides the byte ordering.
@ BIG_ENDIAN_ORDER
byte order is big-endian
inline ::Integer operator&(const ::Integer &a, const ::Integer &b)
Bitwise AND.
inline ::Integer operator%(const ::Integer &a, const ::Integer &b)
Remainder.
bool operator<(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator-(const ::Integer &a, const ::Integer &b)
Subtraction.
inline ::Integer operator^(const ::Integer &a, const ::Integer &b)
Bitwise XOR.
inline ::Integer operator|(const ::Integer &a, const ::Integer &b)
Bitwise OR.
bool operator>=(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator*(const ::Integer &a, const ::Integer &b)
Multiplication.
bool operator<=(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator/(const ::Integer &a, const ::Integer &b)
Division.
bool operator==(const ::Integer &a, const ::Integer &b)
Comparison.
bool operator>(const ::Integer &a, const ::Integer &b)
Comparison.
bool operator!=(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator+(const ::Integer &a, const ::Integer &b)
Addition.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Performs static initialization of the Integer class.