Crypto++
8.8
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
16 #ifndef CRYPTOPP_INTEGER_H
17 #define CRYPTOPP_INTEGER_H
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);
511 if (!GenerateRandomNoThrow(rng, params))
517 void SetBit(
size_t n,
bool value=1);
521 void SetByte(
size_t n,
byte value);
539 bool operator!()
const;
561 int Compare(
const Integer& a)
const;
639 bool IsSquare()
const;
646 Integer MultiplicativeInverse()
const;
740 int PositiveCompare(
const Integer &t)
const;
745 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
748 friend class HalfMontgomeryRepresentation;
758 inline bool operator==(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)==0;}
760 inline bool operator!=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)!=0;}
762 inline bool operator> (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)> 0;}
764 inline bool operator>=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)>=0;}
766 inline bool operator< (
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)< 0;}
768 inline bool operator<=(
const CryptoPP::Integer& a,
const CryptoPP::Integer& b) {
return a.Compare(b)<=0;}
770 inline CryptoPP::Integer
operator+(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Plus(b);}
772 inline CryptoPP::Integer
operator-(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Minus(b);}
775 inline CryptoPP::Integer
operator*(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Times(b);}
777 inline CryptoPP::Integer
operator/(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.DividedBy(b);}
780 inline CryptoPP::Integer
operator%(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Modulo(b);}
799 inline CryptoPP::Integer
operator&(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.And(b);}
813 inline CryptoPP::Integer
operator|(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Or(b);}
827 inline CryptoPP::Integer
operator^(
const CryptoPP::Integer &a,
const CryptoPP::Integer &b) {
return a.Xor(b);}
833 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
inline ::Integer operator|(const ::Integer &a, const ::Integer &b)
Bitwise OR.
Integer & operator*=(const Integer &t)
Multiplication Assignment.
Integer operator>>(size_t n) const
Right-shift.
void swap(::SecBlock< T, A > &a, ::SecBlock< T, A > &b)
Swap two SecBlocks.
bool NotZero() const
Determines if the Integer is non-0.
void SetPositive()
Sets the Integer to positive.
Integer Squared() const
Multiply this integer by itself.
@ BIG_ENDIAN_ORDER
byte order is big-endian
Interface for encoding and decoding ASN1 objects.
Integer & operator/=(const Integer &t)
Division Assignment.
Classes and functions for secure memory allocations.
Ring of congruence classes modulo n.
inline ::Integer operator%(const ::Integer &a, const ::Integer &b)
Remainder.
@ ANY
a number with no special properties
inline ::Integer operator-(const ::Integer &a, const ::Integer &b)
Subtraction.
@ UNSIGNED
an unsigned value
Integer operator++(int)
Post-increment.
bool IsEven() const
Determines if the Integer is even parity.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
Integer Doubled() const
Add this integer to itself.
bool IsZero() const
Determines if the Integer is 0.
inline ::Integer operator&(const ::Integer &a, const ::Integer &b)
Bitwise AND.
bool operator==(const ::Integer &a, const ::Integer &b)
Comparison.
inline ::Integer operator+(const ::Integer &a, const ::Integer &b)
Addition.
RandomNumberType
Properties of a random integer.
Interface for random number generators.
Integer operator--(int)
Post-decrement.
bool operator!=(const ::Integer &a, const ::Integer &b)
Comparison.
Integer operator+() const
Addition.
bool operator<=(const ::Integer &a, const ::Integer &b)
Comparison.
Base class for all exceptions thrown by the library.
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
Exception thrown when a random number cannot be found that satisfies the condition.
word64 word
Full word used for multiprecision integer arithmetic.
Integer & operator%=(word t)
Remainder Assignment.
bool IsOdd() const
Determines if the Integer is odd parity.
Signedness
Used when importing and exporting integers.
bool NotPositive() const
Determines if the Integer is non-positive.
ByteOrder
Provides the byte ordering.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random number.
Integer operator<<(size_t n) const
Left-shift.
bool NotNegative() const
Determines if the Integer is non-negative.
std::ostream & operator<<(std::ostream &out, const OID &oid)
Print a OID value.
void SetNegative()
Sets the Integer to negative.
word64 lword
Large word type.
Sign
Used internally to represent the integer.
bool IsPositive() const
Determines if the Integer is positive.
Exception thrown when division by 0 is encountered.
Performs static initialization of the Integer class.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
inline ::Integer operator^(const ::Integer &a, const ::Integer &b)
Bitwise XOR.
Exception thrown when an error is encountered decoding an OpenPGP integer.
Crypto++ library namespace.
Integer & operator%=(const Integer &t)
Remainder Assignment.
bool operator>(const ::Integer &a, const ::Integer &b)
Comparison.
#define CRYPTOPP_API
Win32 calling convention.
bool IsNegative() const
Determines if the Integer is negative.
Integer & operator/=(word t)
Division Assignment.
bool operator<(const ::Integer &a, const ::Integer &b)
Comparison.
Secure memory block with allocator and cleanup.
inline ::Integer operator*(const ::Integer &a, const ::Integer &b)
Multiplication.
Performs modular arithmetic in Montgomery representation for increased speed.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
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.
Abstract base classes that provide a uniform interface to this library.
Multiple precision integer with arithmetic operations.