Template Class BigVectorInterface
Defined in File vector.h
Page Contents
Template Parameter Order
typename Ttypename I
Class Documentation
-
template<typename T, typename I>
class lbcrypto::BigVectorInterface Interface (CRTP base) implemented by every vector-of-integers backend: a vector of residues sharing one modulus. T is the derived vector type and I its integer type. Naming conventions: the plain method returns a new vector, the “Eq” suffix performs the operation in place on *this and returns *this, and “NoCheck” variants skip the length and modulus compatibility checks of the checked forms.
- Template Parameters
T – the derived vector type
I – the integer type of the entries
Public Functions
-
T &operator=(const T &vec)
Copy assignment operator.
- Parameters
vec – is the vector to be assigned from.
- Returns
assigned vector ref.
-
T &operator=(T &&vec)
Move assignment operator.
- Parameters
vec – is the vector to be assigned from.
- Returns
assigned vector ref.
-
T &operator=(std::initializer_list<std::string> strvec)
Assignment operator from initializer list of strings.
- Parameters
strvec – is the list of strings.
- Returns
assigned vector ref.
-
T &operator=(std::initializer_list<uint64_t> vec)
Assignment operator from initializer list of unsigned integers.
- Parameters
vec – is the list of integers.
- Returns
assigned vector ref.
-
T &operator=(uint64_t val)
Assignment operator to assign value val to first entry, 0 for the rest of entries.
- Parameters
val – is the unsigned integer the first entry to be assigned from.
- Returns
assigned vector ref.
-
I &at(size_t idx)
Range-checked access to an entry.
- Parameters
idx – is the index of the entry.
- Returns
reference to the entry at the index; throws if idx is out of range.
-
const I &at(size_t idx) const
Range-checked read access to an entry.
- Parameters
idx – is the index of the entry.
- Returns
const reference to the entry at the index; throws if idx is out of range.
-
I &operator[](size_t idx)
Unchecked access to an entry.
- Parameters
idx – is the index of the entry.
- Returns
reference to the entry at the index; no range check is performed.
-
const I &operator[](size_t idx) const
Unchecked read access to an entry.
- Parameters
idx – is the index of the entry.
- Returns
const reference to the entry at the index; no range check is performed.
-
void SetModulus(const I &value)
Sets the vector modulus.
- Parameters
value – is the modulus value to set.
-
void SwitchModulus(const I &value)
Sets the vector modulus and changes the values to match the new modulus.
- Parameters
value – is the modulus value to set.
-
void LazySwitchModulus(const I &value)
Sets the vector modulus and reduces every entry modulo the new modulus as a non-negative integer, without the centered (signed) adjustment performed by SwitchModulus.
- Parameters
value – is the modulus value to set.
-
T &MultAccEqNoCheck(const T &vec, const I &value)
Fused multiply-accumulate: *this += vec * value (mod the vector modulus), without length or modulus validation. The entries of *this must be reduced; the entries of vec need not be reduced, and value is reduced internally.
- Parameters
vec – is the vector to multiply and accumulate.
value – is the scalar multiplier.
- Returns
*this after the accumulation.
-
size_t GetLength() const
Gets the vector length.
- Returns
vector length.
-
T Mod(const I &modulus) const
Vector modulus operator.
- Parameters
modulus – is the modulus to perform on the current vector entries.
- Returns
is the result of the modulus operation on current vector.
-
T &ModEq(const I &modulus)
Vector modulus operator. In-place variant.
- Parameters
modulus – is the modulus to perform on the current vector entries.
- Returns
is the result of the modulus operation on current vector.
-
T ModAdd(const I &b) const
Scalar-to-vector modulus addition operation.
- Parameters
b – is the scalar to perform operation with.
- Returns
is the result of the modulus addition operation.
-
T &ModAddEq(const I &b)
Scalar-to-vector modulus addition operation. In-place variant.
- Parameters
b – is the scalar to perform operation with.
- Returns
is the result of the modulus addition operation.
-
T ModAddAtIndex(uint32_t i, const I &b) const
Scalar modulus addition at a particular index.
- Parameters
i – is the index of the entry to add.
b – is the scalar to add.
- Returns
is the result of the modulus addition operation.
-
T &ModAddAtIndexEq(uint32_t i, const I &b)
Scalar modulus addition at a particular index. In-place variant.
- Parameters
i – is the index of the entry to add.
b – is the scalar to add.
- Returns
is the result of the modulus addition operation.
-
T ModAdd(const T &b) const
Vector component wise modulus addition.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus addition operation.
-
T &ModAddEq(const T &b)
Vector component wise modulus addition. In-place variant.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus addition operation.
-
T &ModAddNoCheckEq(const T &b)
Vector component wise modulus addition. In-place variant that skips the length and modulus compatibility check of ModAddEq; b must have the same length and modulus.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus addition operation.
-
T ModSub(const I &b) const
Scalar-from-vector modulus subtraction operation.
- Parameters
b – is the scalar to perform operation with.
- Returns
is the result of the modulus subtraction operation.
-
T &ModSubEq(const I &b)
Scalar-from-vector modulus subtraction operation. In-place variant.
- Parameters
b – is the scalar to perform operation with.
- Returns
is the result of the modulus subtraction operation.
-
T ModSub(const T &b) const
Vector component wise modulus subtraction.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus subtraction operation.
-
T &ModSubEq(const T &b)
Vector component wise modulus subtraction. In-place variant.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus subtraction operation.
-
T ModMul(const I &b) const
Scalar-to-vector modulus multiplication operation.
- Parameters
b – is the scalar to perform operation with.
- Returns
is the result of the modulus multiplication operation.
-
T &ModMulEq(const I &b)
Scalar-to-vector modulus multiplication operation. In-place variant.
- Parameters
b – is the scalar to perform operation with.
- Returns
is the result of the modulus multiplication operation.
-
T ModMul(const T &b) const
Vector component wise modulus multiplication.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus multiplication operation.
-
T &ModMulEq(const T &b)
Vector component wise modulus multiplication. In-place variant.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus multiplication operation.
-
T &ModMulNoCheckEq(const T &b)
Vector component wise modulus multiplication. In-place variant that skips the length and modulus compatibility check of ModMulEq; b must have the same length and modulus.
- Parameters
b – is the vector to perform operation with.
- Returns
is the result of the component wise modulus multiplication operation.
-
T ModExp(const I &b) const
Scalar modulus exponentiation operation. Computes this[i]^b mod modulus for each component. The exponent is used as given and is not reduced by the vector modulus, matching the scalar ModExp semantics.
- Parameters
b – is the scalar exponent to perform operation with.
- Returns
is the result of the modulus exponentiation operation.
-
T &ModExpEq(const I &b)
Scalar modulus exponentiation operation. In-place variant. Computes this[i]^b mod modulus for each component. The exponent is used as given and is not reduced by the vector modulus, matching the scalar ModExp semantics.
- Parameters
b – is the scalar exponent to perform operation with.
- Returns
is the result of the modulus exponentiation operation.
-
T ModInverse() const
Modulus inverse operation.
- Returns
is the result of the component wise modulus inverse operation.
-
T &ModInverseEq()
Modulus inverse operation. In-place variant.
- Returns
is the result of the component wise modulus inverse operation.
-
T ModByTwo() const
Modulus 2 operation, also a least significant bit.
- Returns
is the result of the component wise modulus 2 operation, also a least significant bit.
-
T &ModByTwoEq()
Modulus 2 operation, also a least significant bit. In-place variant.
- Returns
is the result of the component wise modulus 2 operation, also a least significant bit.
-
T MultiplyAndRound(const I &p, const I &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 &MultiplyAndRoundEq(const I &p, const I &q)
Multiply and Rounding operation. Returns [x*p/q] where [] is the rounding operation. In-place variant.
- 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 I &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 &DivideAndRoundEq(const I &q)
Divide and Rounding operation. Returns [x/q] where [] is the rounding operation. In-place variant.
- Parameters
q – is the denominator to be divided.
- Returns
is the result of divide and round operation.
-
T GetDigitAtIndexForBase(uint32_t index, uint32_t base) const
Digit vector at a specific index for all entries for a given number base. Example: for vector (83, 1, 45), index 2 and base 4 we have:
|83| |3,0,1,1| |1| |1 | —base 4 decomposition–> |1,0,0,0| —at index 2–> |0| |45| |1,3,2,0| |2|index:0,1,2,3
The return vector is (1,0,2)
- Parameters
index – is the index to return the digit from in all entries.
base – is the base to use for the operation.
- Returns
is the digit at a specific index for all entries for a given number base
Protected Functions
-
~BigVectorInterface() = default
Friends
-
inline friend bool operator==(const T &a, const T &b)
Equals to operator.
- Parameters
a – is the first vector to be compared.
b – is the second vector to be compared.
- Returns
true if equal and false otherwise.
-
inline friend bool operator!=(const T &a, const T &b)
Not equal to operator.
- Parameters
a – is the first vector to be compared.
b – is the second vector to be compared.
- Returns
true if not equal and false otherwise.
-
inline friend T operator+(const T &a, const I &b)
inline operators for the scalar-to-vector modulus addition operations.
-
inline friend T &operator+=(T &a, const I &b)
inline in-place operator for the scalar-to-vector modulus addition.
-
inline friend T operator+(const T &a, const T &b)
inline operators for the vector component wise modulus addition operations.
-
inline friend T &operator+=(T &a, const T &b)
inline in-place operator for the vector component wise modulus addition.
-
inline friend T operator-(const T &a, const I &b)
inline operators for the scalar-from-vector modulus subtraction operations.
-
inline friend T &operator-=(T &a, const I &b)
inline in-place operator for the scalar-from-vector modulus subtraction.
-
inline friend T operator-(const T &a, const T &b)
inline operators for the vector component wise modulus subtraction operations.
-
inline friend const T &operator-=(T &a, const T &b)
inline in-place operator for the vector component wise modulus subtraction.
-
inline friend T operator*(const T &a, const I &b)
inline operators for the scalar-to-vector modulus multiplication operations.
-
inline friend T &operator*=(T &a, const I &b)
inline in-place operator for the scalar-to-vector modulus multiplication.