Template Class PolyImpl
Defined in File poly.h
Inheritance Relationships
Base Type
public lbcrypto::PolyInterface< PolyImpl< VecType >, VecType, PolyImpl >
(Template Class PolyInterface)
Template Parameter Order
typename VecType
Class Documentation
-
template<typename VecType>
class lbcrypto::PolyImpl : public lbcrypto::PolyInterface<PolyImpl<VecType>, VecType, PolyImpl> Inheritence diagram for lbcrypto::PolyImpl:
Collaboration diagram for lbcrypto::PolyImpl:
Public Types
-
using Params = ILParamsImpl<Integer>
-
using PolyNative = PolyImpl<NativeVector>
-
using DggType = typename PolyInterfaceType::DggType
-
using DugType = typename PolyInterfaceType::DugType
-
using TugType = typename PolyInterfaceType::TugType
-
using BugType = typename PolyInterfaceType::BugType
Public Functions
-
constexpr PolyImpl() = default
-
template<typename T = VecType>
inline PolyImpl(const PolyNative &rhs, Format format, typename std::enable_if_t<std::is_same_v<T, NativeVector>, bool> = true)
-
template<typename T = VecType>
inline PolyImpl(const PolyNative &rhs, Format format, typename std::enable_if_t<!std::is_same_v<T, NativeVector>, bool> = true)
-
virtual PolyType &operator=(std::initializer_list<uint64_t> rhs) override
Assignment operator that copies elements.
- Parameters
rhs –
-
virtual PolyNative DecryptionCRTInterpolate(PlaintextModulus ptm) const override
-
inline virtual PolyNative ToNativePoly() const final
If the values are small enough this is used for efficiency.
Warning
This will be replaced with a non-member utility function.
- Returns
NativePoly
-
virtual void SetValues(const VecType &values, Format format) override
Set method that should not be used, will throw an error.
- Parameters
&values –
format –
-
inline virtual void SetValuesToZero() override
Sets all values of element to zero.
-
inline virtual void SetValuesToMax() override
-
inline virtual Format GetFormat() const final
Get format of the element.
- Returns
Format is either COEFFICIENT or EVALUATION
-
inline virtual void OverrideFormat(const Format f) final
Sets format to value without calling FFT. Only use if you know what you’re doing.
-
inline virtual const VecType &GetValues() const final
Get method that should not be used.
Warning
Doesn’t make sense for DCRT
- Returns
will throw an error.
-
inline virtual bool IsEmpty() const final
Returns true if ALL the tower(s) are empty.
- Returns
true if all towers are empty
-
inline virtual Integer &at(usint i) final
Get interpolated value of elements at all tower index i. Note this operation is computationally intense. Does bound checking.
- Returns
interpolated value at index i.
-
virtual PolyImpl &operator+=(const PolyImpl &element) override
Performs an entry-wise addition over all elements of each tower with the towers of the element on the right hand side.
- Parameters
&rhs – is the element to add with.
- Returns
is the result of the addition.
-
virtual PolyImpl Plus(const Integer &element) const override
Scalar addition - add an element to the first index of each tower.
- Parameters
&element – is the element to add entry-wise.
- Returns
is the result of the addition operation.
-
inline virtual PolyImpl &operator+=(const Integer &element) override
Performs += operation with a BigInteger and returns the result.
- Parameters
&element – is the element to add
- Returns
is the result of the addition.
-
virtual PolyImpl Minus(const PolyImpl &element) const override
Performs a subtraction operation and returns the result.
- Parameters
&element – is the element to subtract from.
- Returns
is the result of the subtraction.
-
virtual PolyImpl &operator-=(const PolyImpl &element) override
Performs an entry-wise subtraction over all elements of each tower with the towers of the element on the right hand side.
- Parameters
&rhs – is the element to subtract from.
- Returns
is the result of the addition.
-
virtual PolyImpl Minus(const Integer &element) const override
Scalar subtraction - subtract an element to all entries.
- Parameters
&element – is the element to subtract entry-wise.
- Returns
is the return value of the minus operation.
-
inline virtual PolyImpl &operator-=(const Integer &element) override
Performs a subtraction operation and returns the result.
- Parameters
&element – is the element to subtract from.
- Returns
is the result of the subtraction.
-
inline virtual PolyImpl Times(const PolyImpl &rhs) const override
Performs a modular multiplication operation for Poly’s in EVALUATION format and returns the result. Performs runtime checks for operand compatibility.
- Parameters
&element – is the element to multiply with.
- Returns
is the result of the multiplication.
-
inline virtual PolyImpl &operator*=(const PolyImpl &rhs) override
Performs an multiplication operation and returns the result.
- Parameters
&element – is the element to multiply with.
- Returns
is the result of the multiplication.
-
virtual PolyImpl Times(const Integer &element) const override
Scalar multiplication - multiply all entries.
- Parameters
&element – is the element to multiply entry-wise.
- Returns
is the return value of the times operation.
-
inline virtual PolyImpl &operator*=(const Integer &element) override
Performs a multiplication operation and returns the result.
- Parameters
&element – is the element to multiply by.
- Returns
is the result of the multiplication.
-
virtual PolyImpl Times(NativeInteger::SignedNativeInt element) const override
Scalar multiplication - multiply by a signed integer.
- Parameters
&element – is the element to multiply entry-wise.
- Returns
is the return value of the times operation.
-
virtual PolyImpl MultiplyAndRound(const Integer &p, const Integer &q) const override
Scalar multiplication followed by division and rounding operation - operation on all entries.
Warning
Will remove, this is only inplace because of BFV
- Parameters
&p – is the element to multiply entry-wise.
&q – is the element to divide entry-wise.
- Returns
is the return value of the multiply, divide and followed by rounding operation.
-
virtual PolyImpl DivideAndRound(const Integer &q) const override
Scalar division followed by rounding operation - operation on all entries.
Warning
Will remove, this is only inplace because of BFV
- Parameters
&q – is the element to divide entry-wise.
- Returns
is the return value of the divide, followed by rounding operation.
-
virtual PolyImpl Negate() const override
Performs a negation operation and returns the result.
- Returns
is the result of the negation.
-
inline virtual PolyImpl operator-() const override
Unary minus on a element.
- Returns
additive inverse of the an element.
-
inline virtual bool operator==(const PolyImpl &rhs) const override
Equality operator.
- Parameters
&rhs – is the specified element to be compared with this element.
- Returns
true if this element represents the same values as the specified element, false otherwise
-
virtual void AddILElementOne() override
Adds “1” to every entry in every tower.
-
virtual PolyImpl AutomorphismTransform(uint32_t k) const override
Permutes coefficients in a polynomial. Moves the ith index to the first one, it only supports odd indices.
- Parameters
&i – is the element to perform the automorphism transform with.
- Returns
is the result of the automorphism transform.
-
virtual PolyImpl AutomorphismTransform(uint32_t k, const std::vector<uint32_t> &vec) const override
Performs an automorphism transform operation using precomputed bit reversal indices.
- Parameters
&i – is the element to perform the automorphism transform with.
&vec – a vector with precomputed indices
- Returns
is the result of the automorphism transform.
-
virtual PolyImpl MultiplicativeInverse() const override
Performs a multiplicative inverse operation and returns the result.
- Returns
is the result of the multiplicative inverse.
-
virtual PolyImpl ModByTwo() const override
Perform a modulus by 2 operation. Returns the least significant bit.
- Returns
is the resulting value.
-
virtual PolyImpl Mod(const Integer &modulus) const override
Modulus - perform a modulus operation. Does proper mapping of [-modulus/2, modulus/2) to [0, modulus)
- Parameters
modulus – is the modulus to use.
- Returns
is the return value of the modulus.
-
virtual void SwitchModulus(const Integer &modulus, const Integer &rootOfUnity, const Integer &modulusArb, const Integer &rootOfUnityArb) override
Switch modulus and adjust the values.
- Parameters
&modulus – is the modulus to be set
&rootOfUnity – is the corresponding root of unity for the modulus
&modulusArb – is the modulus used for arbitrary cyclotomics CRT
&rootOfUnityArb – is the corresponding root of unity for the modulus ASSUMPTION: This method assumes that the caller provides the correct rootOfUnity for the modulus
-
virtual void SwitchFormat() override
Convert from Coefficient to CRT or vice versa; calls FFT and inverse FFT.
See also
SetFormat(format) instead
Warning
use
-
virtual void MakeSparse(uint32_t wFactor) override
Make DCRTPoly Sparse. Sets every index of each tower not equal to zero mod the wFactor to zero.
Warning
Only used by RingSwitching, which is no longer supported. Will be removed in future.
- Parameters
&wFactor – ratio between the sparse and none-sparse values.
-
virtual bool InverseExists() const override
Determines if inverse exists.
- Returns
is the Boolean representation of the existence of multiplicative inverse.
-
virtual double Norm() const override
Returns the infinity norm, basically the largest value in the ring element.
- Returns
is the largest value in the ring element.
-
virtual std::vector<PolyImpl> BaseDecompose(usint baseBits, bool evalModeAnswer) const override
Write the element as and return the vector of ; This is used as a subroutine in the relinearization procedure.
See also
DCRTPolyInterface::CRTDecompose instead.
Warning
not efficient and not fast, uses multiprecision arithmetic and will be removed in future. Use
- Parameters
baseBits – is the number of bits in the base, i.e., .
- Returns
is the pointer where the base decomposition vector is stored
-
virtual std::vector<PolyImpl> PowersOfBase(usint baseBits) const override
Generate a vector of PolyImpl’s as , where is the current PolyImpl object; used as a subroutine in the relinearization procedure to get powers of a certain “base” for the secret key element.
See also
DCRTPolyInterface::CRTDecompose instead.
Warning
not efficient and not fast, uses multiprecision arithmetic and will be removed in future. Use
- Parameters
baseBits – is the number of bits in the base, i.e., .
- Returns
is the pointer where the base decomposition vector is stored
-
inline virtual std::string SerializedObjectName() const override
-
inline virtual PolyImpl<NativeVector> ToNativePoly() const
If the values are small enough this is used for efficiency.
Warning
This will be replaced with a non-member utility function.
- Returns
NativePoly
Public Static Functions
-
static inline const std::string GetElementName()
-
static inline uint32_t SerializedVersion()
Protected Functions
-
void ArbitrarySwitchFormat()
-
using Params = ILParamsImpl<Integer>