Template Class AdvancedSHEBase

Template Parameter Order

  1. class Element

Class Documentation

template<class Element>
class lbcrypto::AdvancedSHEBase

Abstract base class for derived HE algorithms.

Template Parameters

Element – a ring element.

Public Functions

inline virtual ~AdvancedSHEBase()
virtual Ciphertext<Element> EvalAddMany(const std::vector<Ciphertext<Element>> &ciphertextVec) const

Virtual function for evaluating addition of a list of ciphertexts.

Parameters

ciphertextVec

Returns

virtual Ciphertext<Element> EvalAddManyInPlace(std::vector<Ciphertext<Element>> &ciphertextVec) const

Virtual function for evaluating addition of a list of ciphertexts. This version uses no additional space, other than the vector provided.

Parameters
  • ciphertextVec – is the ciphertext list.

  • *newCiphertext – the new resulting ciphertext.

virtual Ciphertext<Element> EvalMultMany(const std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<EvalKey<Element>> &evalKeyVec) const

Virtual function for evaluating multiplication of a ciphertext list which each multiplication is followed by relinearization operation.

Parameters
  • cipherTextList – is the ciphertext list.

  • evalKeys – is the evaluation key to make the newCiphertext decryptable by the same secret key as that of ciphertext list.

  • *newCiphertext – the new resulting ciphertext.

inline virtual Ciphertext<Element> EvalLinearWSum(std::vector<ConstCiphertext<Element>> &ciphertextVec, const std::vector<double> &weights) const

Virtual function for computing the linear weighted sum of a vector of ciphertexts.

Parameters
  • ciphertexts – vector of input ciphertexts.

  • constants – vector containing double weights.

Returns

A ciphertext containing the linear weighted sum.

inline virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<double> &weights) const

Function for computing the linear weighted sum of a vector of ciphertexts. This is a mutable method, meaning that the level/depth of input ciphertexts may change.

Parameters
  • ciphertexts – vector of input ciphertexts.

  • constants – vector containing double weights.

Returns

A ciphertext containing the linear weighted sum.

inline virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients) const

Method for polynomial evaluation for polynomials represented in the power series. This uses a binary tree computation of the polynomial powers.

Parameters
  • &cipherText – input ciphertext

  • &coefficients – is the vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial + 1

Returns

the result of polynomial evaluation.

inline virtual Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients) const

Method for polynomial evaluation for polynomials represented in the power series. This uses a binary tree computation of the polynomial powers.

Parameters
  • &cipherText – input ciphertext

  • &coefficients – is the vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial + 1

Returns

the result of polynomial evaluation.

inline virtual Ciphertext<Element> EvalPolyPS(ConstCiphertext<Element> x, const std::vector<double> &coefficients) const
inline virtual Ciphertext<Element> EvalChebyshevSeries(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients, double a, double b) const

Method for evaluating Chebyshev polynomial interpolation; first the range [a,b] is mapped to [-1,1] using linear transformation 1 + 2 (x-a)/(b-a) If the degree of the polynomial is less than 5, use EvalChebyshevSeriesLinear, otherwise, use EvalChebyshevSeriesPS.

Parameters
  • &cipherText – input ciphertext

  • &coefficients – is the vector of coefficients in Chebyshev expansion

  • a – - lower bound of argument for which the coefficients were found

  • b – - upper bound of argument for which the coefficients were found

Returns

the result of polynomial evaluation.

inline virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients, double a, double b) const
inline virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients, double a, double b) const
virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalSumKeyGen(const PrivateKey<Element> privateKey, const PublicKey<Element> publicKey) const

Virtual function to generate the automorphism keys for EvalSum; works only for packed encoding

Parameters

privateKey – private key.

Returns

returns the evaluation keys

virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalSumRowsKeyGen(const PrivateKey<Element> privateKey, const PublicKey<Element> publicKey, usint rowSize, usint subringDim) const

Virtual function to generate the automorphism keys for EvalSumRows; works only for packed encoding

Parameters
  • privateKey – private key.

  • publicKey – public key.

  • rowSize – size of rows in the matrix

  • subringDim – subring dimension (set to cyclotomic order if set to 0)

Returns

returns the evaluation keys

virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalSumColsKeyGen(const PrivateKey<Element> privateKey, const PublicKey<Element> publicKey) const

Virtual function to generate the automorphism keys for EvalSumCols; works only for packed encoding

Parameters
  • privateKey – private key.

  • publicKey – public key.

Returns

returns the evaluation keys

virtual Ciphertext<Element> EvalSum(ConstCiphertext<Element> ciphertext, usint batchSize, const std::map<usint, EvalKey<Element>> &evalSumKeyMap) const

Sums all elements in log (batch size) time - works only with packed encoding

Parameters
  • ciphertext – the input ciphertext.

  • batchSize – size of the batch to be summed up

  • &evalKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.

Returns

resulting ciphertext

virtual Ciphertext<Element> EvalSumRows(ConstCiphertext<Element> ciphertext, usint rowSize, const std::map<usint, EvalKey<Element>> &evalSumRowsKeyMap, usint subringDim) const

Sums all elements over row-vectors in a matrix - works only with packed encoding

Parameters
  • ciphertext – the input ciphertext.

  • rowSize – size of rows in the matrix

  • &evalKeys – - reference to the map of evaluation keys generated by

  • subringDim – the current cyclotomic order/subring dimension. If set to 0, we use the full cyclotomic order. EvalAutomorphismKeyGen.

Returns

resulting ciphertext

virtual Ciphertext<Element> EvalSumCols(ConstCiphertext<Element> ciphertext, usint batchSize, const std::map<usint, EvalKey<Element>> &evalSumColsKeyMap, const std::map<usint, EvalKey<Element>> &rightEvalKeys) const

Sums all elements over column-vectors in a matrix - works only with packed encoding

Parameters
  • ciphertext – the input ciphertext.

  • rowSize – size of rows in the matrixs

  • &evalKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.

Returns

resulting ciphertext

virtual Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2, usint batchSize, const std::map<usint, EvalKey<Element>> &evalKeyMap, const EvalKey<Element> evalMultKey) const

Evaluates inner product in batched encoding

Parameters
  • ciphertext1 – first vector.

  • ciphertext2 – second vector.

  • batchSize – size of the batch to be summed up

  • &evalSumKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.

  • &evalMultKey – - reference to the evaluation key generated by EvalMultKeyGen.

Returns

resulting ciphertext

virtual Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext, usint batchSize, const std::map<usint, EvalKey<Element>> &evalKeyMap) const

Evaluates inner product in batched encoding

Parameters
  • ciphertext1 – first vector.

  • plaintext – plaintext.

  • batchSize – size of the batch to be summed up

  • &evalSumKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.

  • &evalMultKey – - reference to the evaluation key generated by EvalMultKeyGen.

Returns

resulting ciphertext

virtual Ciphertext<Element> AddRandomNoise(ConstCiphertext<Element> ciphertext) const

Function to add random noise to all plaintext slots except for the first one; used in EvalInnerProduct

Parameters

&ciphertext – the input ciphertext.

Returns

modified ciphertext

virtual Ciphertext<Element> EvalMerge(const std::vector<Ciphertext<Element>> &ciphertextVector, const std::map<usint, EvalKey<Element>> &evalKeyMap) const

Merges multiple ciphertexts with encrypted results in slot 0 into a single ciphertext The slot assignment is done based on the order of ciphertexts in the vector

Parameters
  • ciphertextVector – vector of ciphertexts to be merged.

  • &evalKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.

Returns

resulting ciphertext

Protected Functions

std::vector<usint> GenerateIndices_2n(usint batchSize, usint m) const
std::vector<usint> GenerateIndices2nComplex(usint batchSize, usint m) const
std::vector<usint> GenerateIndices2nComplexRows(usint rowSize, usint m) const
std::vector<usint> GenerateIndices2nComplexCols(usint batchSize, usint m) const
Ciphertext<Element> EvalSum_2n(ConstCiphertext<Element> ciphertext, usint batchSize, usint m, const std::map<usint, EvalKey<Element>> &evalKeyMap) const
Ciphertext<Element> EvalSum2nComplex(ConstCiphertext<Element> ciphertext, usint batchSize, usint m, const std::map<usint, EvalKey<Element>> &evalKeyMap) const
Ciphertext<Element> EvalSum2nComplexRows(ConstCiphertext<Element> ciphertext, usint rowSize, usint m, const std::map<usint, EvalKey<Element>> &evalKeyMap) const
Ciphertext<Element> EvalSum2nComplexCols(ConstCiphertext<Element> ciphertext, usint batchSize, usint m, const std::map<usint, EvalKey<Element>> &evalKeyMap) const