16#ifndef CRYPTOPP_INTEGER_H
17#define CRYPTOPP_INTEGER_H
25NAMESPACE_BEGIN(CryptoPP)
118 Integer(Sign sign, word highWord, word lowWord);
171 static const Integer & CRYPTOPP_API Zero();
175 static const Integer & CRYPTOPP_API One();
179 static const Integer & CRYPTOPP_API Two();
202 static Integer CRYPTOPP_API Power2(
size_t e);
210 size_t MinEncodedSize(Signedness sign=UNSIGNED)
const;
219 void Encode(
byte *output,
size_t outputLen, Signedness sign=UNSIGNED)
const;
247 size_t OpenPGPEncode(
byte *output,
size_t bufferSize)
const;
260 void Decode(
const byte *input,
size_t inputLen, Signedness sign=UNSIGNED);
272 void BERDecode(
const byte *input,
size_t inputLen);
293 void OpenPGPDecode(
const byte *input,
size_t inputLen);
304 bool IsConvertableToLong()
const;
308 signed long ConvertToLong()
const;
313 unsigned int BitCount()
const;
317 unsigned int ByteCount()
const;
321 unsigned int WordCount()
const;
325 bool GetBit(
size_t i)
const;
331 lword GetBits(
size_t i,
size_t n)
const;
353 bool IsEven()
const {
return GetBit(0) == 0;}
356 bool IsOdd()
const {
return GetBit(0) == 1;}
400 Integer& operator<<=(
size_t n);
404 Integer& operator>>=(
size_t n);
510 if (!GenerateRandomNoThrow(rng, params))
516 void SetBit(
size_t n,
bool value=1);
520 void SetByte(
size_t n,
byte value);
538 bool operator!()
const;
560 int Compare(
const Integer& a)
const;
575 Integer DividedBy(word b)
const;
578 word Modulo(word b)
const;
638 bool IsSquare()
const;
645 Integer MultiplicativeInverse()
const;
662 static void CRYPTOPP_API Divide(word &r,
Integer &q,
const Integer &a, word d);
694 word InverseMod(word n)
const;
703 friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in,
Integer &a);
715 friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out,
const Integer &a);
738 Integer(word value,
size_t length);
739 int PositiveCompare(
const Integer &t)
const;
744#ifndef CRYPTOPP_DOXYGEN_PROCESSING
747 friend class HalfMontgomeryRepresentation;
757inline bool operator==(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)==0;}
759inline bool operator!=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)!=0;}
761inline bool operator> (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)> 0;}
763inline bool operator>=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)>=0;}
765inline bool operator< (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)< 0;}
767inline bool operator<=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)<=0;}
769inline CryptoPP::Integer
operator+(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Plus(b);}
771inline CryptoPP::Integer
operator-(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Minus(b);}
774inline CryptoPP::Integer
operator*(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Times(b);}
776inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.DividedBy(b);}
779inline CryptoPP::Integer
operator%(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Modulo(b);}
781inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.DividedBy(b);}
784inline CryptoPP::word
operator%(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.Modulo(b);}
798inline CryptoPP::Integer
operator&(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.And(b);}
812inline CryptoPP::Integer
operator|(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Or(b);}
826inline CryptoPP::Integer
operator^(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Xor(b);}
832inline 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.
Integer & operator/=(const Integer &t)
Division Assignment.
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 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)
Remainder Assignment.
Integer Squared() const
Multiply this integer by itself.
bool NotPositive() const
Determines if the Integer is non-positive.
Integer & operator/=(word t)
Division Assignment.
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
Integer & operator*=(const Integer &t)
Multiplication Assignment.
Signedness
Used when importing and exporting integers.
@ UNSIGNED
an unsigned value
Integer operator<<(size_t n) const
Left-shift.
Integer & operator%=(const Integer &t)
Remainder Assignment.
bool IsZero() const
Determines if the Integer is 0.
bool IsNegative() const
Determines if the Integer is negative.
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.
word64 lword
Large word type.
Abstract base classes that provide a uniform interface to this library.
ByteOrder
Provides the byte ordering.
@ BIG_ENDIAN_ORDER
byte order is big-endian
CryptoPP::Integer operator*(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Multiplication.
CryptoPP::Integer operator^(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Bitwise XOR.
bool operator<(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Comparison.
bool operator!=(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Comparison.
CryptoPP::Integer operator-(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Subtraction.
CryptoPP::Integer operator%(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Remainder.
bool operator<=(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Comparison.
CryptoPP::Integer operator|(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Bitwise OR.
CryptoPP::Integer operator/(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Division.
CryptoPP::Integer operator&(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Bitwise AND.
bool operator>=(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Comparison.
bool operator==(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Comparison.
CryptoPP::Integer operator+(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Addition.
bool operator>(const CryptoPP::Integer &a, const CryptoPP::Integer &b)
Comparison.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
Classes and functions for secure memory allocations.
Performs static initialization of the Integer class.