Template Class ILElement

Inheritance Relationships

Base Type

Derived Type

Template Parameter Order

  1. typename Element

  2. typename VecType

Class Documentation

template<typename Element, typename VecType>
class lbcrypto::ILElement : public lbcrypto::Serializable

Inheritence diagram for lbcrypto::ILElement:

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

Collaboration diagram for lbcrypto::ILElement:

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

Interface for ideal lattices.

Every lattice must implement these pure virtuals in order to properly interoperate with OpenFHE PKE. Element is the return type for all of these virtual functions. There is no constructor here in the base class; it contains no data to construct.

Subclassed by lbcrypto::PolyInterface< PolyImpl< VecType >, VecType, PolyImpl >

Public Functions

virtual Element Clone() const = 0

Clone the object by making a copy of it and returning the copy.

Returns

new Element

virtual Element CloneEmpty() const = 0

Clone the object, but have it contain nothing.

Returns

new Element

virtual Element CloneParametersOnly() const = 0

Clones the element’s parameters, leaves vector initialized to 0.

Returns

new Element

virtual Element CloneWithNoise(const DiscreteGaussianGeneratorImpl<VecType> &dgg, Format format) const = 0

Clones the element with parameters and with noise for the vector.

Parameters
  • dgg

  • format

Returns

new Element

virtual ~ILElement() = default

Standard destructor.

virtual const Element &operator=(const Element &rhs) = 0

Assignment operator that copies elements.

Parameters

rhs

virtual const Element &operator=(Element &&rhs) = 0

Assignment operator that copies elements.

Parameters

rhs

virtual const Element &operator=(std::initializer_list<uint64_t> rhs) = 0

Assignment operator that copies elements.

Parameters

rhs

virtual Format GetFormat() const = 0

Get format of the element.

Returns

Format is either COEFFICIENT or EVALUATION

virtual usint GetLength() const = 0

Get the length of the element.

Returns

length

virtual const IntType &GetModulus() const = 0

Get modulus of the element.

Returns

the modulus.

virtual const VecType &GetValues() const = 0

Get the values for the element.

Returns

the vector.

virtual usint GetCyclotomicOrder() const = 0

Get the cyclotomic order.

Returns

order

inline virtual IntType &at(usint i)

Gets the Value in the Element that is At Index and returns it. This is only implemented for some derived classes, so the default implementation throws an exception.

Parameters

i – is the index.

Returns

will throw an error.

inline virtual const IntType &at(usint i) const
inline virtual IntType &operator[](usint i)
inline virtual const IntType &operator[](usint i) const
virtual Element operator-() const = 0

Unary negation on a lattice.

Returns

-lattice

virtual Element Plus(const IntType &element) const = 0

Scalar addition - add an element to the first index only. This operation is only allowed in COEFFICIENT format.

Parameters

&element – is the element to add entry-wise.

Returns

is the return of the addition operation.

virtual Element Minus(const IntType &element) const = 0

Scalar subtraction - subtract an element frp, all entries.

Parameters

&element – is the element to subtract entry-wise.

Returns

is the return value of the minus operation.

virtual Element Times(const IntType &element) const = 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 Element Times(NativeInteger::SignedNativeInt element) const = 0

Scalar multiplication - mulltiply by a signed integer.

Parameters

&element – is the element to multiply entry-wise.

Returns

is the return value of the times operation.

virtual Element Plus(const Element &element) const = 0

Performs an addition operation and returns the result.

Parameters

&element – is the element to add with.

Returns

is the result of the addition.

virtual Element Minus(const Element &element) const = 0

Performs a subtraction operation and returns the result.

Parameters

&element – is the element to subtract with.

Returns

is the result of the subtraction.

virtual Element Times(const Element &element) const = 0

Performs a multiplication operation and returns the result.

Parameters

&element – is the element to multiply with.

Returns

is the result of the multiplication.

virtual const Element &operator+=(const IntType &element) = 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 const Element &operator-=(const IntType &element) = 0

Performs -= operation with a BigInteger and returns the result.

Parameters

&element – is the element to subtract

Returns

is the result of the addition.

virtual const Element &operator*=(const IntType &element) = 0

Performs *= operation with a BigInteger and returns the result.

Parameters

&element – is the element to multiply by

Returns

is the result of the multiplication.

virtual const Element &operator+=(const Element &element) = 0

Performs an addition operation and returns the result.

Parameters

&element – is the element to add

Returns

is the result of the addition.

virtual const Element &operator-=(const Element &element) = 0

Performs an subtraction operation and returns the result.

Parameters

&element – is the element to subtract

Returns

is the result of the addition.

virtual const Element &operator*=(const Element &element) = 0

Performs an multiplication operation and returns the result.

Parameters

&element – is the element to multiply by

Returns

is the result of the multiplication.

virtual bool operator==(const Element &element) const = 0

Equality operator. Compares values of element to be compared to.

Parameters

element – the element to compare to.

inline bool operator!=(const Element &element) const

Inequality operator. Compares values of element to be compared to.

Parameters

element – the element to compare to.

virtual void AddILElementOne() = 0

Adds one to every entry of the Element, in place.

virtual Element AutomorphismTransform(uint32_t i) const = 0

Performs an automorphism transform operation and returns the result.

Parameters

&i – is the element to perform the automorphism transform with.

Returns

is the result of the automorphism transform.

virtual Element AutomorphismTransform(uint32_t i, const std::vector<uint32_t> &vec) const = 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.

virtual Element Transpose() const = 0

Transpose the ring element using the automorphism operation.

Returns

is the result of the transposition.

virtual std::vector<Element> BaseDecompose(usint baseBits, bool evalModeAnswer) const = 0

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.

Parameters
  • baseBits – is the number of bits in the base, i.e., base = 2^baseBits

  • evalModeAnswer – - if true, convert the resultant polynomials to evaluation mode

Returns

is the pointer where the base decomposition vector is stored

virtual Element DivideAndRound(const IntType &q) const = 0

Scalar division followed by rounding operation - operation on all entries.

Parameters

&q – is the element to divide entry-wise.

Returns

is the return value of the divide, followed by rounding operation.

virtual bool InverseExists() const = 0

Determines if inverse exists.

Returns

true if there exists a multiplicative inverse.

virtual double Norm() const = 0

Returns the infinity norm, basically the largest value in the ring element.

Returns

the largest value in the ring element.

virtual bool IsEmpty() const = 0

Returns true if the vector is empty/ m_values==nullptr.

Returns

true if the vector is empty and all values nullptr. false otherwise.

virtual void MakeSparse(uint32_t wFactor) = 0

Make the element Sparse for SHE KeyGen operations. Sets every index not equal to zero mod the wFactor to zero.

Parameters

&wFactor – ratio between the original element’s ring dimension and the new ring dimension.

virtual Element ModByTwo() const = 0

Calculate Element mod 2.

Returns

result of performing a mod-2 operation on the element.

virtual Element MultiplicativeInverse() const = 0

Calculate and return the Multiplicative Inverse of the element.

Returns

the multiplicative inverse of the element, if it exists.

virtual Element MultiplyAndRound(const IntType &p, const IntType &q) const = 0

Scalar multiplication followed by division and rounding operation - operation on all entries.

Parameters
  • &p – is the integer muliplicand.

  • &q – is the integer divisor.

Returns

is the return value of the multiply, divide and followed by rounding operation.

virtual std::vector<Element> PowersOfBase(usint baseBits) const = 0

Calculate a vector of elements by raising the base element to successive powers.

Parameters

baseBits

Returns

virtual Element Mod(const IntType &modulus) const = 0

Mod - 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 IntType &modulus, const IntType &rootOfUnity, const IntType &modulusArb, const IntType &rootOfUnityArb) = 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() = 0

onvert from Coefficient to CRT or vice versa; calls FFT and inverse FFT.

inline void SetFormat(const Format format)

Sets the format/representation of the element.

Parameters

format – the format/representation to set.