Template Class AdvancedSHEBase
Defined in File base-advancedshe.h
Page Contents
Template Parameter Order
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
-
virtual ~AdvancedSHEBase() = default
-
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<ReadOnlyCiphertext<Element>> &ciphertextVec, const std::vector<int64_t> &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> EvalLinearWSum(std::vector<ReadOnlyCiphertext<Element>> &ciphertextVec, const std::vector<double> &weights) const
-
inline virtual Ciphertext<Element> EvalLinearWSum(std::vector<ReadOnlyCiphertext<Element>> &ciphertextVec, const std::vector<std::complex<double>> &weights) const
-
inline virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<int64_t> &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> EvalLinearWSumMutable(std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<double> &weights) const
-
inline virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<std::complex<double>> &weights) const
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients) const
Method for computing the powers 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 std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients) const
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients) const
-
inline virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients) const
Method for computing the powers of a ciphertext to be used when evaluating a polynomial. Uses EvalPowersLinear() for low polynomial degrees (degree < 5), or EvalPowersPS() for higher degrees.
- 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 resulting data structure of powers.
-
inline virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients) const
-
inline virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients) const
-
inline virtual Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &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
-
inline virtual Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients) const
-
inline virtual Ciphertext<Element> EvalPolyPS(ConstCiphertext<Element> &x, const std::vector<int64_t> &coefficients) const
Method for polynomial evaluation for polynomials represented in the power series. This uses the Paterson-Stockmeyer algorith,.
- 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> EvalPolyPS(ConstCiphertext<Element> &x, const std::vector<std::complex<double>> &coefficients) const
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients, double a, double b) const
Method for computing the Chebyshev polynomials to be used in polynomial interpolation via the Chebyshev series. This uses a binary tree computation of the Chebyshev polynomials.
- 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
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 std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients, double a, double b) const
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeries(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &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> EvalChebyshevSeries(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeries(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients, double a, double b) const
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients, double a, double b) const
-
virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalSumKeyGen(const PrivateKey<Element> privateKey) 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<uint32_t, EvalKey<Element>>> EvalSumRowsKeyGen(const PrivateKey<Element> privateKey, uint32_t rowSize, uint32_t subringDim, std::vector<uint32_t> &indices) 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<uint32_t, EvalKey<Element>>> EvalSumColsKeyGen(const PrivateKey<Element> privateKey, std::vector<uint32_t> &indices) 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, uint32_t batchSize, const std::map<uint32_t, EvalKey<Element>> &evalSumKeyMap) const
Sums all elements in log (batch size) time - works only with packedvencoding.
- 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, uint32_t numRows, const std::map<uint32_t, EvalKey<Element>> &evalSumKeys, uint32_t subringDim) const
Sums all elements over row-vectors in a matrix - works only with packed encoding.
- Parameters
ciphertext – the input ciphertext.
numRows – number of rows in the matrix
evalSumKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.
subringDim – the current cyclotomic order/subring dimension. If set to 0, we use the full cyclotomic order.
- Returns
resulting ciphertext
-
virtual Ciphertext<Element> EvalSumCols(ConstCiphertext<Element> ciphertext, uint32_t numCols, const std::map<uint32_t, EvalKey<Element>> &evalSumKeys, const std::map<uint32_t, EvalKey<Element>> &rightEvalKeys) const
Sums all elements over column-vectors in a matrix - works only with packed encoding. The code is implemented according to the specifications in https://eprint.iacr.org/2018/662.pdf.
- Parameters
ciphertext – the input ciphertext.
numCols – number of columns in the matrixs
evalSumKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.
rightEvalKeys – - reference to the map of
- Returns
resulting ciphertext
-
virtual Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2, uint32_t batchSize, const std::map<uint32_t, 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, uint32_t batchSize, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Evaluates inner product in batched encoding.
- Parameters
ciphertext – first vector.
plaintext – plaintext.
batchSize – size of the batch to be summed up
evalSumKeys – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.
- 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<uint32_t, 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::set<uint32_t> GenerateIndices_2n(uint32_t batchSize, uint32_t m) const
-
std::set<uint32_t> GenerateIndices2nComplex(uint32_t batchSize, uint32_t m) const
-
std::set<uint32_t> GenerateIndices2nComplexRows(uint32_t rowSize, uint32_t m) const
-
std::set<uint32_t> GenerateIndices2nComplexCols(uint32_t batchSize, uint32_t m) const
-
std::set<uint32_t> GenerateIndexListForEvalSum(const PrivateKey<Element> &privateKey) const
-
Ciphertext<Element> EvalSum_2n(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
-
Ciphertext<Element> EvalSum2nComplex(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
-
Ciphertext<Element> EvalSum2nComplexRows(ConstCiphertext<Element> ciphertext, uint32_t rowSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
-
Ciphertext<Element> EvalSum2nComplexCols(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const