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);
453 if (!GenerateRandomNoThrow(rng, params))
454 throw RandomNumberNotFound();
459 void SetBit(
size_t n,
bool value=1);
463 void SetByte(
size_t n, byte value);
481 bool operator!()
const;
503 int Compare(
const Integer& a)
const;
518 Integer DividedBy(word b)
const;
521 word Modulo(word b)
const;
581 bool IsSquare()
const;
586 Integer MultiplicativeInverse()
const;
591 static void CRYPTOPP_API Divide(word &r,
Integer &q,
const Integer &a, word d);
602 word InverseMod(word n)
const;
611 friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in,
Integer &a);
623 friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out,
const Integer &a);
626 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 635 Integer(word value,
size_t length);
636 int PositiveCompare(
const Integer &t)
const;
641 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 644 friend class HalfMontgomeryRepresentation;
654 inline bool operator==(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)==0;}
656 inline bool operator!=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)!=0;}
658 inline bool operator> (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)> 0;}
660 inline bool operator>=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)>=0;}
662 inline bool operator< (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)< 0;}
664 inline bool operator<=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)<=0;}
666 inline CryptoPP::Integer
operator+(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Plus(b);}
668 inline CryptoPP::Integer
operator-(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Minus(b);}
671 inline CryptoPP::Integer
operator*(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Times(b);}
673 inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.DividedBy(b);}
676 inline CryptoPP::Integer
operator%(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Modulo(b);}
678 inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.DividedBy(b);}
681 inline CryptoPP::word
operator%(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.Modulo(b);}
695 inline CryptoPP::Integer
operator&(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.And(b);}
709 inline CryptoPP::Integer
operator|(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Or(b);}
723 inline CryptoPP::Integer
operator^(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Xor(b);}
729 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
Base class for all exceptions thrown by the library.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
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)
Multiplication.
Integer & operator/=(word t)
Division Assignment.
Integer operator--(int)
Post-decrement.
ByteOrder
Provides the byte ordering.
void SetPositive()
Sets the Integer to positive.
inline ::Integer operator%(const ::Integer &a, const ::Integer &b)
Remainder.
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 ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator+(const ::Integer &a, const ::Integer &b)
Addition.
Sign
Used internally to represent the integer.
Classes and functions for secure memory allocations.
Integer & operator/=(const Integer &t)
Division Assignment.
inline ::Integer operator-(const ::Integer &a, const ::Integer &b)
Subtraction.
a number with no special properties
bool operator!=(const ::Integer &a, const ::Integer &b)
Comparison.
bool operator<=(const ::Integer &a, const ::Integer &b)
Comparison.
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
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 initialization of the Integer class.
Multiple precision integer with arithmetic operations.
inline ::Integer operator &(const ::Integer &a, const ::Integer &b)
Bitwise AND.
RandomNumberType
Properties of a random integer.
bool IsEven() const
Determines if the Integer is even parity.
Integer & operator*=(const Integer &t)
Multiplication Assignment.
bool operator>(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator^(const ::Integer &a, const ::Integer &b)
Bitwise XOR.
Integer operator++(int)
Post-increment.
Exception thrown when division by 0 is encountered.
const NameValuePairs g_nullNameValuePairs
An empty set of name-value pairs.
Integer Squared() const
Multiply this integer by itself.
Exception thrown when a random number cannot be found that satisfies the condition.
Performs modular arithmetic in Montgomery representation for increased speed.
Integer operator<<(size_t n) const
Left-shift.
Integer Doubled() const
Add this integer to itself.
Integer operator>>(size_t n) const
Right-shift.
bool NotPositive() const
Determines if the Integer is non-positive.
Integer operator+() const
Addition.
Crypto++ library namespace.
Integer & operator%=(word t)
Remainder Assignment.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
bool operator<(const ::Integer &a, const ::Integer &b)
Comparison.
Integer & operator%=(const Integer &t)
Remainder Assignment.
inline ::Integer operator|(const ::Integer &a, const ::Integer &b)
Bitwise OR.
bool IsOdd() const
Determines if the Integer is odd parity.
bool operator>=(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator/(const ::Integer &a, const ::Integer &b)
Division.
Interface for retrieving values given their names.