Template Class BigIntegerInterface
Defined in File integer.h
Page Contents
Template Parameter Order
typename T
Class Documentation
-
template<typename T>
class lbcrypto::BigIntegerInterface Public Functions
-
void SetValue(const std::string &str)
Set from a string
- Parameters
str – is the string representation of the value
-
T Add(const T &b) const
Addition operation.
- Parameters
&b – is the value to add.
- Returns
result of the addition operation.
-
T Sub(const T &b) const
Subtraction operation.
- Parameters
&b – is the value to subtract.
- Returns
is the result of the subtraction operation.
-
T Mul(const T &b) const
Multiplication operation.
- Parameters
&b – is the value to multiply with.
- Returns
is the result of the multiplication operation.
-
T &MulEq(const T &b)
Multiplication operation. In-place variant.
- Parameters
&b – is the value to multiply with.
- Returns
is the result of the multiplication operation.
-
T DividedBy(const T &b) const
Division operation.
- Parameters
&b – is the value to divide by.
- Returns
is the result of the division operation.
-
T &DividedByEq(const T &b)
Division operation. In-place variant.
- Parameters
&b – is the value to divide by.
- Returns
is the result of the division operation.
-
T MultiplyAndRound(const T &p, const T &q) const
Multiply and Rounding operation. Returns [x*p/q] where [] is the rounding operation.
- Parameters
&p – is the numerator to be multiplied.
&q – is the denominator to be divided.
- Returns
is the result of multiply and round operation.
-
T DivideAndRound(const T &q) const
Divide and Rounding operation. Returns [x/q] where [] is the rounding operation.
- Parameters
&q – is the denominator to be divided.
- Returns
is the result of divide and round operation.
-
T Mod(const T &modulus) const
Naive modulus operation.
- Parameters
&modulus – is the modulus to perform.
- Returns
is the result of the modulus operation.
-
T ComputeMu() const
Precomputes a parameter mu for Barrett modular reduction.
- Returns
the precomputed parameter mu.
-
T Mod(const T &modulus, const T &mu) const
Barrett modulus operation. Implements generalized Barrett modular reduction algorithm. Uses one precomputed value of mu.
- Parameters
&modulus – is the modulus to perform.
&mu – is the Barrett value.
- Returns
is the result of the modulus operation.
-
T ModAdd(const T &b, const T &modulus) const
Modulus addition operation.
- Parameters
&b – is the scalar to add.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus addition operation.
-
T ModAddFast(const T &b, const T &modulus) const
Modulus addition where operands are < modulus.
- Parameters
&b – is the scalar to add.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus addition operation.
-
T ModAdd(const T &b, const T &modulus, const T &mu) const
Barrett modulus addition operation.
- Parameters
&b – is the scalar to add.
&modulus – is the modulus to perform operations with.
&mu – is the Barrett value.
- Returns
is the result of the modulus addition operation.
-
T ModSub(const T &b, const T &modulus) const
Modulus subtraction operation.
- Parameters
&b – is the scalar to subtract.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus subtraction operation.
-
T ModSubFast(const T &b, const T &modulus) const
Modulus subtraction where operands are < modulus.
- Parameters
&b – is the scalar to subtract.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus subtraction operation.
-
T ModSub(const T &b, const T &modulus, const T &mu) const
Barrett modulus subtraction operation.
- Parameters
&b – is the scalar to subtract.
&modulus – is the modulus to perform operations with.
&mu – is the Barrett value.
- Returns
is the result of the modulus subtraction operation.
-
T ModMul(const T &b, const T &modulus) const
Modulus multiplication operation.
- Parameters
&b – is the scalar to multiply.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus multiplication operation.
-
T ModMul(const T &b, const T &modulus, const T &mu) const
Barrett modulus multiplication.
- Parameters
&b – is the scalar to multiply.
&modulus – is the modulus to perform operations with.
&mu – is the Barrett value.
- Returns
is the result of the modulus multiplication operation.
-
T ModMulFast(const T &b, const T &modulus) const
Modulus multiplication that assumes the operands are < modulus.
- Parameters
&b – is the scalar to multiply.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus multiplication operation.
-
T ModMulFast(const T &b, const T &modulus, const T &mu) const
Barrett modulus multiplication that assumes the operands are < modulus.
- Parameters
&b – is the scalar to multiply.
&modulus – is the modulus to perform operations with.
&mu – is the Barrett value.
- Returns
is the result of the modulus multiplication operation.
-
T ModMulFastConst(const T &b, const T &modulus, const T &bInv) const
NTL-optimized modular multiplication using a precomputation for the multiplicand. Assumes operands are < modulus.
- Parameters
&b – is the scalar to multiply.
&modulus – is the modulus to perform operations with.
&bInv – NTL precomputation for b.
- Returns
is the result of the modulus multiplication operation.
-
T ModExp(const T &b, const T &modulus) const
Modulus exponentiation operation.
- Parameters
&b – is the scalar to exponentiate at all locations.
&modulus – is the modulus to perform operations with.
- Returns
is the result of the modulus exponentiation operation.
-
T ModInverse(const T &modulus) const
Modulus inverse operation.
- Parameters
&modulus – is the modulus to perform.
- Returns
is the result of the modulus inverse operation.
-
T LShift(usshort shift) const
Left shift operation.
- Parameters
shift – # of bits.
- Returns
result of the shift operation.
-
T RShift(usshort shift) const
Right shift operation.
- Parameters
shift – # of bits.
- Returns
result of the shift operation.
-
int Compare(const T &a) const
Compares the current BigInteger to BigInteger a.
- Parameters
a – is the BigInteger to be compared with.
- Returns
-1 for strictly less than, 0 for equal to and 1 for strictly greater than conditons.
-
uint64_t ConvertToInt() const
Convert the value to an int.
- Returns
the int representation of the value.
-
usint GetMSB() const
Returns the MSB location of the value.
- Returns
the index of the most significant bit.
-
usint GetLengthForBase(usint base) const
Get the number of digits using a specific base - support for arbitrary base may be needed.
- Parameters
base – is the base with which to determine length in.
- Returns
the length of the representation in a specific base.
-
usint GetDigitAtIndexForBase(usint index, usint base) const
Get the number of digits using a specific base - support for arbitrary base may be needed. Example: for number 83, index 2 and base 4 we have:
83 —base 4 decomposition–> (3,0,1,1) —at index 2–> 1index:0,1,2,3
The return number is 1.
- Parameters
index – is the location to return value from in the specific base.
base – is the base with which to determine length in.
- Returns
the length of the representation in a specific base.
-
const std::string ToString() const
Convert this integer into a std::string, for serialization
- Returns
the value of this T as a string.
Protected Functions
-
~BigIntegerInterface() = default
Friends
-
inline friend T operator*(const T &a, const T &b)
inline operators for the multiplication operation.
-
inline friend T operator<<(const T &a, usshort shift)
inline operators for the left shift operations.
-
void SetValue(const std::string &str)