1 #ifndef CRYPTOPP_INTEGER_H 2 #define CRYPTOPP_INTEGER_H 106 explicit Integer(
const char *str);
112 explicit Integer(
const wchar_t *str);
139 static const Integer & CRYPTOPP_API Zero();
143 static const Integer & CRYPTOPP_API One();
147 static const Integer & CRYPTOPP_API Two();
170 static Integer CRYPTOPP_API Power2(
size_t e);
178 size_t MinEncodedSize(
Signedness sign=UNSIGNED)
const;
187 void Encode(byte *output,
size_t outputLen,
Signedness sign=UNSIGNED)
const;
215 size_t OpenPGPEncode(byte *output,
size_t bufferSize)
const;
228 void Decode(
const byte *input,
size_t inputLen,
Signedness sign=UNSIGNED);
240 void BERDecode(
const byte *input,
size_t inputLen);
261 void OpenPGPDecode(
const byte *input,
size_t inputLen);
270 bool IsConvertableToLong()
const;
272 signed long ConvertToLong()
const;
275 unsigned int BitCount()
const;
277 unsigned int ByteCount()
const;
279 unsigned int WordCount()
const;
282 bool GetBit(
size_t i)
const;
286 lword GetBits(
size_t i,
size_t n)
const;
289 bool IsZero()
const {
return !*
this;}
291 bool NotZero()
const {
return !IsZero();}
293 bool IsNegative()
const {
return sign == NEGATIVE;}
295 bool NotNegative()
const {
return !IsNegative();}
297 bool IsPositive()
const {
return NotNegative() && NotZero();}
299 bool NotPositive()
const {
return !IsPositive();}
301 bool IsEven()
const {
return GetBit(0) == 0;}
303 bool IsOdd()
const {
return GetBit(0) == 1;}
319 Integer& operator/=(
const Integer& t) {
return *
this = DividedBy(t);}
324 Integer& operator/=(word t) {
return *
this = DividedBy(t);}
368 if (!GenerateRandomNoThrow(rng, params))
374 void SetBit(
size_t n,
bool value=1);
378 void SetByte(
size_t n, byte value);
396 bool operator!()
const;
398 Integer operator+()
const {
return *
this;}
406 Integer operator++(
int) {
Integer temp = *
this; ++*
this;
return temp;}
408 Integer operator--(
int) {
Integer temp = *
this; --*
this;
return temp;}
418 int Compare(
const Integer& a)
const;
433 Integer DividedBy(word b)
const;
436 word Modulo(word b)
const;
449 Integer Doubled()
const {
return Plus(*
this);}
456 bool IsSquare()
const;
461 Integer MultiplicativeInverse()
const;
466 static void CRYPTOPP_API Divide(word &r,
Integer &q,
const Integer &a, word d);
478 word InverseMod(word n)
const;
487 friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in,
Integer &a);
499 friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out,
const Integer &a);
502 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 511 Integer(word value,
size_t length);
512 int PositiveCompare(
const Integer &t)
const;
517 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 520 friend class HalfMontgomeryRepresentation;
530 inline bool operator==(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)==0;}
532 inline bool operator!=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)!=0;}
534 inline bool operator> (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)> 0;}
536 inline bool operator>=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)>=0;}
538 inline bool operator< (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)< 0;}
540 inline bool operator<=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)<=0;}
542 inline CryptoPP::Integer operator+(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Plus(b);}
544 inline CryptoPP::Integer operator-(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Minus(b);}
547 inline CryptoPP::Integer
operator*(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Times(b);}
549 inline CryptoPP::Integer operator/(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.DividedBy(b);}
552 inline CryptoPP::Integer
operator%(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Modulo(b);}
554 inline CryptoPP::Integer operator/(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.DividedBy(b);}
557 inline CryptoPP::word
operator%(
const CryptoPP::Integer &a, CryptoPP::word b) {
return a.Modulo(b);}
563 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
Base class for all exceptions thrown by Crypto++.
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.
inline::Integer operator*(const ::Integer &a, const ::Integer &b)
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.
Ring of congruence classes modulo n.
Interface for random number generators.
Sign
Used internally to represent the integer.
Classes and functions for secure memory allocations.
a number with no special properties
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.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
RandomNumberType
Properties of a random integer.
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
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.
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
Interface for retrieving values given their names.