PALISADE Lattice Crypto Library  1.11.9
A lattice crypto library for software engineers by software engineers.
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
bigintfxd::BigInteger< uint_type, BITLENGTH > Class Template Reference

Main class for big integers represented as an array of native (primitive) unsigned integers. More...

#include <ubintfxd.h>

Inheritance diagram for bigintfxd::BigInteger< uint_type, BITLENGTH >:
Inheritance graph
[legend]
Collaboration diagram for bigintfxd::BigInteger< uint_type, BITLENGTH >:
Collaboration graph
[legend]

Public Member Functions

 BigInteger ()
 
 BigInteger (const BigInteger &val)
 
 BigInteger (BigInteger &&val)
 
 BigInteger (const std::string &strval)
 
 BigInteger (uint64_t val)
 
 BigInteger (U128BITS val)
 
 BigInteger (int val)
 
 BigInteger (uint32_t val)
 
 BigInteger (long val)
 
 BigInteger (long long val)
 
template<typename T >
 BigInteger (const bigintnat::NativeIntegerT< T > &val)
 
 BigInteger (double val) __attribute__((deprecated("Cannot const ruct from a double")))
 
const BigIntegeroperator= (const BigInteger &val)
 
const BigIntegeroperator= (BigInteger &&val)
 
const BigIntegeroperator= (const std::string strval)
 
const BigIntegeroperator= (uint64_t val)
 
const BigIntegeroperator= (const bigintnat::NativeInteger &val)
 
void SetValue (const std::string &strval)
 
void SetValue (const BigInteger &val)
 
void SetIdentity ()
 
void SetIntAtIndex (usint idx, uint_type value)
 
BigInteger Add (const BigInteger &b) const
 
const BigIntegerAddEq (const BigInteger &b)
 
BigInteger Sub (const BigInteger &b) const
 
const BigIntegerSubEq (const BigInteger &b)
 
BigInteger operator- () const
 
BigInteger Mul (const BigInteger &b) const
 
const BigIntegerMulEq (const BigInteger &b)
 
BigInteger DividedBy (const BigInteger &b) const
 
const BigIntegerDividedByEq (const BigInteger &b)
 
BigInteger Exp (usint p) const
 
const BigIntegerExpEq (usint p)
 
BigInteger MultiplyAndRound (const BigInteger &p, const BigInteger &q) const
 
const BigIntegerMultiplyAndRoundEq (const BigInteger &p, const BigInteger &q)
 
BigInteger DivideAndRound (const BigInteger &q) const
 
const BigIntegerDivideAndRoundEq (const BigInteger &q)
 
BigInteger Mod (const BigInteger &modulus) const
 
const BigIntegerModEq (const BigInteger &modulus)
 
BigInteger ComputeMu () const
 
BigInteger Mod (const BigInteger &modulus, const BigInteger &mu) const
 
const BigIntegerModEq (const BigInteger &modulus, const BigInteger &mu)
 
BigInteger ModAdd (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModAddEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModAddFast (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModAddFastEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModAdd (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu) const
 
const BigIntegerModAddEq (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu)
 
BigInteger ModSub (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModSubEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModSubFast (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModSubFastEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModSub (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu) const
 
const BigIntegerModSubEq (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu)
 
BigInteger ModMul (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModMulEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModMul (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu) const
 
const BigIntegerModMulEq (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu)
 
BigInteger ModMulFast (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModMulFastEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModMulFast (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu) const
 
const BigIntegerModMulFastEq (const BigInteger &b, const BigInteger &modulus, const BigInteger &mu)
 
BigInteger ModMulFastConst (const BigInteger &b, const BigInteger &modulus, const BigInteger &bInv) const
 
const BigIntegerModMulFastConstEq (const BigInteger &b, const BigInteger &modulus, const BigInteger &bInv)
 
BigInteger ModExp (const BigInteger &b, const BigInteger &modulus) const
 
const BigIntegerModExpEq (const BigInteger &b, const BigInteger &modulus)
 
BigInteger ModInverse (const BigInteger &modulus) const
 
const BigIntegerModInverseEq (const BigInteger &modulus)
 
BigInteger LShift (usshort shift) const
 
const BigIntegerLShiftEq (usshort shift)
 
BigInteger RShift (usshort shift) const
 
const BigIntegerRShiftEq (usshort shift)
 
int Compare (const BigInteger &a) const
 
template<typename T = bigintnat::BasicInteger>
ConvertToInt () const
 
double ConvertToDouble () const
 
usint GetMSB () const
 
usint GetLengthForBase (usint base) const
 
usint GetDigitAtIndexForBase (usint index, usint base) const
 
bool CheckIfPowerOfTwo (const BigInteger &m_numToCheck)
 
uschar GetBitAtIndex (usint index) const
 
const std::string ToString () const
 
std::string GetInternalRepresentation (void) const
 
template<class Archive >
std::enable_if<!cereal::traits::is_text_archive< Archive >::value, void >::type save (Archive &ar, std::uint32_t const version) const
 
template<class Archive >
std::enable_if< cereal::traits::is_text_archive< Archive >::value, void >::type save (Archive &ar, std::uint32_t const version) const
 
template<class Archive >
std::enable_if<!cereal::traits::is_text_archive< Archive >::value, void >::type load (Archive &ar, std::uint32_t const version)
 
template<class Archive >
std::enable_if< cereal::traits::is_text_archive< Archive >::value, void >::type load (Archive &ar, std::uint32_t const version)
 
std::string SerializedObjectName () const
 
- Public Member Functions inherited from lbcrypto::BigIntegerInterface< BigInteger< uint_type, BITLENGTH > >
void SetValue (const std::string &str)
 
BigInteger< uint_type, BITLENGTH > Add (const BigInteger< uint_type, BITLENGTH > &b) const
 
const BigInteger< uint_type, BITLENGTH > & AddEq (const BigInteger< uint_type, BITLENGTH > &b)
 
BigInteger< uint_type, BITLENGTH > Sub (const BigInteger< uint_type, BITLENGTH > &b) const
 
const BigInteger< uint_type, BITLENGTH > & SubEq (const BigInteger< uint_type, BITLENGTH > &b)
 
BigInteger< uint_type, BITLENGTH > Mul (const BigInteger< uint_type, BITLENGTH > &b) const
 
const BigInteger< uint_type, BITLENGTH > & MulEq (const BigInteger< uint_type, BITLENGTH > &b)
 
BigInteger< uint_type, BITLENGTH > DividedBy (const BigInteger< uint_type, BITLENGTH > &b) const
 
const BigInteger< uint_type, BITLENGTH > & DividedByEq (const BigInteger< uint_type, BITLENGTH > &b)
 
BigInteger< uint_type, BITLENGTH > MultiplyAndRound (const BigInteger< uint_type, BITLENGTH > &p, const BigInteger< uint_type, BITLENGTH > &q) const
 
const BigInteger< uint_type, BITLENGTH > & MultiplyAndRoundEq (const BigInteger< uint_type, BITLENGTH > &p, const BigInteger< uint_type, BITLENGTH > &q)
 
BigInteger< uint_type, BITLENGTH > DivideAndRound (const BigInteger< uint_type, BITLENGTH > &q) const
 
const BigInteger< uint_type, BITLENGTH > & DivideAndRoundEq (const BigInteger< uint_type, BITLENGTH > &q)
 
BigInteger< uint_type, BITLENGTH > Mod (const BigInteger< uint_type, BITLENGTH > &modulus) const
 
BigInteger< uint_type, BITLENGTH > Mod (const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu) const
 
const BigInteger< uint_type, BITLENGTH > & ModEq (const BigInteger< uint_type, BITLENGTH > &modulus)
 
const BigInteger< uint_type, BITLENGTH > & ModEq (const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu)
 
BigInteger< uint_type, BITLENGTH > ComputeMu () const
 
BigInteger< uint_type, BITLENGTH > ModAdd (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
BigInteger< uint_type, BITLENGTH > ModAdd (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu) const
 
const BigInteger< uint_type, BITLENGTH > & ModAddEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
const BigInteger< uint_type, BITLENGTH > & ModAddEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu)
 
BigInteger< uint_type, BITLENGTH > ModAddFast (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
const BigInteger< uint_type, BITLENGTH > & ModAddFastEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
BigInteger< uint_type, BITLENGTH > ModSub (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
BigInteger< uint_type, BITLENGTH > ModSub (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu) const
 
const BigInteger< uint_type, BITLENGTH > & ModSubEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
const BigInteger< uint_type, BITLENGTH > & ModSubEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu)
 
BigInteger< uint_type, BITLENGTH > ModSubFast (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
const BigInteger< uint_type, BITLENGTH > & ModSubFastEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
BigInteger< uint_type, BITLENGTH > ModMul (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
BigInteger< uint_type, BITLENGTH > ModMul (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu) const
 
const BigInteger< uint_type, BITLENGTH > & ModMulEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
const BigInteger< uint_type, BITLENGTH > & ModMulEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu)
 
BigInteger< uint_type, BITLENGTH > ModMulFast (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
BigInteger< uint_type, BITLENGTH > ModMulFast (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu) const
 
const BigInteger< uint_type, BITLENGTH > & ModMulFastEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
const BigInteger< uint_type, BITLENGTH > & ModMulFastEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &mu)
 
BigInteger< uint_type, BITLENGTH > ModMulFastConst (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &bInv) const
 
const BigInteger< uint_type, BITLENGTH > & ModMulFastConstEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus, const BigInteger< uint_type, BITLENGTH > &bInv)
 
BigInteger< uint_type, BITLENGTH > ModExp (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus) const
 
const BigInteger< uint_type, BITLENGTH > & ModExpEq (const BigInteger< uint_type, BITLENGTH > &b, const BigInteger< uint_type, BITLENGTH > &modulus)
 
BigInteger< uint_type, BITLENGTH > ModInverse (const BigInteger< uint_type, BITLENGTH > &modulus) const
 
const BigInteger< uint_type, BITLENGTH > & ModInverseEq (const BigInteger< uint_type, BITLENGTH > &modulus)
 
BigInteger< uint_type, BITLENGTH > LShift (usshort shift) const
 
const BigInteger< uint_type, BITLENGTH > & LShiftEq (usshort shift)
 
BigInteger< uint_type, BITLENGTH > RShift (usshort shift) const
 
const BigInteger< uint_type, BITLENGTH > & RShiftEq (usshort shift)
 
int Compare (const BigInteger< uint_type, BITLENGTH > &a) const
 
uint64_t ConvertToInt () const
 
usint GetMSB () const
 
usint GetLengthForBase (usint base) const
 
usint GetDigitAtIndexForBase (usint index, usint base) const
 
const std::string ToString () const
 

Static Public Member Functions

static BigInteger intToBigInteger (usint m)
 
static BigInteger FromBinaryString (const std::string &bitString)
 
static BigInteger Allocator ()
 
static const std::string IntegerTypeName ()
 
static uint32_t SerializedVersion ()
 

Protected Member Functions

void AssignVal (const std::string &v)
 
void SetMSB ()
 
void SetMSB (usint guessIdxChar)
 

Friends

template<typename uint_type_c , usint BITLENGTH_c>
std::ostream & operator<< (std::ostream &os, const BigInteger< uint_type_c, BITLENGTH_c > &ptr_obj)
 

Detailed Description

template<typename uint_type, usint BITLENGTH>
class bigintfxd::BigInteger< uint_type, BITLENGTH >

Main class for big integers represented as an array of native (primitive) unsigned integers.

Template Parameters
uint_typenative unsigned integer type
BITLENGTHmaximum bitwidth supported for big integers

Constructor & Destructor Documentation

◆ BigInteger() [1/8]

template<typename uint_type , usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( )

Default constructor.

◆ BigInteger() [2/8]

template<typename uint_type , usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( const BigInteger< uint_type, BITLENGTH > &  val)

Copy constructor.

Parameters
&valis the big binary integer to be copied.

◆ BigInteger() [3/8]

template<typename uint_type , usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( BigInteger< uint_type, BITLENGTH > &&  val)

Move constructor.

Parameters
&&valis the big binary integer to be copied.

◆ BigInteger() [4/8]

template<typename uint_type , usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( const std::string &  strval)
explicit

Constructor from a string.

Parameters
&strvalis the initial integer represented as a string.

◆ BigInteger() [5/8]

template<typename uint_type , usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( uint64_t  val)

Constructor from an unsigned integer.

Parameters
valis the initial integer represented as a uint64_t.

◆ BigInteger() [6/8]

template<typename uint_type, usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( int  val)
inline

Constructors from smaller basic types

Parameters
valis the initial integer represented as a basic integer type.

◆ BigInteger() [7/8]

template<typename uint_type, usint BITLENGTH>
template<typename T >
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( const bigintnat::NativeIntegerT< T > &  val)
inline

Constructor from a NativeInteger

Parameters
&valis the initial integer represented as a native integer.

◆ BigInteger() [8/8]

template<typename uint_type, usint BITLENGTH>
bigintfxd::BigInteger< uint_type, BITLENGTH >::BigInteger ( double  val) const

Constructor from double is not permitted

Parameters
val

Member Function Documentation

◆ Add()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::Add ( const BigInteger< uint_type, BITLENGTH > &  b) const

Addition operation.

Parameters
&bis the value to add.
Returns
result of the addition operation.

◆ AddEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::AddEq ( const BigInteger< uint_type, BITLENGTH > &  b)

Addition operation. In-place variant.

Parameters
&bis the value to add.
Returns
result of the addition operation.

◆ Allocator()

template<typename uint_type, usint BITLENGTH>
static BigInteger bigintfxd::BigInteger< uint_type, BITLENGTH >::Allocator ( )
inlinestatic

A zero allocator that is called by the Matrix class. It is used to initialize a Matrix of BigInteger objects.

◆ AssignVal()

template<typename uint_type , usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::AssignVal ( const std::string &  v)
protected

Converts the string v into base-r integer where r is equal to 2^bitwidth of integral data type.

Parameters
vThe input string

◆ CheckIfPowerOfTwo()

template<typename uint_type , usint BITLENGTH>
bool bigintfxd::BigInteger< uint_type, BITLENGTH >::CheckIfPowerOfTwo ( const BigInteger< uint_type, BITLENGTH > &  m_numToCheck)

Tests whether the BigInteger is a power of 2.

Parameters
m_numToCheckis the value to check.
Returns
true if the input is a power of 2, false otherwise.

◆ Compare()

template<typename uint_type , usint BITLENGTH>
int bigintfxd::BigInteger< uint_type, BITLENGTH >::Compare ( const BigInteger< uint_type, BITLENGTH > &  a) const

Compares the current BigInteger to BigInteger a.

Parameters
ais the BigInteger to be compared with.
Returns
-1 for strictly less than, 0 for equal to and 1 for strictly greater than conditons.

◆ ComputeMu()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ComputeMu ( ) const

Pre-computes the mu factor that is used in Barrett modulo reduction

Returns
the value of mu

◆ ConvertToDouble()

template<typename uint_type , usint BITLENGTH>
double bigintfxd::BigInteger< uint_type, BITLENGTH >::ConvertToDouble ( ) const
inline

Converts the value to an double.

Returns
double representation of the value.

◆ ConvertToInt()

template<typename uint_type, usint BITLENGTH>
template<typename T = bigintnat::BasicInteger>
T bigintfxd::BigInteger< uint_type, BITLENGTH >::ConvertToInt ( ) const
inline

Converts the value to an int.

Returns
the int representation of the value as uint64_t.

◆ DivideAndRound()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::DivideAndRound ( const BigInteger< uint_type, BITLENGTH > &  q) const

Divide and Rounding operation. Returns [x/q] where [] is the rounding operation.

Parameters
&qis the denominator to be divided.
Returns
is the result of divide and round operation.

◆ DivideAndRoundEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::DivideAndRoundEq ( const BigInteger< uint_type, BITLENGTH > &  q)

Divide and Rounding operation. Returns [x/q] where [] is the rounding operation. In-place variant.

Parameters
&qis the denominator to be divided.
Returns
is the result of divide and round operation.

◆ DividedBy()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::DividedBy ( const BigInteger< uint_type, BITLENGTH > &  b) const

Division operation.

Parameters
&bis the value to divide by.
Returns
is the result of the division operation.

◆ DividedByEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::DividedByEq ( const BigInteger< uint_type, BITLENGTH > &  b)

Division operation. In-place variant.

Parameters
&bis the value to divide by.
Returns
is the result of the division operation.

◆ Exp()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::Exp ( usint  p) const

Exponentiation operation. Returns x^p.

Parameters
pthe exponent.
Returns
is the result of the exponentiation operation.

◆ ExpEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ExpEq ( usint  p)

Exponentiation operation. Returns x^p. In-place variant.

Parameters
pthe exponent.
Returns
is the result of the exponentiation operation.

◆ FromBinaryString()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::FromBinaryString ( const std::string &  bitString)
static

Convert a string representation of a binary number to a decimal BigInteger.

Parameters
bitStringthe binary num in string.
Returns
the binary number represented as a big binary int.

◆ GetBitAtIndex()

template<typename uint_type , usint BITLENGTH>
uschar bigintfxd::BigInteger< uint_type, BITLENGTH >::GetBitAtIndex ( usint  index) const

Gets the bit at the specified index.

Parameters
indexis the index of the bit to get.
Returns
resulting bit.

◆ GetDigitAtIndexForBase()

template<typename uint_type , usint BITLENGTH>
usint bigintfxd::BigInteger< uint_type, BITLENGTH >::GetDigitAtIndexForBase ( usint  index,
usint  base 
) const

Get a specific digit at "digit" index; big integer is seen as an array of digits, where a 0 <= digit < base Warning: only power-of-2 bases are currently supported. Example: for number 83, index 2 and base 4 we have:

                    index:0,1,2,3

83 –base 4 decomposition–> (3,0,1,1) –at index 2–> 1

The return number is 1.

Parameters
indexis the "digit" index of the requested digit
baseis the base with which to determine length in.
Returns
is the requested digit

◆ GetInternalRepresentation()

template<typename uint_type, usint BITLENGTH>
std::string bigintfxd::BigInteger< uint_type, BITLENGTH >::GetInternalRepresentation ( void  ) const
inline

Delivers value of the internal limb storage Used primarily for debugging

Returns
STL vector of uint_type

◆ GetLengthForBase()

template<typename uint_type, usint BITLENGTH>
usint bigintfxd::BigInteger< uint_type, BITLENGTH >::GetLengthForBase ( usint  base) const
inline

Get the number of digits using a specific base - support for arbitrary base may be needed.

Parameters
baseis the base with which to determine length in.
Returns
the length of the representation in a specific base.

◆ GetMSB()

template<typename uint_type , usint BITLENGTH>
usint bigintfxd::BigInteger< uint_type, BITLENGTH >::GetMSB ( ) const

Returns the MSB location of the value.

Returns
the index of the most significant bit.

◆ intToBigInteger()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::intToBigInteger ( usint  m)
static

Convert a value from an int to a BigInteger.

Parameters
mthe value to convert from.
Returns
int represented as a big binary int.

◆ LShift()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::LShift ( usshort  shift) const

Left shift operation.

Parameters
shift# of bits.
Returns
result of the shift operation.

◆ LShiftEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::LShiftEq ( usshort  shift)

Left shift operation. In-place variant.

Parameters
shift# of bits.
Returns
result of the shift operation.

◆ Mod() [1/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::Mod ( const BigInteger< uint_type, BITLENGTH > &  modulus) const

Naive modulus operation.

Parameters
&modulusis the modulus to perform.
Returns
is the result of the modulus operation.

◆ Mod() [2/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::Mod ( const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
) const

Barrett modulus operation. Implements generalized Barrett modular reduction algorithm. Uses one precomputed value of mu.

Parameters
&modulusis the modulus to perform.
&muis the Barrett value.
Returns
is the result of the modulus operation.

◆ ModAdd() [1/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModAdd ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus addition operation.

Parameters
&bis the scalar to add.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus addition operation.

◆ ModAdd() [2/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModAdd ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
) const

Barrett modulus addition operation.

Parameters
&bis the scalar to add.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus addition operation.

◆ ModAddEq() [1/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModAddEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus addition operation. In-place variant.

Parameters
&bis the scalar to add.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus addition operation.

◆ ModAddEq() [2/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModAddEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
)

Barrett modulus addition operation. In-place variant.

Parameters
&bis the scalar to add.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus addition operation.

◆ ModAddFast()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModAddFast ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus addition where operands are < modulus.

Parameters
&bis the scalar to add.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus addition operation.

◆ ModAddFastEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModAddFastEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus addition where operands are < modulus. In-place variant.

Parameters
&bis the scalar to add.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus addition operation.

◆ ModEq() [1/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModEq ( const BigInteger< uint_type, BITLENGTH > &  modulus)

Naive modulus operation. In-place variant.

Parameters
&modulusis the modulus to perform.
Returns
is the result of the modulus operation.

◆ ModEq() [2/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModEq ( const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
)

Barrett modulus operation. In-place variant. Implements generalized Barrett modular reduction algorithm. Uses one precomputed value of mu.

Parameters
&modulusis the modulus to perform.
&muis the Barrett value.
Returns
is the result of the modulus operation.

◆ ModExp()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModExp ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus exponentiation operation. Square-and-multiply algorithm is used.

Parameters
&bis the scalar to exponentiate at all locations.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus exponentiation operation.

◆ ModExpEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModExpEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus exponentiation operation. Square-and-multiply algorithm is used. In-place variant.

Parameters
&bis the scalar to exponentiate at all locations.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus exponentiation operation.

◆ ModInverse()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModInverse ( const BigInteger< uint_type, BITLENGTH > &  modulus) const

Modulus inverse operation.

Parameters
&modulusis the modulus to perform.
Returns
is the result of the modulus inverse operation.

◆ ModInverseEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModInverseEq ( const BigInteger< uint_type, BITLENGTH > &  modulus)

Modulus inverse operation. In-place variant.

Parameters
&modulusis the modulus to perform.
Returns
is the result of the modulus inverse operation.

◆ ModMul() [1/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMul ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus multiplication operation.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus multiplication operation.

◆ ModMul() [2/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMul ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
) const

Barrett modulus multiplication.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus multiplication operation.

◆ ModMulEq() [1/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMulEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus multiplication operation. In-place variant.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus multiplication operation.

◆ ModMulEq() [2/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMulEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
)

Barrett modulus multiplication. In-place variant.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus multiplication operation.

◆ ModMulFast() [1/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMulFast ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus multiplication that assumes the operands are < modulus.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus multiplication operation.

◆ ModMulFast() [2/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMulFast ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
) const

Barrett modulus multiplication that assumes the operands are < modulus.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus multiplication operation.

◆ ModMulFastEq() [1/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMulFastEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus multiplication that assumes the operands are < modulus. In-place variant.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus multiplication operation.

◆ ModMulFastEq() [2/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModMulFastEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
)

Barrett modulus multiplication that assumes the operands are < modulus. In-place variant.

Parameters
&bis the scalar to multiply.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus multiplication operation.

◆ ModSub() [1/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModSub ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus subtraction operation.

Parameters
&bis the scalar to subtract.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus subtraction operation.

◆ ModSub() [2/2]

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModSub ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
) const

Barrett modulus subtraction operation.

Parameters
&bis the scalar to subtract.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus subtraction operation.

◆ ModSubEq() [1/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModSubEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus subtraction operation. In-place variant.

Parameters
&bis the scalar to subtract.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus subtraction operation.

◆ ModSubEq() [2/2]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModSubEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus,
const BigInteger< uint_type, BITLENGTH > &  mu 
)

Barrett modulus subtraction operation. In-place variant.

Parameters
&bis the scalar to subtract.
&modulusis the modulus to perform operations with.
&muis the Barrett value.
Returns
is the result of the modulus subtraction operation.

◆ ModSubFast()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::ModSubFast ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
) const

Modulus subtraction where operands are < modulus.

Parameters
&bis the scalar to subtract.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus subtraction operation.

◆ ModSubFastEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::ModSubFastEq ( const BigInteger< uint_type, BITLENGTH > &  b,
const BigInteger< uint_type, BITLENGTH > &  modulus 
)

Modulus subtraction where operands are < modulus. In-place variant.

Parameters
&bis the scalar to subtract.
&modulusis the modulus to perform operations with.
Returns
is the result of the modulus subtraction operation.

◆ Mul()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::Mul ( const BigInteger< uint_type, BITLENGTH > &  b) const

Multiplication operation.

Parameters
&bis the value to multiply with.
Returns
is the result of the multiplication operation.

◆ MulEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::MulEq ( const BigInteger< uint_type, BITLENGTH > &  b)

Multiplication operation. In-place variant.

Parameters
&bis the value to multiply with.
Returns
is the result of the multiplication operation.

◆ MultiplyAndRound()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::MultiplyAndRound ( const BigInteger< uint_type, BITLENGTH > &  p,
const BigInteger< uint_type, BITLENGTH > &  q 
) const

Multiply and Rounding operation. Returns [x*p/q] where [] is the rounding operation.

Parameters
&pis the numerator to be multiplied.
&qis the denominator to be divided.
Returns
is the result of multiply and round operation.

◆ MultiplyAndRoundEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::MultiplyAndRoundEq ( const BigInteger< uint_type, BITLENGTH > &  p,
const BigInteger< uint_type, BITLENGTH > &  q 
)

Multiply and Rounding operation. Returns [x*p/q] where [] is the rounding operation. In-place variant.

Parameters
&pis the numerator to be multiplied.
&qis the denominator to be divided.
Returns
is the result of multiply and round operation.

◆ operator-()

template<typename uint_type, usint BITLENGTH>
BigInteger bigintfxd::BigInteger< uint_type, BITLENGTH >::operator- ( ) const
inline

Operator for unary minus

Returns

◆ operator=() [1/5]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::operator= ( const BigInteger< uint_type, BITLENGTH > &  val)

Copy assignment operator

Parameters
&valis the big binary integer to be assigned from.
Returns
assigned BigInteger ref.

◆ operator=() [2/5]

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::operator= ( BigInteger< uint_type, BITLENGTH > &&  val)

Move assignment operator

Parameters
&valis the big binary integer to be assigned from.
Returns
assigned BigInteger ref.

◆ operator=() [3/5]

template<typename uint_type, usint BITLENGTH>
const BigInteger& bigintfxd::BigInteger< uint_type, BITLENGTH >::operator= ( const std::string  strval)
inline

Assignment operator from string

Parameters
strvalis the string to be assigned from
Returns
the assigned BigInteger ref.

◆ operator=() [4/5]

template<typename uint_type, usint BITLENGTH>
const BigInteger& bigintfxd::BigInteger< uint_type, BITLENGTH >::operator= ( uint64_t  val)
inline

Assignment operator from unsigned integer

Parameters
valis the unsigned integer to be assigned from.
Returns
the assigned BigInteger ref.

◆ operator=() [5/5]

template<typename uint_type, usint BITLENGTH>
const BigInteger& bigintfxd::BigInteger< uint_type, BITLENGTH >::operator= ( const bigintnat::NativeInteger val)
inline

Assignment operator from native integer

Parameters
&valis the native integer to be assigned from.
Returns
the assigned BigInteger ref.

◆ RShift()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::RShift ( usshort  shift) const

Right shift operation.

Parameters
shift# of bits.
Returns
result of the shift operation.

◆ RShiftEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::RShiftEq ( usshort  shift)

Right shift operation. In-place variant.

Parameters
shift# of bits.
Returns
result of the shift operation.

◆ SetIdentity()

template<typename uint_type, usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::SetIdentity ( )
inline

Set this int to 1.

◆ SetIntAtIndex()

template<typename uint_type , usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::SetIntAtIndex ( usint  idx,
uint_type  value 
)

Sets the int value at the specified index.

Parameters
indexis the index of the int to set in the uint array.

◆ SetMSB() [1/2]

template<typename uint_type , usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::SetMSB ( )
protected

Sets the MSB to the correct value from the BigInteger.

◆ SetMSB() [2/2]

template<typename uint_type , usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::SetMSB ( usint  guessIdxChar)
protected

Sets the MSB to the correct value from the BigInteger.

Parameters
guessIdxCharis the hint of the MSB position.

◆ SetValue() [1/2]

template<typename uint_type , usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::SetValue ( const std::string &  strval)

Basic set method for setting the value of a big binary integer

Parameters
strvalis the string representation of the big binary integer to be copied.

◆ SetValue() [2/2]

template<typename uint_type , usint BITLENGTH>
void bigintfxd::BigInteger< uint_type, BITLENGTH >::SetValue ( const BigInteger< uint_type, BITLENGTH > &  val)

Basic set method for setting the value of a big binary integer

Parameters
valis the big binary integer representation of the big binary integer to be assigned.

◆ Sub()

template<typename uint_type , usint BITLENGTH>
BigInteger< uint_type, BITLENGTH > bigintfxd::BigInteger< uint_type, BITLENGTH >::Sub ( const BigInteger< uint_type, BITLENGTH > &  b) const

Subtraction operation.

Parameters
&bis the value to subtract.
Returns
is the result of the subtraction operation.

◆ SubEq()

template<typename uint_type , usint BITLENGTH>
const BigInteger< uint_type, BITLENGTH > & bigintfxd::BigInteger< uint_type, BITLENGTH >::SubEq ( const BigInteger< uint_type, BITLENGTH > &  b)

Subtraction operation. In-place variant.

Parameters
&bis the value to subtract.
Returns
is the result of the subtraction operation.

◆ ToString()

template<typename uint_type , usint BITLENGTH>
const std::string bigintfxd::BigInteger< uint_type, BITLENGTH >::ToString ( ) const

Stores the based 10 equivalent/Decimal value of the BigInteger in a string object and returns it.

Returns
value of this BigInteger in base 10 represented as a string.

Friends And Related Function Documentation

◆ operator<<

template<typename uint_type, usint BITLENGTH>
template<typename uint_type_c , usint BITLENGTH_c>
std::ostream& operator<< ( std::ostream &  os,
const BigInteger< uint_type_c, BITLENGTH_c > &  ptr_obj 
)
friend

Console output operation.

Parameters
osis the std ostream object.
ptr_objis BigInteger to be printed.
Returns
is the ostream object.

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