Template Class PolyImpl

Inheritance Relationships

Base Type

Template Parameter Order

  1. typename VecType

Class Documentation

template<typename VecType>
class lbcrypto::PolyImpl : public lbcrypto::PolyInterface<PolyImpl<VecType>, VecType, PolyImpl>

Inheritence diagram for lbcrypto::PolyImpl:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "4" [label="lbcrypto::Serializable" tooltip="lbcrypto::Serializable"] "2" [label="lbcrypto::PolyInterface< PolyImpl< VecType >, VecType, PolyImpl >" tooltip="lbcrypto::PolyInterface< PolyImpl< VecType >, VecType, PolyImpl >"] "1" [label="lbcrypto::PolyImpl< VecType >" tooltip="lbcrypto::PolyImpl< VecType >" fillcolor="#BFBFBF"] "3" [label="lbcrypto::ILElement< Element, VecType >" tooltip="lbcrypto::ILElement< Element, VecType >"] "2" -> "3" [dir=forward tooltip="public-inheritance"] "1" -> "2" [dir=forward tooltip="public-inheritance"] "3" -> "4" [dir=forward tooltip="public-inheritance"] }

Collaboration diagram for lbcrypto::PolyImpl:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "4" [label="lbcrypto::Serializable" tooltip="lbcrypto::Serializable"] "2" [label="lbcrypto::PolyInterface< PolyImpl< VecType >, VecType, PolyImpl >" tooltip="lbcrypto::PolyInterface< PolyImpl< VecType >, VecType, PolyImpl >"] "1" [label="lbcrypto::PolyImpl< VecType >" tooltip="lbcrypto::PolyImpl< VecType >" fillcolor="#BFBFBF"] "3" [label="lbcrypto::ILElement< Element, VecType >" tooltip="lbcrypto::ILElement< Element, VecType >"] "2" -> "3" [dir=forward tooltip="public-inheritance"] "1" -> "2" [dir=forward tooltip="public-inheritance"] "3" -> "4" [dir=forward tooltip="public-inheritance"] }

Public Types

using Vector = VecType
using Integer = typename VecType::Integer
using Params = ILParamsImpl<Integer>
using PolyNative = PolyImpl<NativeVector>
using PolyType = PolyImpl<VecType>
using PolyLargeType = PolyImpl<VecType>
using PolyInterfaceType = PolyInterface<PolyImpl<VecType>, VecType, PolyImpl>
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
inline PolyImpl(const std::shared_ptr<Params> &params, Format format = Format::EVALUATION, bool initializeElementToZero = false)
inline PolyImpl(const std::shared_ptr<ILDCRTParams<Integer>> &params, Format format = Format::EVALUATION, bool initializeElementToZero = false)
inline PolyImpl(bool initializeElementToMax, const std::shared_ptr<Params> &params, Format format = Format::EVALUATION)
PolyImpl(const DggType &dgg, const std::shared_ptr<Params> &params, Format format = Format::EVALUATION)
PolyImpl(DugType &dug, const std::shared_ptr<Params> &params, Format format = Format::EVALUATION)
PolyImpl(const BugType &bug, const std::shared_ptr<Params> &params, Format format = Format::EVALUATION)
PolyImpl(const TugType &tug, const std::shared_ptr<Params> &params, Format format = Format::EVALUATION, uint32_t h = 0)
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)
inline PolyImpl(const PolyType &p) noexcept
inline PolyImpl(PolyType &&p) noexcept
virtual PolyType &operator=(const PolyType &rhs) noexcept override
inline virtual PolyType &operator=(PolyType &&rhs) noexcept override
PolyType &operator=(const std::vector<int32_t> &rhs)
PolyType &operator=(const std::vector<int64_t> &rhs)
virtual PolyType &operator=(std::initializer_list<uint64_t> rhs) override

Assignment operator that copies elements.

Parameters

rhs

PolyType &operator=(std::initializer_list<std::string> rhs)
PolyType &operator=(uint64_t val)
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

virtual void SetValues(VecType &&values, Format format) override
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 const std::shared_ptr<Params> &GetParams() const
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.

inline virtual const Integer &at(usint i) const final
inline virtual Integer &operator[](usint i) final
inline virtual const Integer &operator[](usint i) const final
inline PolyImpl Plus(const PolyImpl &rhs) const override
inline PolyImpl PlusNoCheck(const PolyImpl &rhs) const
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 PolyImpl TimesNoCheck(const PolyImpl &rhs) const
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.

inline PolyImpl Times(int64_t element) const
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 \sum\limits{i=0}^{\lfloor {\log q/base} \rfloor} {(base^i u_i)} and return the vector of \left\{u_0, u_1,...,u_{\lfloor {\log q/base} \rfloor} \right\} \in R_{{base}^{\lceil {\log q/base} \rceil}}; This is used as a subroutine in the relinearization procedure.

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., base = 2^{baseBits}.

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 \left\{x, {base}*x, {base}^2*x, ..., {base}^{\lfloor {\log q/{base}} \rfloor} \right\}*x, where x 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.

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., base = 2^{baseBits}.

Returns

is the pointer where the base decomposition vector is stored

template<class Archive>
inline void save(Archive &ar, std::uint32_t const version) const
template<class Archive>
inline void load(Archive &ar, std::uint32_t const version)
inline virtual std::string SerializedObjectName() const override
template<typename VecType>
PolyImpl(const DggType &dgg, const std::shared_ptr<PolyImpl::Params> &params, Format format)
template<typename VecType>
PolyImpl(DugType &dug, const std::shared_ptr<PolyImpl::Params> &params, Format format)
template<typename VecType>
PolyImpl(const BugType &bug, const std::shared_ptr<PolyImpl::Params> &params, Format format)
template<typename VecType>
PolyImpl(const TugType &tug, const std::shared_ptr<PolyImpl::Params> &params, Format format, uint32_t h)
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()

Protected Attributes

Format m_format = {Format::EVALUATION}
std::shared_ptr<Params> m_params = {nullptr}
std::unique_ptr<VecType> m_values = {nullptr}