Template Class PolyInterface
Defined in File poly-interface.h
Page Contents
Inheritance Relationships
Base Type
public lbcrypto::ILElement< DerivedType, VecType >
(Template Class ILElement)
Derived Types
public lbcrypto::PolyImpl< NativeVector >
(Template Class PolyImpl)public lbcrypto::PolyImpl< BigVector >
(Template Class PolyImpl)
Template Parameter Order
typename DerivedType
typename VecType
template< typename LVT > typename ContainerType
Class Documentation
-
template<typename DerivedType, typename VecType, template<typename LVT> typename ContainerType>
class lbcrypto::PolyInterface : public lbcrypto::ILElement<DerivedType, VecType> Inheritence diagram for lbcrypto::PolyInterface:
Collaboration diagram for lbcrypto::PolyInterface:
Subclassed by lbcrypto::PolyImpl< NativeVector >, lbcrypto::PolyImpl< BigVector >
Public Types
-
using Params = ILParamsImpl<Integer>
-
using PolyNative = ContainerType<NativeVector>
-
using DggType = DiscreteGaussianGeneratorImpl<VecType>
-
using DugType = DiscreteUniformGeneratorImpl<VecType>
-
using TugType = TernaryUniformGeneratorImpl<VecType>
-
using BugType = BinaryUniformGeneratorImpl<VecType>
Public Functions
-
inline DerivedType &GetDerived()
Get the Derived object, this is apart of the CRTP software design pattern it allows the base class (this one) to implement methods that call the derived objects implementation.
Chapter 21.2 “C++ Templates The Complete Guide” by David Vandevoorde and Nicolai M. Josuttis http://www.informit.com/articles/article.asp?p=31473
- Returns
DerivedType&
-
inline const DerivedType &GetDerived() const
-
virtual DerivedType &operator=(const DerivedType &rhs) override = 0
Assignment operator that copies elements.
- Parameters
rhs –
-
virtual DerivedType &operator=(DerivedType &&rhs) override = 0
Assignment operator that copies elements.
- Parameters
rhs –
-
inline DerivedType &operator=(const std::vector<int32_t> &rhs)
-
inline DerivedType &operator=(const std::vector<int64_t> &rhs)
-
virtual DerivedType &operator=(std::initializer_list<uint64_t> rhs) override = 0
Assignment operator that copies elements.
- Parameters
rhs –
-
inline DerivedType &operator=(std::initializer_list<std::string> rhs)
-
inline DerivedType &operator=(uint64_t rhs)
-
inline virtual Format GetFormat() const override
Get method of the format.
- Returns
the format, either COEFFICIENT or EVALUATION
-
inline const std::shared_ptr<Params> &GetParams() const
returns the parameters of the element.
- Returns
the element parameter set.
-
inline usint GetRingDimension() const
returns the element’s ring dimension
- Returns
returns the ring dimension of the element.
-
inline const Integer &GetRootOfUnity() const
returns the element’s root of unity.
- Returns
the element’s root of unity.
-
inline virtual const Integer &GetModulus() const final
returns the element’s modulus
- Returns
returns the modulus of the element.
-
inline virtual usint GetCyclotomicOrder() const final
returns the element’s cyclotomic order
- Returns
returns the cyclotomic order of the element.
-
inline virtual usint GetLength() const final
Get method for length of each component element. NOTE assumes all components are the same size. (Ring Dimension)
- Returns
length of the component element
-
virtual const VecType &GetValues() const override = 0
Get method that should not be used.
Warning
Doesn’t make sense for DCRT
- Returns
will throw an error.
-
virtual Integer &at(usint i) override = 0
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 Integer &operator[](usint i) override
Get interpolated value of element at index i. Note this operation is computationally intense. No bound checking.
- Returns
interpolated value at index i.
-
inline virtual DerivedType Plus(const DerivedType &rhs) const override
Performs an addition operation and returns the result.
- Parameters
&element – is the element to add with.
- Returns
is the result of the addition.
-
virtual DerivedType Minus(const DerivedType &element) const override = 0
Performs a subtraction operation and returns the result.
- Parameters
&element – is the element to subtract from.
- Returns
is the result of the subtraction.
-
virtual DerivedType Times(const DerivedType &element) const override = 0
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 DerivedType TimesNoCheck(const DerivedType &rhs) const
Performs a modular multiplication operation for Poly’s in any format and returns the result. Performs no runtime checks.
- Parameters
&element – is the element to multiply with.
- Returns
is the result of the multiplication.
-
virtual DerivedType Plus(const Integer &element) const override = 0
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.
-
virtual DerivedType Minus(const Integer &element) const override = 0
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.
-
virtual DerivedType Times(const Integer &element) const override = 0
Scalar multiplication - multiply all entries.
- Parameters
&element – is the element to multiply entry-wise.
- Returns
is the return value of the times operation.
-
virtual DerivedType Times(NativeInteger::SignedNativeInt element) const override = 0
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 DerivedType Times(int64_t rhs) const
Scalar multiplication - multiply by a signed integer.
Note
this is need for 128-bit so that the 64-bit inputs can be used.
- Parameters
&element – is the element to multiply entry-wise.
- Returns
is the return value of the times operation.
-
virtual DerivedType MultiplyAndRound(const Integer &p, const Integer &q) const override = 0
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 DerivedType DivideAndRound(const Integer &q) const override = 0
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 DerivedType Negate() const = 0
Performs a negation operation and returns the result.
- Returns
is the result of the negation.
-
virtual DerivedType operator-() const override = 0
Unary minus on a element.
- Returns
additive inverse of the an element.
-
virtual DerivedType &operator+=(const Integer &element) override = 0
Performs += operation with a BigInteger and returns the result.
- Parameters
&element – is the element to add
- Returns
is the result of the addition.
-
virtual DerivedType &operator-=(const Integer &element) override = 0
Performs a subtraction operation and returns the result.
- Parameters
&element – is the element to subtract from.
- Returns
is the result of the subtraction.
-
virtual DerivedType &operator*=(const Integer &element) override = 0
Performs a multiplication operation and returns the result.
- Parameters
&element – is the element to multiply by.
- Returns
is the result of the multiplication.
-
virtual DerivedType &operator+=(const DerivedType &rhs) override = 0
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 DerivedType &operator-=(const DerivedType &rhs) override = 0
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 DerivedType &operator*=(const DerivedType &element) override = 0
Performs an multiplication operation and returns the result.
- Parameters
&element – is the element to multiply with.
- Returns
is the result of the multiplication.
-
virtual bool operator==(const DerivedType &rhs) const override = 0
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 = 0
Adds “1” to every entry in every tower.
-
virtual DerivedType AutomorphismTransform(uint32_t i) const override = 0
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 DerivedType AutomorphismTransform(uint32_t i, const std::vector<uint32_t> &vec) const override = 0
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.
-
inline virtual DerivedType Transpose() const final
Transpose the ring element using the automorphism operation.
- Returns
is the result of the transposition.
-
virtual DerivedType MultiplicativeInverse() const override = 0
Performs a multiplicative inverse operation and returns the result.
- Returns
is the result of the multiplicative inverse.
-
virtual DerivedType ModByTwo() const override = 0
Perform a modulus by 2 operation. Returns the least significant bit.
- Returns
is the resulting value.
-
virtual DerivedType Mod(const Integer &modulus) const override = 0
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 = 0
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 = 0
Convert from Coefficient to CRT or vice versa; calls FFT and inverse FFT.
See also
SetFormat(format) instead
Warning
use
-
virtual void OverrideFormat(const Format f) = 0
Sets format to value without calling FFT. Only use if you know what you’re doing.
-
virtual void MakeSparse(uint32_t wFactor) override = 0
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 IsEmpty() const override = 0
Returns true if ALL the tower(s) are empty.
- Returns
true if all towers are empty
-
virtual bool InverseExists() const override = 0
Determines if inverse exists.
- Returns
is the Boolean representation of the existence of multiplicative inverse.
-
virtual double Norm() const override = 0
Returns the infinity norm, basically the largest value in the ring element.
- Returns
is the largest value in the ring element.
-
virtual std::vector<DerivedType> BaseDecompose(usint baseBits, bool evalModeAnswer) const override = 0
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<DerivedType> PowersOfBase(usint baseBits) const override = 0
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
-
virtual void SetValues(const VecType &values, Format format) = 0
Set method that should not be used, will throw an error.
- Parameters
&values –
format –
-
virtual void SetValuesToZero() = 0
Sets all values of element to zero.
-
virtual void SetValuesToMax() = 0
-
inline DerivedType CRTInterpolate() const
Interpolates the DCRTPoly to an Poly based on the Chinese Remainder Transform Interpolation. and then returns a Poly with that single element.
- Returns
the interpolated ring element as a Poly object.
-
virtual PolyNative DecryptionCRTInterpolate(PlaintextModulus ptm) const = 0
-
virtual PolyNative ToNativePoly() const = 0
If the values are small enough this is used for efficiency.
Warning
This will be replaced with a non-member utility function.
- Returns
NativePoly
-
inline virtual DerivedType Clone() const final
Clone the object by making a copy of it and returning the copy.
- Returns
new Element
-
inline virtual DerivedType CloneEmpty() const final
Clone the object, but have it contain nothing.
- Returns
new Element
-
inline virtual DerivedType CloneParametersOnly() const final
Clones the element’s parameters, leaves vector initialized to 0.
- Returns
new Element
-
inline virtual DerivedType CloneWithNoise(const DggType &dgg, Format format) const final
Clones the element with parameters and with noise for the vector.
- Parameters
dgg –
format –
- Returns
new Element
-
inline const std::string GetElementName() const
Public Static Functions
Create lambda that allocates a zeroed element for the case when it is called from a templated class.
- Parameters
params – the params to use.
format – - EVALUATION or COEFFICIENT
Friends
-
inline friend std::ostream &operator<<(std::ostream &os, const DerivedType &vec)
ostream operator
- Parameters
os – the input preceding output stream
vec – the element to add to the output stream.
- Returns
a resulting concatenated output stream
-
inline friend DerivedType operator+(const DerivedType &a, const DerivedType &b)
Element-element addition operator.
- Parameters
a – first element to add.
b – second element to add.
- Returns
the result of the addition operation.
-
inline friend DerivedType operator+(const DerivedType &a, const Integer &b)
Element-integer addition operator.
- Parameters
a – first element to add.
b – integer to add.
- Returns
the result of the addition operation.
-
inline friend DerivedType operator+(const Integer &a, const DerivedType &b)
Integer-element addition operator.
- Parameters
a – integer to add.
b – element to add.
- Returns
the result of the addition operation.
-
inline friend DerivedType operator-(const DerivedType &a, const DerivedType &b)
Element-element subtraction operator.
- Parameters
a – element to subtract from.
b – element to subtract.
- Returns
the result of the subtraction operation.
-
inline friend DerivedType operator-(const DerivedType &a, const Integer &b)
Element-integer subtraction operator.
- Parameters
a – element to subtract from.
b – integer to subtract.
- Returns
the result of the subtraction operation.
-
inline friend DerivedType operator*(const DerivedType &a, const DerivedType &b)
Element-element multiplication operator.
- Parameters
a – element to multiply.
b – element to multiply.
- Returns
the result of the multiplication operation.
-
inline friend DerivedType operator*(const DerivedType &a, const Integer &b)
Element-integer multiplication operator.
- Parameters
a – element to multiply.
b – integer to multiply.
- Returns
the result of the multiplication operation.
-
inline friend DerivedType operator*(const Integer &a, const DerivedType &b)
Integer-element multiplication operator.
- Parameters
a – integer to multiply.
b – element to multiply.
- Returns
the result of the multiplication operation.
-
inline friend DerivedType operator*(const DerivedType &a, int64_t b)
Element-signed-integer multiplication operator.
- Parameters
a – element to multiply.
b – integer to multiply.
- Returns
the result of the multiplication operation.
-
inline friend DerivedType operator*(int64_t a, const DerivedType &b)
signed-Integer-element multiplication operator.
- Parameters
a – integer to multiply.
b – element to multiply.
- Returns
the result of the multiplication operation.
-
using Params = ILParamsImpl<Integer>