Crypto++ 8.9
Free C++ class library of cryptographic schemes
Classes | Typedefs | Functions
integer.h File Reference

Multiple precision integer with arithmetic operations. More...

Go to the source code of this file.

Classes

struct  InitializeInteger
 Performs static initialization of the Integer class. More...
 
class  Integer
 Multiple precision integer with arithmetic operations. More...
 
class  Integer::DivideByZero
 Exception thrown when division by 0 is encountered. More...
 
class  Integer::RandomNumberNotFound
 Exception thrown when a random number cannot be found that satisfies the condition. More...
 
class  Integer::OpenPGPDecodeErr
 Exception thrown when an error is encountered decoding an OpenPGP integer. More...
 

Typedefs

typedef SecBlock< word, AllocatorWithCleanup< word, true > > IntegerSecBlock
 

Functions

bool operator== (const ::Integer &a, const ::Integer &b)
 Comparison.
 
bool operator!= (const ::Integer &a, const ::Integer &b)
 Comparison.
 
bool operator> (const ::Integer &a, const ::Integer &b)
 Comparison.
 
bool operator>= (const ::Integer &a, const ::Integer &b)
 Comparison.
 
bool operator< (const ::Integer &a, const ::Integer &b)
 Comparison.
 
bool operator<= (const ::Integer &a, const ::Integer &b)
 Comparison.
 
inline ::Integer operator+ (const ::Integer &a, const ::Integer &b)
 Addition.
 
inline ::Integer operator- (const ::Integer &a, const ::Integer &b)
 Subtraction.
 
inline ::Integer operator* (const ::Integer &a, const ::Integer &b)
 Multiplication.
 
inline ::Integer operator/ (const ::Integer &a, const ::Integer &b)
 Division.
 
inline ::Integer operator% (const ::Integer &a, const ::Integer &b)
 Remainder.
 
inline ::Integer operator/ (const ::Integer &a, ::word b)
 Division.
 
inline ::word operator% (const ::Integer &a, ::word b)
 Remainder.
 
inline ::Integer operator& (const ::Integer &a, const ::Integer &b)
 Bitwise AND.
 
inline ::Integer operator| (const ::Integer &a, const ::Integer &b)
 Bitwise OR.
 
inline ::Integer operator^ (const ::Integer &a, const ::Integer &b)
 Bitwise XOR.
 
void swap (::Integer &a, ::Integer &b)
 

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.

For details on how the Integer class initializes its function pointers using InitializeInteger and how it creates Integer::Zero(), Integer::One(), and Integer::Two(), then see the comments at the top of integer.cpp.

Since
Crypto++ 1.0

Definition in file integer.h.

Typedef Documentation

◆ IntegerSecBlock

Definition at line 35 of file integer.h.

Function Documentation

◆ operator==()

bool operator== ( const ::Integer & a,
const ::Integer & b )
inline

Comparison.

Definition at line 758 of file integer.h.

◆ operator!=()

bool operator!= ( const ::Integer & a,
const ::Integer & b )
inline

Comparison.

Definition at line 760 of file integer.h.

◆ operator>()

bool operator> ( const ::Integer & a,
const ::Integer & b )
inline

Comparison.

Definition at line 762 of file integer.h.

◆ operator>=()

bool operator>= ( const ::Integer & a,
const ::Integer & b )
inline

Comparison.

Definition at line 764 of file integer.h.

◆ operator<()

bool operator< ( const ::Integer & a,
const ::Integer & b )
inline

Comparison.

Definition at line 766 of file integer.h.

◆ operator<=()

bool operator<= ( const ::Integer & a,
const ::Integer & b )
inline

Comparison.

Definition at line 768 of file integer.h.

◆ operator+()

inline ::Integer operator+ ( const ::Integer & a,
const ::Integer & b )

Addition.

Definition at line 770 of file integer.h.

◆ operator-()

inline ::Integer operator- ( const ::Integer & a,
const ::Integer & b )

Subtraction.

Definition at line 772 of file integer.h.

◆ operator*()

inline ::Integer operator* ( const ::Integer & a,
const ::Integer & b )

Multiplication.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 775 of file integer.h.

◆ operator/() [1/2]

inline ::Integer operator/ ( const ::Integer & a,
const ::Integer & b )

Division.

Definition at line 777 of file integer.h.

◆ operator%() [1/2]

inline ::Integer operator% ( const ::Integer & a,
const ::Integer & b )

Remainder.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 780 of file integer.h.

◆ operator/() [2/2]

inline ::Integer operator/ ( const ::Integer & a,
::word b )

Division.

Definition at line 782 of file integer.h.

◆ operator%() [2/2]

inline ::word operator% ( const ::Integer & a,
::word b )

Remainder.

See also
a_times_b_mod_c() and a_exp_b_mod_c()

Definition at line 785 of file integer.h.

◆ operator&()

inline ::Integer operator& ( const ::Integer & a,
const ::Integer & b )

Bitwise AND.

Parameters
athe first Integer
bthe second Integer
Returns
the result of a & b

operator&() 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++ 6.0

Definition at line 799 of file integer.h.

◆ operator|()

inline ::Integer operator| ( const ::Integer & a,
const ::Integer & b )

Bitwise OR.

Parameters
athe first Integer
bthe second Integer
Returns
the result of a | b

operator|() 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++ 6.0

Definition at line 813 of file integer.h.

◆ operator^()

inline ::Integer operator^ ( const ::Integer & a,
const ::Integer & b )

Bitwise XOR.

Parameters
athe first Integer
bthe second Integer
Returns
the result of a ^ b

operator^() 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++ 6.0

Definition at line 827 of file integer.h.

◆ swap()

void swap ( ::Integer & a,
::Integer & b )
inline

Definition at line 833 of file integer.h.