Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Private Member Functions | Private Attributes | Friends | List of all members
Integer Class Reference

Multiple precision integer with arithmetic operations. More...

#include <integer.h>

Inheritance diagram for Integer:
[legend]
Collaboration diagram for Integer:
[legend]

Classes

class  DivideByZero
 Exception thrown when division by 0 is encountered. More...
 
class  OpenPGPDecodeErr
 Exception thrown when an error is encountered decoding an OpenPGP integer. More...
 
class  RandomNumberNotFound
 Exception thrown when a random number cannot be found that satisfies the condition. More...
 

Private Member Functions

 Integer (word value, size_t length)
 
int PositiveCompare (const Integer &t) const
 
- Private Member Functions inherited from InitializeInteger
 InitializeInteger ()
 

Private Attributes

IntegerSecBlock reg
 
Sign sign
 

Friends

class ModularArithmetic
 
class MontgomeryRepresentation
 
class HalfMontgomeryRepresentation
 
CRYPTOPP_DLL friend Integer CRYPTOPP_API a_times_b_mod_c (const Integer &x, const Integer &y, const Integer &m)
 modular multiplication More...
 
CRYPTOPP_DLL friend Integer CRYPTOPP_API a_exp_b_mod_c (const Integer &x, const Integer &e, const Integer &m)
 modular exponentiation More...
 
void PositiveAdd (Integer &sum, const Integer &a, const Integer &b)
 
void PositiveSubtract (Integer &diff, const Integer &a, const Integer &b)
 
void PositiveMultiply (Integer &product, const Integer &a, const Integer &b)
 
void PositiveDivide (Integer &remainder, Integer &quotient, const Integer &dividend, const Integer &divisor)
 

ENUMS, EXCEPTIONS, and TYPEDEFS

enum  Sign { POSITIVE =0, NEGATIVE =1 }
 Used internally to represent the integer. More...
 
enum  Signedness { UNSIGNED, SIGNED }
 Used when importing and exporting integers. More...
 
enum  RandomNumberType { ANY, PRIME }
 Properties of a random integer. More...
 

CREATORS

 Integer ()
 Creates the zero integer. More...
 
 Integer (const Integer &t)
 copy constructor More...
 
 Integer (signed long value)
 Convert from signed long. More...
 
 Integer (Sign sign, lword value)
 Convert from lword. More...
 
 Integer (Sign sign, word highWord, word lowWord)
 Convert from two words. More...
 
 Integer (const char *str, ByteOrder order=BIG_ENDIAN_ORDER)
 Convert from a C-string. More...
 
 Integer (const wchar_t *str, ByteOrder order=BIG_ENDIAN_ORDER)
 Convert from a wide C-string. More...
 
 Integer (const byte *encodedInteger, size_t byteCount, Signedness sign=UNSIGNED, ByteOrder order=BIG_ENDIAN_ORDER)
 Convert from a big-endian byte array. More...
 
 Integer (BufferedTransformation &bt, size_t byteCount, Signedness sign=UNSIGNED, ByteOrder order=BIG_ENDIAN_ORDER)
 Convert from a big-endian array. More...
 
 Integer (BufferedTransformation &bt)
 Convert from a BER encoded byte array. More...
 
 Integer (RandomNumberGenerator &rng, size_t bitCount)
 Create a random integer. More...
 
 Integer (RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType=ANY, const Integer &equiv=Zero(), const Integer &mod=One())
 Create a random integer of special form. More...
 
static const Integer &CRYPTOPP_API Zero ()
 Integer representing 0. More...
 
static const Integer &CRYPTOPP_API One ()
 Integer representing 1. More...
 
static const Integer &CRYPTOPP_API Two ()
 Integer representing 2. More...
 
static Integer CRYPTOPP_API Power2 (size_t e)
 Exponentiates to a power of 2. More...
 

ENCODE/DECODE

size_t MinEncodedSize (Signedness sign=UNSIGNED) const
 Minimum number of bytes to encode this integer. More...
 
void Encode (byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
 Encode in big-endian format. More...
 
void Encode (BufferedTransformation &bt, size_t outputLen, Signedness sign=UNSIGNED) const
 Encode in big-endian format. More...
 
void DEREncode (BufferedTransformation &bt) const
 Encode in DER format. More...
 
void DEREncodeAsOctetString (BufferedTransformation &bt, size_t length) const
 Encode absolute value as big-endian octet string. More...
 
size_t OpenPGPEncode (byte *output, size_t bufferSize) const
 Encode absolute value in OpenPGP format. More...
 
size_t OpenPGPEncode (BufferedTransformation &bt) const
 Encode absolute value in OpenPGP format. More...
 
void Decode (const byte *input, size_t inputLen, Signedness sign=UNSIGNED)
 Decode from big-endian byte array. More...
 
void Decode (BufferedTransformation &bt, size_t inputLen, Signedness sign=UNSIGNED)
 Decode nonnegative value from big-endian byte array. More...
 
void BERDecode (const byte *input, size_t inputLen)
 Decode from BER format. More...
 
void BERDecode (BufferedTransformation &bt)
 Decode from BER format. More...
 
void BERDecodeAsOctetString (BufferedTransformation &bt, size_t length)
 Decode nonnegative value from big-endian octet string. More...
 
void OpenPGPDecode (const byte *input, size_t inputLen)
 Decode from OpenPGP format. More...
 
void OpenPGPDecode (BufferedTransformation &bt)
 Decode from OpenPGP format. More...
 

ACCESSORS

bool IsConvertableToLong () const
 Determines if the Integer is convertable to Long. More...
 
signed long ConvertToLong () const
 Convert the Integer to Long. More...
 
unsigned int BitCount () const
 Determines the number of bits required to represent the Integer. More...
 
unsigned int ByteCount () const
 Determines the number of bytes required to represent the Integer. More...
 
unsigned int WordCount () const
 Determines the number of words required to represent the Integer. More...
 
bool GetBit (size_t i) const
 Provides the i-th bit of the Integer. More...
 
byte GetByte (size_t i) const
 Provides the i-th byte of the Integer. More...
 
lword GetBits (size_t i, size_t n) const
 Provides the low order bits of the Integer. More...
 
bool IsZero () const
 Determines if the Integer is 0. More...
 
bool NotZero () const
 Determines if the Integer is non-0. More...
 
bool IsNegative () const
 Determines if the Integer is negative. More...
 
bool NotNegative () const
 Determines if the Integer is non-negative. More...
 
bool IsPositive () const
 Determines if the Integer is positive. More...
 
bool NotPositive () const
 Determines if the Integer is non-positive. More...
 
bool IsEven () const
 Determines if the Integer is even parity. More...
 
bool IsOdd () const
 Determines if the Integer is odd parity. More...
 

MANIPULATORS

Integeroperator= (const Integer &t)
 Assignment. More...
 
Integeroperator+= (const Integer &t)
 Addition Assignment. More...
 
Integeroperator-= (const Integer &t)
 Subtraction Assignment. More...
 
Integeroperator*= (const Integer &t)
 Multiplication Assignment. More...
 
Integeroperator/= (const Integer &t)
 Division Assignment. More...
 
Integeroperator%= (const Integer &t)
 Remainder Assignment. More...
 
Integeroperator/= (word t)
 Division Assignment. More...
 
Integeroperator%= (word t)
 Remainder Assignment. More...
 
Integeroperator<<= (size_t n)
 Left-shift Assignment. More...
 
Integeroperator>>= (size_t n)
 Right-shift Assignment. More...
 
Integeroperator&= (const Integer &t)
 Bitwise AND Assignment. More...
 
Integeroperator|= (const Integer &t)
 Bitwise OR Assignment. More...
 
Integeroperator^= (const Integer &t)
 Bitwise XOR Assignment. More...
 
void Randomize (RandomNumberGenerator &rng, size_t bitCount)
 Set this Integer to random integer. More...
 
void Randomize (RandomNumberGenerator &rng, const Integer &min, const Integer &max)
 Set this Integer to random integer. More...
 
bool Randomize (RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv=Zero(), const Integer &mod=One())
 Set this Integer to random integer of special form. More...
 
bool GenerateRandomNoThrow (RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
 
void GenerateRandom (RandomNumberGenerator &rng, const NameValuePairs &params=g_nullNameValuePairs)
 
void SetBit (size_t n, bool value=1)
 Set the n-th bit to value. More...
 
void SetByte (size_t n, byte value)
 Set the n-th byte to value. More...
 
void Negate ()
 Reverse the Sign of the Integer. More...
 
void SetPositive ()
 Sets the Integer to positive. More...
 
void SetNegative ()
 Sets the Integer to negative. More...
 
void swap (Integer &a)
 Swaps this Integer with another Integer. More...
 

UNARY OPERATORS

bool operator! () const
 Negation. More...
 
Integer operator+ () const
 Addition. More...
 
Integer operator- () const
 Subtraction. More...
 
Integeroperator++ ()
 Pre-increment. More...
 
Integeroperator-- ()
 Pre-decrement. More...
 
Integer operator++ (int)
 Post-increment. More...
 
Integer operator-- (int)
 Post-decrement. More...
 

BINARY OPERATORS

int Compare (const Integer &a) const
 Perform signed comparison. More...
 
Integer Plus (const Integer &b) const
 Addition. More...
 
Integer Minus (const Integer &b) const
 Subtraction. More...
 
Integer Times (const Integer &b) const
 Multiplication. More...
 
Integer DividedBy (const Integer &b) const
 Division. More...
 
Integer Modulo (const Integer &b) const
 Remainder. More...
 
Integer DividedBy (word b) const
 Division. More...
 
word Modulo (word b) const
 Remainder. More...
 
Integer And (const Integer &) const
 Bitwise AND. More...
 
Integer Or (const Integer &) const
 Bitwise OR. More...
 
Integer Xor (const Integer &) const
 Bitwise XOR. More...
 
Integer operator>> (size_t n) const
 Right-shift. More...
 
Integer operator<< (size_t n) const
 Left-shift. More...
 

OTHER ARITHMETIC FUNCTIONS

Integer AbsoluteValue () const
 Retrieve the absolute value of this integer. More...
 
Integer Doubled () const
 Add this integer to itself. More...
 
Integer Squared () const
 Multiply this integer by itself. More...
 
Integer SquareRoot () const
 Extract square root. More...
 
bool IsSquare () const
 Determine whether this integer is a perfect square. More...
 
bool IsUnit () const
 is 1 or -1 More...
 
Integer MultiplicativeInverse () const
 return inverse if 1 or -1, otherwise return 0 More...
 
Integer InverseMod (const Integer &n) const
 calculate multiplicative inverse of *this mod n More...
 
word InverseMod (word n) const
 
static void CRYPTOPP_API Divide (Integer &r, Integer &q, const Integer &a, const Integer &d)
 calculate r and q such that (a == d*q + r) && (0 <= r < abs(d)) More...
 
static void CRYPTOPP_API Divide (word &r, Integer &q, const Integer &a, word d)
 use a faster division algorithm when divisor is short More...
 
static void CRYPTOPP_API DivideByPowerOf2 (Integer &r, Integer &q, const Integer &a, unsigned int n)
 returns same result as Divide(r, q, a, Power2(n)), but faster More...
 
static Integer CRYPTOPP_API Gcd (const Integer &a, const Integer &n)
 greatest common divisor More...
 

INPUT/OUTPUT

CRYPTOPP_DLL std::istream &CRYPTOPP_API operator>> (std::istream &in, Integer &a)
 Extraction operator. More...
 
CRYPTOPP_DLL std::ostream &CRYPTOPP_API operator<< (std::ostream &out, const Integer &a)
 Insertion operator. More...
 

Additional Inherited Members

- Public Member Functions inherited from ASN1Object
virtual ~ASN1Object ()
 
virtual void BEREncode (BufferedTransformation &bt) const
 Encode this object into a BufferedTransformation. More...
 

Detailed Description

Multiple precision integer with arithmetic operations.

The Integer class can represent positive and negative integers with absolute value less than (256**sizeof(word))(256**sizeof(int)).

Internally, the library uses a sign magnitude representation, and the class has two data members. The first is a IntegerSecBlock (a SecBlock<word>) and it is used to hold the representation. The second is a Sign (an enumeration), and it is used to track the sign of the Integer.

Since
Crypto++ 1.0

Definition at line 43 of file integer.h.

Member Enumeration Documentation

Properties of a random integer.

Enumerator
ANY 

a number with no special properties

PRIME 

a number which is probabilistically prime

Definition at line 85 of file integer.h.

Used internally to represent the integer.

Sign is used internally to represent the integer. It is also used in a few API functions.

See also
SetPositive(), SetNegative(), Signedness
Enumerator
POSITIVE 

the value is positive or 0

NEGATIVE 

the value is negative

Definition at line 67 of file integer.h.

Used when importing and exporting integers.

Signedness is usually used in API functions.

See also
Sign
Enumerator
UNSIGNED 

an unsigned value

SIGNED 

a signed value

Definition at line 77 of file integer.h.

Constructor & Destructor Documentation

Integer::Integer ( )

Creates the zero integer.

Definition at line 2892 of file integer.cpp.

Here is the caller graph for this function:

Integer::Integer ( const Integer t)

copy constructor

Definition at line 2898 of file integer.cpp.

Here is the call graph for this function:

Integer::Integer ( signed long  value)

Convert from signed long.

Definition at line 2911 of file integer.cpp.

Integer::Integer ( Sign  sign,
lword  value 
)

Convert from lword.

Parameters
signenumeration indicating Sign
valuethe long word

Definition at line 2904 of file integer.cpp.

Integer::Integer ( Sign  sign,
word  highWord,
word  lowWord 
)

Convert from two words.

Parameters
signenumeration indicating Sign
highWordthe high word
lowWordthe low word

Definition at line 2925 of file integer.cpp.

Integer::Integer ( const char *  str,
ByteOrder  order = BIG_ENDIAN_ORDER 
)
explicit

Convert from a C-string.

Parameters
strC-string value
orderthe ByteOrder of the string to be processed

str can be in base 2, 8, 10, or 16. Base is determined by a case insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10.

Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.

Definition at line 3279 of file integer.cpp.

Integer::Integer ( const wchar_t *  str,
ByteOrder  order = BIG_ENDIAN_ORDER 
)
explicit

Convert from a wide C-string.

Parameters
strwide C-string value
orderthe ByteOrder of the string to be processed

str can be in base 2, 8, 10, or 16. Base is determined by a case insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10.

Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.

Definition at line 3285 of file integer.cpp.

Integer::Integer ( const byte encodedInteger,
size_t  byteCount,
Signedness  sign = UNSIGNED,
ByteOrder  order = BIG_ENDIAN_ORDER 
)

Convert from a big-endian byte array.

Parameters
encodedIntegerbig-endian byte array
byteCountlength of the byte array
signenumeration indicating Signedness
orderthe ByteOrder of the array to be processed

Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.

Definition at line 2972 of file integer.cpp.

Here is the call graph for this function:

Integer::Integer ( BufferedTransformation bt,
size_t  byteCount,
Signedness  sign = UNSIGNED,
ByteOrder  order = BIG_ENDIAN_ORDER 
)

Convert from a big-endian array.

Parameters
btBufferedTransformation object with big-endian byte array
byteCountlength of the byte array
signenumeration indicating Signedness
orderthe ByteOrder of the data to be processed

Byte order was added at Crypto++ 5.7 to allow use of little-endian integers with curve25519, Poly1305 and Microsoft CAPI.

Definition at line 2955 of file integer.cpp.

Here is the call graph for this function:

Integer::Integer ( BufferedTransformation bt)
explicit

Convert from a BER encoded byte array.

Parameters
btBufferedTransformation object with BER encoded byte array

Definition at line 2992 of file integer.cpp.

Here is the call graph for this function:

Integer::Integer ( RandomNumberGenerator rng,
size_t  bitCount 
)

Create a random integer.

Parameters
rngRandomNumberGenerator used to generate material
bitCountthe number of bits in the resulting integer

The random integer created is uniformly distributed over [0, 2bitCount].

Definition at line 2997 of file integer.cpp.

Here is the call graph for this function:

Integer::Integer ( RandomNumberGenerator rng,
const Integer min,
const Integer max,
RandomNumberType  rnType = ANY,
const Integer equiv = Zero(),
const Integer mod = One() 
)

Create a random integer of special form.

Parameters
rngRandomNumberGenerator used to generate material
minthe minimum value
maxthe maximum value
rnTypeRandomNumberType to specify the type
equivthe equivalence class based on the parameter mod
modthe modulus used to reduce the equivalence class
Exceptions
RandomNumberNotFoundif the set is empty.

Ideally, the random integer created should be uniformly distributed over {x | min <= x <= max and x is of rnType and x % mod == equiv}. However the actual distribution may not be uniform because sequential search is used to find an appropriate number from a random starting point.

May return (with very small probability) a pseudoprime when a prime is requested and max > lastSmallPrime*lastSmallPrime. lastSmallPrime is declared in nbtheory.h.

Definition at line 3002 of file integer.cpp.

Here is the call graph for this function:

Integer::Integer ( word  value,
size_t  length 
)
private

Definition at line 3135 of file integer.cpp.

Here is the call graph for this function:

Member Function Documentation

Integer Integer::AbsoluteValue ( ) const

Retrieve the absolute value of this integer.

Definition at line 3122 of file integer.cpp.

Here is the caller graph for this function:

Integer Integer::And ( const Integer t) const

Bitwise AND.

Parameters
tthe other Integer
Returns
the result of *this & t

And() performs a bitwise AND on the operands. Missing bits are truncated at the most significant bit positions, so the result is as small as the smaller of the operands.

Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.

Since
Crypto++ 5.7

Definition at line 3738 of file integer.cpp.

Here is the call graph for this function:

void Integer::BERDecode ( const byte input,
size_t  inputLen 
)

Decode from BER format.

Parameters
inputbig-endian byte array
inputLenlength of the byte array

Definition at line 3398 of file integer.cpp.

Here is the caller graph for this function:

void Integer::BERDecode ( BufferedTransformation bt)
virtual

Decode from BER format.

Parameters
btBufferedTransformation object

Implements ASN1Object.

Definition at line 3404 of file integer.cpp.

Here is the call graph for this function:

void Integer::BERDecodeAsOctetString ( BufferedTransformation bt,
size_t  length 
)

Decode nonnegative value from big-endian octet string.

Parameters
btBufferedTransformation object
lengthlength of the byte array

Definition at line 3420 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int Integer::BitCount ( ) const

Determines the number of bits required to represent the Integer.

Returns
number of significant bits = floor(log2(abs(*this))) + 1

Definition at line 3305 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int Integer::ByteCount ( ) const

Determines the number of bytes required to represent the Integer.

Returns
number of significant bytes = ceiling(BitCount()/8)

Definition at line 3296 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int Integer::Compare ( const Integer a) const

Perform signed comparison.

Parameters
athe Integer to comapre
Return values
-1if *this < a
0if *this = a
1if *this > a

Definition at line 4302 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

signed long Integer::ConvertToLong ( ) const

Convert the Integer to Long.

Returns
equivalent signed long if possible, otherwise undefined
See also
IsConvertableToLong()

Definition at line 2946 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::Decode ( const byte input,
size_t  inputLen,
Signedness  sign = UNSIGNED 
)

Decode from big-endian byte array.

Parameters
inputbig-endian byte array
inputLenlength of the byte array
signenumeration indicating Signedness

Definition at line 3314 of file integer.cpp.

Here is the caller graph for this function:

void Integer::Decode ( BufferedTransformation bt,
size_t  inputLen,
Signedness  sign = UNSIGNED 
)

Decode nonnegative value from big-endian byte array.

Parameters
btBufferedTransformation object
inputLenlength of the byte array
signenumeration indicating Signedness
Note
bt.MaxRetrievable() >= inputLen.

Definition at line 3320 of file integer.cpp.

Here is the call graph for this function:

void Integer::DEREncode ( BufferedTransformation bt) const
virtual

Encode in DER format.

Parameters
btBufferedTransformation object

Encodes the Integer using Distinguished Encoding Rules The result is placed into a BufferedTransformation object

Implements ASN1Object.

Definition at line 3391 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::DEREncodeAsOctetString ( BufferedTransformation bt,
size_t  length 
) const

Encode absolute value as big-endian octet string.

Parameters
btBufferedTransformation object
lengththe number of mytes to decode

Definition at line 3413 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::Divide ( Integer r,
Integer q,
const Integer a,
const Integer d 
)
static

calculate r and q such that (a == d*q + r) && (0 <= r < abs(d))

Definition at line 4144 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::Divide ( word r,
Integer q,
const Integer a,
word  d 
)
static

use a faster division algorithm when divisor is short

Definition at line 4204 of file integer.cpp.

Here is the call graph for this function:

void Integer::DivideByPowerOf2 ( Integer r,
Integer q,
const Integer a,
unsigned int  n 
)
static

returns same result as Divide(r, q, a, Power2(n)), but faster

Definition at line 4162 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::DividedBy ( const Integer b) const

Division.

Definition at line 4190 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::DividedBy ( word  b) const

Division.

Definition at line 4238 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::Doubled ( ) const
inline

Add this integer to itself.

Definition at line 567 of file integer.h.

void Integer::Encode ( byte output,
size_t  outputLen,
Signedness  sign = UNSIGNED 
) const

Encode in big-endian format.

Parameters
outputbig-endian byte array
outputLenlength of the byte array
signenumeration indicating Signedness

Unsigned means encode absolute value, signed means encode two's complement if negative.

outputLen can be used to ensure an Integer is encoded to an exact size (rather than a minimum size). An exact size is useful, for example, when encoding to a field element size.

Definition at line 3369 of file integer.cpp.

Here is the caller graph for this function:

void Integer::Encode ( BufferedTransformation bt,
size_t  outputLen,
Signedness  sign = UNSIGNED 
) const

Encode in big-endian format.

Parameters
btBufferedTransformation object
outputLenlength of the encoding
signenumeration indicating Signedness

Unsigned means encode absolute value, signed means encode two's complement if negative.

outputLen can be used to ensure an Integer is encoded to an exact size (rather than a minimum size). An exact size is useful, for example, when encoding to a field element size.

Definition at line 3376 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::Gcd ( const Integer a,
const Integer n 
)
static

greatest common divisor

Definition at line 4365 of file integer.cpp.

Here is the caller graph for this function:

void Integer::GenerateRandom ( RandomNumberGenerator rng,
const NameValuePairs params = g_nullNameValuePairs 
)
inline

Definition at line 445 of file integer.h.

bool Integer::GenerateRandomNoThrow ( RandomNumberGenerator rng,
const NameValuePairs params = g_nullNameValuePairs 
)

Definition at line 3511 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Integer::GetBit ( size_t  i) const

Provides the i-th bit of the Integer.

Returns
the i-th bit, i=0 being the least significant bit

Definition at line 3065 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

lword Integer::GetBits ( size_t  i,
size_t  n 
) const

Provides the low order bits of the Integer.

Returns
n lowest bits of *this >> i

Definition at line 3106 of file integer.cpp.

Here is the call graph for this function:

byte Integer::GetByte ( size_t  i) const

Provides the i-th byte of the Integer.

Returns
the i-th byte

Definition at line 3089 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::InverseMod ( const Integer n) const

calculate multiplicative inverse of *this mod n

Definition at line 4370 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

word Integer::InverseMod ( word  n) const
See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 4395 of file integer.cpp.

bool Integer::IsConvertableToLong ( ) const

Determines if the Integer is convertable to Long.

Returns
true if *this can be represented as a signed long
See also
ConvertToLong()

Definition at line 2932 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Integer::IsEven ( ) const
inline

Determines if the Integer is even parity.

Returns
true if the Integer is even, false otherwise

Definition at line 342 of file integer.h.

Here is the caller graph for this function:

bool Integer::IsNegative ( ) const
inline

Determines if the Integer is negative.

Returns
true if the Integer is negative, false otherwise

Definition at line 330 of file integer.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Integer::IsOdd ( ) const
inline

Determines if the Integer is odd parity.

Returns
true if the Integer is odd, false otherwise

Definition at line 345 of file integer.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Integer::IsPositive ( ) const
inline

Determines if the Integer is positive.

Returns
true if the Integer is positive, false otherwise

Definition at line 336 of file integer.h.

Here is the caller graph for this function:

bool Integer::IsSquare ( ) const

Determine whether this integer is a perfect square.

Definition at line 4338 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Integer::IsUnit ( ) const

is 1 or -1

Definition at line 4344 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Integer::IsZero ( ) const
inline

Determines if the Integer is 0.

Returns
true if the Integer is 0, false otherwise

Definition at line 324 of file integer.h.

Here is the caller graph for this function:

size_t Integer::MinEncodedSize ( Signedness  sign = UNSIGNED) const

Minimum number of bytes to encode this integer.

Parameters
signenumeration indicating Signedness
Note
The MinEncodedSize() of 0 is 1.

Definition at line 3354 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::Minus ( const Integer b) const

Subtraction.

Definition at line 3936 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::Modulo ( const Integer b) const

Remainder.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 4197 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

word Integer::Modulo ( word  b) const

Remainder.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 4246 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::MultiplicativeInverse ( ) const

return inverse if 1 or -1, otherwise return 0

Definition at line 4349 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::Negate ( )

Reverse the Sign of the Integer.

Definition at line 4285 of file integer.cpp.

Here is the caller graph for this function:

bool Integer::NotNegative ( ) const
inline

Determines if the Integer is non-negative.

Returns
true if the Integer is non-negative, false otherwise

Definition at line 333 of file integer.h.

Here is the caller graph for this function:

bool Integer::NotPositive ( ) const
inline

Determines if the Integer is non-positive.

Returns
true if the Integer is non-positive, false otherwise

Definition at line 339 of file integer.h.

bool Integer::NotZero ( ) const
inline

Determines if the Integer is non-0.

Returns
true if the Integer is non-0, false otherwise

Definition at line 327 of file integer.h.

Here is the caller graph for this function:

const Integer & Integer::One ( )
static

Integer representing 1.

Returns
an Integer representing 1

One() avoids calling constructors for frequently used integers

Definition at line 3035 of file integer.cpp.

Here is the caller graph for this function:

void Integer::OpenPGPDecode ( const byte input,
size_t  inputLen 
)

Decode from OpenPGP format.

Parameters
inputbig-endian byte array
inputLenlength of the byte array

Definition at line 3444 of file integer.cpp.

Here is the caller graph for this function:

void Integer::OpenPGPDecode ( BufferedTransformation bt)

Decode from OpenPGP format.

Parameters
btBufferedTransformation object

Definition at line 3450 of file integer.cpp.

Here is the call graph for this function:

size_t Integer::OpenPGPEncode ( byte output,
size_t  bufferSize 
) const

Encode absolute value in OpenPGP format.

Parameters
outputbig-endian byte array
bufferSizelength of the byte array
Returns
length of the output

OpenPGPEncode places result into a BufferedTransformation object and returns the number of bytes used for the encoding

Definition at line 3429 of file integer.cpp.

Here is the caller graph for this function:

size_t Integer::OpenPGPEncode ( BufferedTransformation bt) const

Encode absolute value in OpenPGP format.

Parameters
btBufferedTransformation object
Returns
length of the output

OpenPGPEncode places result into a BufferedTransformation object and returns the number of bytes used for the encoding

Definition at line 3435 of file integer.cpp.

Here is the call graph for this function:

bool Integer::operator! ( ) const

Negation.

Definition at line 3048 of file integer.cpp.

Here is the call graph for this function:

Integer& Integer::operator%= ( const Integer t)
inline

Remainder Assignment.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 364 of file integer.h.

Integer& Integer::operator%= ( word  t)
inline

Remainder Assignment.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 369 of file integer.h.

Integer & Integer::operator&= ( const Integer t)

Bitwise AND Assignment.

Parameters
tthe other Integer
Returns
the result of *this & t

operator&=() performs a bitwise AND on *this. Missing bits are truncated at the most significant bit positions, so the result is as small as the smaller of the operands.

Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.

Since
Crypto++ 5.7

Definition at line 4008 of file integer.cpp.

Here is the call graph for this function:

Integer& Integer::operator*= ( const Integer t)
inline

Multiplication Assignment.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 359 of file integer.h.

Integer Integer::operator+ ( ) const
inline

Addition.

Definition at line 477 of file integer.h.

Here is the call graph for this function:

Integer & Integer::operator++ ( )

Pre-increment.

Definition at line 3696 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::operator++ ( int  )
inline

Post-increment.

Definition at line 485 of file integer.h.

Integer & Integer::operator+= ( const Integer t)

Addition Assignment.

Definition at line 3913 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::operator- ( ) const

Subtraction.

Definition at line 3115 of file integer.cpp.

Here is the call graph for this function:

Integer & Integer::operator-- ( )

Pre-decrement.

Definition at line 3718 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::operator-- ( int  )
inline

Post-decrement.

Definition at line 487 of file integer.h.

Integer & Integer::operator-= ( const Integer t)

Subtraction Assignment.

Definition at line 3959 of file integer.cpp.

Here is the call graph for this function:

Integer& Integer::operator/= ( const Integer t)
inline

Division Assignment.

Definition at line 361 of file integer.h.

Integer& Integer::operator/= ( word  t)
inline

Division Assignment.

Definition at line 366 of file integer.h.

Integer Integer::operator<< ( size_t  n) const
inline

Left-shift.

Definition at line 559 of file integer.h.

Integer & Integer::operator<<= ( size_t  n)

Left-shift Assignment.

Definition at line 3982 of file integer.cpp.

Here is the call graph for this function:

Integer & Integer::operator= ( const Integer t)

Assignment.

Definition at line 3053 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::operator>> ( size_t  n) const
inline

Right-shift.

Definition at line 557 of file integer.h.

Integer & Integer::operator>>= ( size_t  n)

Right-shift Assignment.

Definition at line 3994 of file integer.cpp.

Here is the call graph for this function:

Integer & Integer::operator^= ( const Integer t)

Bitwise XOR Assignment.

Parameters
tthe other Integer
Returns
the result of *this ^ t

operator^=() performs a bitwise XOR on *this. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.

Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.

Since
Crypto++ 5.7

Definition at line 4041 of file integer.cpp.

Here is the call graph for this function:

Integer & Integer::operator|= ( const Integer t)

Bitwise OR Assignment.

Parameters
tthe second Integer
Returns
the result of *this | t

operator|=() performs a bitwise OR on *this. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.

Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.

Since
Crypto++ 5.7

Definition at line 4020 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::Or ( const Integer t) const

Bitwise OR.

Parameters
tthe other Integer
Returns
the result of *this | t

Or() performs a bitwise OR on the operands. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.

Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.

Since
Crypto++ 5.7

Definition at line 3764 of file integer.cpp.

Here is the call graph for this function:

Integer Integer::Plus ( const Integer b) const

Addition.

Definition at line 3890 of file integer.cpp.

Here is the call graph for this function:

int Integer::PositiveCompare ( const Integer t) const
private

Definition at line 4291 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::Power2 ( size_t  e)
static

Exponentiates to a power of 2.

Returns
the Integer 2e
See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 3008 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::Randomize ( RandomNumberGenerator rng,
size_t  bitCount 
)

Set this Integer to random integer.

Parameters
rngRandomNumberGenerator used to generate material
bitCountthe number of bits in the resulting integer

The random integer created is uniformly distributed over [0, 2bitCount].

Definition at line 3458 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::Randomize ( RandomNumberGenerator rng,
const Integer min,
const Integer max 
)

Set this Integer to random integer.

Parameters
rngRandomNumberGenerator used to generate material
minthe minimum value
maxthe maximum value

The random integer created is uniformly distributed over [min, max].

Definition at line 3468 of file integer.cpp.

Here is the call graph for this function:

bool Integer::Randomize ( RandomNumberGenerator rng,
const Integer min,
const Integer max,
RandomNumberType  rnType,
const Integer equiv = Zero(),
const Integer mod = One() 
)

Set this Integer to random integer of special form.

Parameters
rngRandomNumberGenerator used to generate material
minthe minimum value
maxthe maximum value
rnTypeRandomNumberType to specify the type
equivthe equivalence class based on the parameter mod
modthe modulus used to reduce the equivalence class
Exceptions
RandomNumberNotFoundif the set is empty.

Ideally, the random integer created should be uniformly distributed over {x | min <= x <= max and x is of rnType and x % mod == equiv}. However the actual distribution may not be uniform because sequential search is used to find an appropriate number from a random starting point.

May return (with very small probability) a pseudoprime when a prime is requested and max > lastSmallPrime*lastSmallPrime. lastSmallPrime is declared in nbtheory.h.

Definition at line 3485 of file integer.cpp.

Here is the call graph for this function:

void Integer::SetBit ( size_t  n,
bool  value = 1 
)

Set the n-th bit to value.

0-based numbering.

Definition at line 3075 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::SetByte ( size_t  n,
byte  value 
)

Set the n-th byte to value.

0-based numbering.

Definition at line 3099 of file integer.cpp.

Here is the call graph for this function:

void Integer::SetNegative ( )
inline

Sets the Integer to negative.

Definition at line 466 of file integer.h.

Here is the call graph for this function:

void Integer::SetPositive ( )
inline

Sets the Integer to positive.

Definition at line 463 of file integer.h.

Here is the call graph for this function:

Integer Integer::Squared ( ) const
inline

Multiply this integer by itself.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 570 of file integer.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::SquareRoot ( ) const

Extract square root.

if negative return 0, else return floor of square root

Definition at line 4320 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Integer::swap ( Integer a)

Swaps this Integer with another Integer.

Definition at line 3129 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::Times ( const Integer b) const

Multiplication.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 4086 of file integer.cpp.

Here is the call graph for this function:

const Integer & Integer::Two ( )
static

Integer representing 2.

Returns
an Integer representing 2

Two() avoids calling constructors for frequently used integers

Definition at line 3043 of file integer.cpp.

Here is the caller graph for this function:

unsigned int Integer::WordCount ( ) const

Determines the number of words required to represent the Integer.

Returns
number of significant words = ceiling(ByteCount()/sizeof(word))

Definition at line 3291 of file integer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Integer Integer::Xor ( const Integer t) const

Bitwise XOR.

Parameters
tthe other Integer
Returns
the result of *this ^ t

Xor() performs a bitwise XOR on the operands. Missing bits are shifted in at the most significant bit positions, so the result is as large as the larger of the operands.

Internally, Crypto++ uses a sign-magnitude representation. The library does not attempt to interpret bits, and the result is always POSITIVE. If needed, the integer should be converted to a 2's compliment representation before performing the operation.

Since
Crypto++ 5.7

Definition at line 3790 of file integer.cpp.

Here is the call graph for this function:

const Integer & Integer::Zero ( )
static

Integer representing 0.

Returns
an Integer representing 0

Zero() avoids calling constructors for frequently used integers

Definition at line 3027 of file integer.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

CRYPTOPP_DLL friend Integer CRYPTOPP_API a_exp_b_mod_c ( const Integer x,
const Integer e,
const Integer m 
)
friend

modular exponentiation

Definition at line 4359 of file integer.cpp.

CRYPTOPP_DLL friend Integer CRYPTOPP_API a_times_b_mod_c ( const Integer x,
const Integer y,
const Integer m 
)
friend

modular multiplication

Definition at line 4354 of file integer.cpp.

friend class HalfMontgomeryRepresentation
friend

Definition at line 638 of file integer.h.

friend class ModularArithmetic
friend

Definition at line 636 of file integer.h.

friend class MontgomeryRepresentation
friend

Definition at line 637 of file integer.h.

CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<< ( std::ostream &  out,
const Integer a 
)
friend

Insertion operator.

Parameters
outa reference to a std::ostream
aa constant reference to an Integer
Returns
a reference to a std::ostream reference

The output integer responds to std::hex, std::oct, std::hex, std::upper and std::lower. The output includes the suffix h (for hex), . (dot, for dec) and o (for octal). There is currently no way to suppress the suffix.

If you want to print an Integer without the suffix or using an arbitrary base, then use IntToString<Integer>().

See also
IntToString<Integer>

Definition at line 3629 of file integer.cpp.

CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>> ( std::istream &  in,
Integer a 
)
friend

Extraction operator.

Parameters
ina reference to a std::istream
aa reference to an Integer
Returns
a reference to a std::istream reference

Definition at line 3604 of file integer.cpp.

void PositiveAdd ( Integer sum,
const Integer a,
const Integer b 
)
friend

Definition at line 3814 of file integer.cpp.

void PositiveDivide ( Integer remainder,
Integer quotient,
const Integer dividend,
const Integer divisor 
)
friend

Definition at line 4115 of file integer.cpp.

void PositiveMultiply ( Integer product,
const Integer a,
const Integer b 
)
friend

Definition at line 4066 of file integer.cpp.

void PositiveSubtract ( Integer diff,
const Integer a,
const Integer b 
)
friend

Definition at line 3844 of file integer.cpp.

Member Data Documentation

IntegerSecBlock Integer::reg
private

Definition at line 632 of file integer.h.

Sign Integer::sign
private

Definition at line 633 of file integer.h.


The documentation for this class was generated from the following files: