PIVX Core  5.6.99
P2P Digital Currency
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
CBigNum Class Reference

C++ wrapper for BIGNUM. More...

#include <bignum.h>

Public Member Functions

 CBigNum ()
 C++ wrapper for BIGNUM (Gmp bignum) More...
 
 CBigNum (const CBigNum &b)
 
CBigNumoperator= (const CBigNum &b)
 
 ~CBigNum ()
 
 CBigNum (signed char n)
 
 CBigNum (short n)
 
 CBigNum (int n)
 
 CBigNum (long n)
 
 CBigNum (long long n)
 
 CBigNum (unsigned char n)
 
 CBigNum (unsigned short n)
 
 CBigNum (unsigned int n)
 
 CBigNum (unsigned long n)
 
 CBigNum (unsigned long long n)
 
 CBigNum (uint256 n)
 
 CBigNum (const std::vector< unsigned char > &vch)
 
int bitSize () const
 Returns the size in bits of the underlying bignum. More...
 
void setulong (unsigned long n)
 
unsigned long getulong () const
 
unsigned int getuint () const
 
int getint () const
 
void setint64 (int64_t sn)
 
void setuint64 (uint64_t n)
 
void setuint256 (uint256 n)
 
arith_uint256 getuint256 () const
 
void setvch (const std::vector< unsigned char > &vch)
 
std::vector< unsigned char > getvch () const
 
void SetDec (const std::string &str)
 
void SetHex (const std::string &str)
 
bool SetHexBool (const std::string &str)
 
std::string ToString (int nBase=10) const
 
std::string GetHex () const
 
std::string GetDec () const
 
template<typename Stream >
void Serialize (Stream &s) const
 
template<typename Stream >
void Unserialize (Stream &s)
 
CBigNum pow (const int e) const
 exponentiation with an int. More...
 
CBigNum pow (const CBigNum &e) const
 exponentiation this^e More...
 
CBigNum mul_mod (const CBigNum &b, const CBigNum &m) const
 modular multiplication: (this * b) mod m More...
 
CBigNum pow_mod (const CBigNum &e, const CBigNum &m) const
 modular exponentiation: this^e mod n More...
 
CBigNum inverse (const CBigNum &m) const
 Calculates the inverse of this element mod m. More...
 
CBigNum gcd (const CBigNum &b) const
 Calculates the greatest common divisor (GCD) of two numbers. More...
 
bool isPrime (const int checks=15) const
 Miller-Rabin primality test on this element. More...
 
bool isOne () const
 
bool operator! () const
 
CBigNumoperator+= (const CBigNum &b)
 
CBigNumoperator-= (const CBigNum &b)
 
CBigNumoperator*= (const CBigNum &b)
 
CBigNumoperator/= (const CBigNum &b)
 
CBigNumoperator%= (const CBigNum &b)
 
CBigNumoperator<<= (unsigned int shift)
 
CBigNumoperator>>= (unsigned int shift)
 
CBigNumoperator++ ()
 
const CBigNum operator++ (int)
 
CBigNumoperator-- ()
 
const CBigNum operator-- (int)
 

Static Public Member Functions

static CBigNum randBignum (const CBigNum &range)
 Generates a cryptographically secure random number between zero and range exclusive i.e. More...
 

Private Attributes

mpz_t bn
 

Friends

const CBigNum operator+ (const CBigNum &a, const CBigNum &b)
 
const CBigNum operator- (const CBigNum &a, const CBigNum &b)
 
const CBigNum operator/ (const CBigNum &a, const CBigNum &b)
 
const CBigNum operator% (const CBigNum &a, const CBigNum &b)
 
const CBigNum operator* (const CBigNum &a, const CBigNum &b)
 
const CBigNum operator<< (const CBigNum &a, unsigned int shift)
 
const CBigNum operator- (const CBigNum &a)
 
bool operator== (const CBigNum &a, const CBigNum &b)
 
bool operator!= (const CBigNum &a, const CBigNum &b)
 
bool operator<= (const CBigNum &a, const CBigNum &b)
 
bool operator>= (const CBigNum &a, const CBigNum &b)
 
bool operator< (const CBigNum &a, const CBigNum &b)
 
bool operator> (const CBigNum &a, const CBigNum &b)
 

Detailed Description

C++ wrapper for BIGNUM.

Definition at line 34 of file bignum.h.

Constructor & Destructor Documentation

◆ CBigNum() [1/14]

CBigNum::CBigNum ( )

C++ wrapper for BIGNUM (Gmp bignum)

Definition at line 10 of file bignum.cpp.

Here is the caller graph for this function:

◆ CBigNum() [2/14]

CBigNum::CBigNum ( const CBigNum b)

Definition at line 15 of file bignum.cpp.

◆ ~CBigNum()

CBigNum::~CBigNum ( )

Definition at line 27 of file bignum.cpp.

◆ CBigNum() [3/14]

CBigNum::CBigNum ( signed char  n)

Definition at line 33 of file bignum.cpp.

◆ CBigNum() [4/14]

CBigNum::CBigNum ( short  n)

Definition at line 34 of file bignum.cpp.

◆ CBigNum() [5/14]

CBigNum::CBigNum ( int  n)

Definition at line 35 of file bignum.cpp.

◆ CBigNum() [6/14]

CBigNum::CBigNum ( long  n)

Definition at line 36 of file bignum.cpp.

◆ CBigNum() [7/14]

CBigNum::CBigNum ( long long  n)

Definition at line 37 of file bignum.cpp.

◆ CBigNum() [8/14]

CBigNum::CBigNum ( unsigned char  n)

Definition at line 38 of file bignum.cpp.

◆ CBigNum() [9/14]

CBigNum::CBigNum ( unsigned short  n)

Definition at line 39 of file bignum.cpp.

◆ CBigNum() [10/14]

CBigNum::CBigNum ( unsigned int  n)

Definition at line 40 of file bignum.cpp.

◆ CBigNum() [11/14]

CBigNum::CBigNum ( unsigned long  n)

Definition at line 41 of file bignum.cpp.

◆ CBigNum() [12/14]

CBigNum::CBigNum ( unsigned long long  n)

◆ CBigNum() [13/14]

CBigNum::CBigNum ( uint256  n)
explicit

Definition at line 43 of file bignum.cpp.

Here is the call graph for this function:

◆ CBigNum() [14/14]

CBigNum::CBigNum ( const std::vector< unsigned char > &  vch)
explicit

Definition at line 45 of file bignum.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ bitSize()

int CBigNum::bitSize ( ) const

Returns the size in bits of the underlying bignum.

Returns
the size

Definition at line 78 of file bignum.cpp.

Here is the caller graph for this function:

◆ gcd()

CBigNum CBigNum::gcd ( const CBigNum b) const

Calculates the greatest common divisor (GCD) of two numbers.

Parameters
mthe second element
Returns
the GCD

Definition at line 248 of file bignum.cpp.

Here is the caller graph for this function:

◆ GetDec()

std::string CBigNum::GetDec ( ) const

Definition at line 326 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHex()

std::string CBigNum::GetHex ( ) const

Definition at line 321 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getint()

int CBigNum::getint ( ) const

Definition at line 98 of file bignum.cpp.

Here is the call graph for this function:

◆ getuint()

unsigned int CBigNum::getuint ( ) const

Definition at line 93 of file bignum.cpp.

◆ getuint256()

arith_uint256 CBigNum::getuint256 ( ) const

Definition at line 113 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getulong()

unsigned long CBigNum::getulong ( ) const

Definition at line 88 of file bignum.cpp.

Here is the caller graph for this function:

◆ getvch()

std::vector< unsigned char > CBigNum::getvch ( ) const

Definition at line 139 of file bignum.cpp.

Here is the caller graph for this function:

◆ inverse()

CBigNum CBigNum::inverse ( const CBigNum m) const

Calculates the inverse of this element mod m.

i.e. i such this*i = 1 mod m

Parameters
mthe modu
Returns
the inverse

Definition at line 236 of file bignum.cpp.

◆ isOne()

bool CBigNum::isOne ( ) const

Definition at line 267 of file bignum.cpp.

Here is the caller graph for this function:

◆ isPrime()

bool CBigNum::isPrime ( const int  checks = 15) const

Miller-Rabin primality test on this element.

Parameters
checksoptional, the number of Miller-Rabin tests to run default causes error rate of 2^-80.
Returns
true if prime

Definition at line 261 of file bignum.cpp.

Here is the caller graph for this function:

◆ mul_mod()

CBigNum CBigNum::mul_mod ( const CBigNum b,
const CBigNum m 
) const

modular multiplication: (this * b) mod m

Parameters
boperand
mmodulus

Definition at line 207 of file bignum.cpp.

Here is the caller graph for this function:

◆ operator!()

bool CBigNum::operator! ( ) const

Definition at line 272 of file bignum.cpp.

◆ operator%=()

CBigNum & CBigNum::operator%= ( const CBigNum b)

Definition at line 347 of file bignum.cpp.

◆ operator*=()

CBigNum & CBigNum::operator*= ( const CBigNum b)

Definition at line 289 of file bignum.cpp.

◆ operator++() [1/2]

CBigNum & CBigNum::operator++ ( )

Definition at line 307 of file bignum.cpp.

◆ operator++() [2/2]

const CBigNum CBigNum::operator++ ( int  )

Definition at line 353 of file bignum.cpp.

◆ operator+=()

CBigNum & CBigNum::operator+= ( const CBigNum b)

Definition at line 277 of file bignum.cpp.

◆ operator--() [1/2]

CBigNum & CBigNum::operator-- ( )

Definition at line 314 of file bignum.cpp.

◆ operator--() [2/2]

const CBigNum CBigNum::operator-- ( int  )

Definition at line 361 of file bignum.cpp.

◆ operator-=()

CBigNum & CBigNum::operator-= ( const CBigNum b)

Definition at line 283 of file bignum.cpp.

◆ operator/=()

CBigNum & CBigNum::operator/= ( const CBigNum b)

Definition at line 341 of file bignum.cpp.

◆ operator<<=()

CBigNum & CBigNum::operator<<= ( unsigned int  shift)

Definition at line 295 of file bignum.cpp.

◆ operator=()

CBigNum & CBigNum::operator= ( const CBigNum b)

Definition at line 21 of file bignum.cpp.

◆ operator>>=()

CBigNum & CBigNum::operator>>= ( unsigned int  shift)

Definition at line 301 of file bignum.cpp.

◆ pow() [1/2]

CBigNum CBigNum::pow ( const CBigNum e) const

exponentiation this^e

Parameters
ethe exponent
Returns

Definition at line 194 of file bignum.cpp.

◆ pow() [2/2]

CBigNum CBigNum::pow ( const int  e) const

exponentiation with an int.

this^e

Parameters
ethe exponent as an int
Returns

Definition at line 331 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pow_mod()

CBigNum CBigNum::pow_mod ( const CBigNum e,
const CBigNum m 
) const

modular exponentiation: this^e mod n

Parameters
eexponent
mmodulus

Definition at line 220 of file bignum.cpp.

Here is the caller graph for this function:

◆ randBignum()

CBigNum CBigNum::randBignum ( const CBigNum range)
static

Generates a cryptographically secure random number between zero and range exclusive i.e.

PRNGs use GMP for consistency with seed initialization.

0 < returned number < range

Parameters
rangeThe upper bound on the number.
Returns

Generates a cryptographically secure random number between zero and range-1 (inclusive) i.e. 0 <= returned number < range

Parameters
rangeThe upper bound on the number.
Returns

Definition at line 58 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serialize()

template<typename Stream >
void CBigNum::Serialize ( Stream &  s) const
inline

Definition at line 87 of file bignum.h.

Here is the call graph for this function:

◆ SetDec()

void CBigNum::SetDec ( const std::string &  str)

Definition at line 164 of file bignum.cpp.

Here is the caller graph for this function:

◆ SetHex()

void CBigNum::SetHex ( const std::string &  str)

Definition at line 336 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetHexBool()

bool CBigNum::SetHexBool ( const std::string &  str)

Definition at line 170 of file bignum.cpp.

Here is the caller graph for this function:

◆ setint64()

void CBigNum::setint64 ( int64_t  sn)

◆ setuint256()

void CBigNum::setuint256 ( uint256  n)

Definition at line 108 of file bignum.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setuint64()

void CBigNum::setuint64 ( uint64_t  n)

◆ setulong()

void CBigNum::setulong ( unsigned long  n)

Definition at line 83 of file bignum.cpp.

◆ setvch()

void CBigNum::setvch ( const std::vector< unsigned char > &  vch)

Definition at line 123 of file bignum.cpp.

Here is the caller graph for this function:

◆ ToString()

std::string CBigNum::ToString ( int  nBase = 10) const

Definition at line 177 of file bignum.cpp.

Here is the caller graph for this function:

◆ Unserialize()

template<typename Stream >
void CBigNum::Unserialize ( Stream &  s)
inline

Definition at line 93 of file bignum.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 221 of file bignum.h.

◆ operator%

const CBigNum operator% ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 205 of file bignum.h.

◆ operator*

const CBigNum operator* ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 195 of file bignum.h.

◆ operator+

const CBigNum operator+ ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 180 of file bignum.h.

◆ operator- [1/2]

const CBigNum operator- ( const CBigNum a)
friend

Definition at line 190 of file bignum.h.

◆ operator- [2/2]

const CBigNum operator- ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 185 of file bignum.h.

◆ operator/

const CBigNum operator/ ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 200 of file bignum.h.

◆ operator<

bool operator< ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 224 of file bignum.h.

◆ operator<<

const CBigNum operator<< ( const CBigNum a,
unsigned int  shift 
)
friend

Definition at line 210 of file bignum.h.

◆ operator<=

bool operator<= ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 222 of file bignum.h.

◆ operator==

bool operator== ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 220 of file bignum.h.

◆ operator>

bool operator> ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 225 of file bignum.h.

◆ operator>=

bool operator>= ( const CBigNum a,
const CBigNum b 
)
friend

Definition at line 223 of file bignum.h.

Member Data Documentation

◆ bn

mpz_t CBigNum::bn
private

Definition at line 36 of file bignum.h.


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