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 interface for the advanced SHE operations built on top of the leveled SHE primitives: multi-operand additions and multiplications, linear weighted sums, polynomial and Chebyshev series evaluation, EvalSum over packed slots (all slots, rows or columns), inner products and merging.
- 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 – is the ciphertext list.
- Returns
the new resulting ciphertext.
-
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 (modified in place to store intermediate results).
- Returns
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
ciphertextVec – is the ciphertext list.
evalKeyVec – are the evaluation keys to make the new ciphertext decryptable by the same secret key as that of ciphertext list.
- Returns
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
ciphertextVec – vector of input ciphertexts.
weights – vector containing the 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
Virtual function for computing the linear weighted sum of a vector of ciphertexts with real weights (CKKS).
- Parameters
ciphertextVec – vector of input ciphertexts.
weights – vector containing the weights.
- Returns
A ciphertext containing the linear weighted sum.
-
inline virtual Ciphertext<Element> EvalLinearWSum(std::vector<ReadOnlyCiphertext<Element>> &ciphertextVec, const std::vector<std::complex<double>> &weights) const
Virtual function for computing the linear weighted sum of a vector of ciphertexts with complex weights (CKKS).
- Parameters
ciphertextVec – vector of input ciphertexts.
weights – vector containing the weights.
- Returns
A ciphertext containing the linear weighted sum.
-
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
ciphertextVec – vector of input ciphertexts.
weights – vector containing the 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 with real weights (CKKS). This is a mutable method, meaning that the level/depth of input ciphertexts may change.
- Parameters
ciphertextVec – vector of input ciphertexts.
weights – vector containing the weights.
- Returns
A ciphertext containing the linear weighted sum.
-
inline virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<std::complex<double>> &weights) const
Function for computing the linear weighted sum of a vector of ciphertexts with complex weights (CKKS). This is a mutable method, meaning that the level/depth of input ciphertexts may change.
- Parameters
ciphertextVec – vector of input ciphertexts.
weights – vector containing the weights.
- Returns
A ciphertext containing the linear weighted sum.
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalPowers(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 represented in the power series. Uses a binary tree computation of the powers for low polynomial degrees (degree < 5), or the Paterson-Stockmeyer power basis 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 std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients) const
Method for computing the powers of a ciphertext to be used when evaluating a polynomial represented in the power series with real coefficients; see the int64_t overload for the algorithm.
- 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 std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients) const
Method for computing the powers of a ciphertext to be used when evaluating a polynomial represented in the power series with complex coefficients; see the int64_t overload for the algorithm.
- 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<int64_t> &coefficients) const
Method for polynomial evaluation for polynomials represented in the power series. Uses EvalPolyLinear() for low polynomial degrees (degree < 5), or EvalPolyPS() 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 result of polynomial evaluation.
-
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 with real coefficients. Uses EvalPolyLinear() for low polynomial degrees (degree < 5), or EvalPolyPS() 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 result of polynomial evaluation.
-
inline virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients) const
Method for polynomial evaluation for polynomials represented in the power series with complex coefficients. Uses EvalPolyLinear() for low polynomial degrees (degree < 5), or EvalPolyPS() 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 result of polynomial evaluation.
Method for evaluating a polynomial with integer coefficients in the power basis from the powers precomputed by EvalPowers, so that several polynomials can be evaluated on the same input.
- Parameters
powers – the powers of the input ciphertext returned by EvalPowers (computed for a polynomial of at least the same degree and, for degree < 5, the same sparsity pattern of the coefficients).
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.
Method for evaluating a polynomial with real coefficients in the power basis from the powers precomputed by EvalPowers, so that several polynomials can be evaluated on the same input.
- Parameters
powers – the powers of the input ciphertext returned by EvalPowers (computed for a polynomial of at least the same degree and, for degree < 5, the same sparsity pattern of the coefficients).
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.
Method for evaluating a polynomial with complex coefficients in the power basis from the powers precomputed by EvalPowers, so that several polynomials can be evaluated on the same input.
- Parameters
powers – the powers of the input ciphertext returned by EvalPowers (computed for a polynomial of at least the same degree and, for degree < 5, the same sparsity pattern of the coefficients).
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<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
Method for polynomial evaluation for polynomials represented in the power series with real coefficients. 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<std::complex<double>> &coefficients) const
Method for polynomial evaluation for polynomials represented in the power series with complex coefficients. 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<int64_t> &coefficients) const
Method for polynomial evaluation for polynomials represented in the power series. This uses the Paterson-Stockmeyer algorithm.
- Parameters
x – 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
Method for polynomial evaluation for polynomials represented in the power series with real coefficients. This uses the Paterson-Stockmeyer algorithm.
- Parameters
x – 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<std::complex<double>> &coefficients) const
Method for polynomial evaluation for polynomials represented in the power series with complex coefficients. This uses the Paterson-Stockmeyer algorithm.
- Parameters
x – 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>> 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. Uses a binary tree computation of the Chebyshev polynomials for low degrees (degree < 5), or the Paterson-Stockmeyer Chebyshev basis for higher degrees.
- Parameters
ciphertext – input ciphertext
coefficients – is the vector of coefficients in the Chebyshev series; 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 resulting data structure of Chebyshev polynomials.
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients, double a, double b) const
Method for computing the Chebyshev polynomials to be used in polynomial interpolation via the Chebyshev series with real coefficients; see the int64_t overload for the algorithm.
- Parameters
ciphertext – input ciphertext
coefficients – is the vector of coefficients in the Chebyshev series; 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 resulting data structure of Chebyshev polynomials.
-
inline virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients, double a, double b) const
Method for computing the Chebyshev polynomials to be used in polynomial interpolation via the Chebyshev series with complex coefficients; see the int64_t overload for the algorithm.
- Parameters
ciphertext – input ciphertext
coefficients – is the vector of coefficients in the Chebyshev series; 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 resulting data structure of Chebyshev polynomials.
-
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
Method for evaluating Chebyshev polynomial interpolation with real coefficients; 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<std::complex<double>> &coefficients, double a, double b) const
Method for evaluating Chebyshev polynomial interpolation with complex coefficients; 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.
Method for evaluating a Chebyshev series with integer coefficients from the Chebyshev polynomials precomputed by EvalChebyPolys, so that several series can be evaluated on the same input.
- Parameters
polys – the Chebyshev polynomials of the input ciphertext returned by EvalChebyPolys (computed for a series of at least the same degree and, for degree < 5, the same sparsity of the coefficients).
coefficients – is the vector of coefficients in Chebyshev expansion
- Returns
the result of polynomial evaluation.
Method for evaluating a Chebyshev series with real coefficients from the Chebyshev polynomials precomputed by EvalChebyPolys, so that several series can be evaluated on the same input.
- Parameters
polys – the Chebyshev polynomials of the input ciphertext returned by EvalChebyPolys (computed for a series of at least the same degree and, for degree < 5, the same sparsity of the coefficients).
coefficients – is the vector of coefficients in Chebyshev expansion
- Returns
the result of polynomial evaluation.
Method for evaluating a Chebyshev series with complex coefficients from the Chebyshev polynomials precomputed by EvalChebyPolys, so that several series can be evaluated on the same input.
- Parameters
polys – the Chebyshev polynomials of the input ciphertext returned by EvalChebyPolys (computed for a series of at least the same degree and, for degree < 5, the same sparsity of the coefficients).
coefficients – is the vector of coefficients in Chebyshev expansion
- Returns
the result of polynomial evaluation.
-
inline virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients, double a, double b) const
Method for evaluating a Chebyshev series with integer coefficients of degree less than 5 using a binary tree computation of the Chebyshev polynomials, after mapping the range [a,b] to [-1,1].
- 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
Method for evaluating a Chebyshev series with real coefficients of degree less than 5 using a binary tree computation of the Chebyshev polynomials, after mapping the range [a,b] to [-1,1].
- 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<std::complex<double>> &coefficients, double a, double b) const
Method for evaluating a Chebyshev series with complex coefficients of degree less than 5 using a binary tree computation of the Chebyshev polynomials, after mapping the range [a,b] to [-1,1].
- 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> EvalChebyshevSeriesPS(ConstCiphertext<Element> &ciphertext, const std::vector<int64_t> &coefficients, double a, double b) const
Method for evaluating a Chebyshev series with integer coefficients using the Paterson-Stockmeyer algorithm in the Chebyshev basis, after mapping the range [a,b] to [-1,1].
- 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> EvalChebyshevSeriesPS(ConstCiphertext<Element> &ciphertext, const std::vector<double> &coefficients, double a, double b) const
Method for evaluating a Chebyshev series with real coefficients using the Paterson-Stockmeyer algorithm in the Chebyshev basis, after mapping the range [a,b] to [-1,1].
- 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> EvalChebyshevSeriesPS(ConstCiphertext<Element> &ciphertext, const std::vector<std::complex<double>> &coefficients, double a, double b) const
Method for evaluating a Chebyshev series with complex coefficients using the Paterson-Stockmeyer algorithm in the Chebyshev basis, after mapping the range [a,b] to [-1,1].
- 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.
-
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.
rowSize – size of rows in the matrix
subringDim – subring dimension (set to cyclotomic order if set to 0)
indices – automorphism indices to generate keys for; the indices needed for EvalSumRows are appended to it
- 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.
indices – automorphism indices to generate keys for; the indices needed for EvalSumCols and EvalSum are appended to it
- 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 packed encoding.
- Parameters
ciphertext – the input ciphertext.
batchSize – size of the batch to be summed up
evalSumKeyMap – - reference to the map of evaluation keys generated by EvalSumKeyGen.
- 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 EvalSumRowsKeyGen.
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 matrix
evalSumKeys – - reference to the map of evaluation keys generated by EvalSumKeyGen.
rightEvalKeys – - reference to the map of evaluation keys generated by EvalSumColsKeyGen.
- 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
evalKeyMap – - reference to the map of evaluation keys generated by EvalSumKeyGen.
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
evalKeyMap – - reference to the map of evaluation keys generated by EvalSumKeyGen.
- 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.
evalKeyMap – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.
- Returns
resulting ciphertext
Protected Functions
-
Ciphertext<Element> EvalSumRadixFold(ConstCiphertext<Element> &ciphertext, uint32_t g0, uint32_t size, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Radix-configured EvalSum rotation fold (compile-time PARTIAL_SUM_RADIX): per level, one hoisted digit decomposition is shared by the level’s up to radix-1 automorphisms of the running sum. Generator g0 selects the flavor (5, 5^rowSize, or 5^-1 mod m); covers size slots. Power-of-two m only.
- Parameters
ciphertext – the input ciphertext.
g0 – generator of the automorphism group used by the fold (5, 5^rowSize or 5^-1 mod m).
size – the number of slots the fold covers.
m – the cyclotomic order (power of two).
evalKeyMap – the map of automorphism keys, containing the indices of GenerateEvalSumIndices.
- Returns
the ciphertext with the partial sums.
-
Ciphertext<Element> EvalSum_2n(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Sums batchSize slots of a ciphertext with real (BGV/BFV) packing in a power-of-two cyclotomic ring: the radix fold generated by 5, followed by the addition of the conjugate (automorphism m-1) when the batch spans both halves of the slots (2*batchSize == m).
- Parameters
ciphertext – the input ciphertext.
batchSize – the number of slots to be summed.
m – the cyclotomic order.
evalKeyMap – the map of automorphism keys generated with GenerateIndices_2n.
- Returns
the ciphertext with the sum in every slot.
-
Ciphertext<Element> EvalSum2nComplex(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Sums batchSize slots of a ciphertext with CKKS packing: the radix fold generated by 5.
- Parameters
ciphertext – the input ciphertext.
batchSize – the number of slots to be summed.
m – the cyclotomic order.
evalKeyMap – the map of automorphism keys generated with GenerateIndices2nComplex.
- Returns
the ciphertext with the sum in every slot.
-
Ciphertext<Element> EvalSum2nComplexRows(ConstCiphertext<Element> ciphertext, uint32_t rowSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Sums the rows of a matrix with rowSize columns packed in CKKS slots: the radix fold generated by 5^rowSize mod m over the m/(4*rowSize) rows.
- Parameters
ciphertext – the input ciphertext.
rowSize – the number of columns of the matrix (size of a row).
m – the cyclotomic order (or subring dimension).
evalKeyMap – the map of automorphism keys generated with GenerateIndices2nComplexRows.
- Returns
the ciphertext with the row sums.
-
Ciphertext<Element> EvalSum2nComplexCols(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Sums over the columns of a matrix packed in CKKS slots: the radix fold generated by 5^-1 mod m over batchSize slots.
- Parameters
ciphertext – the input ciphertext.
batchSize – the number of slots to be summed.
m – the cyclotomic order.
evalKeyMap – the map of automorphism keys generated with GenerateIndices2nComplexCols.
- Returns
the ciphertext with the column sums.
Protected Static Functions
-
static std::set<uint32_t> GenerateIndices_2n(uint32_t batchSize, uint32_t m)
Automorphism indices needed by EvalSum for real (BGV/BFV) packing in a power-of-two cyclotomic ring: the radix fold generated by 5 over batchSize slots when 2*batchSize < m, otherwise the fold over batchSize/2 slots plus the index m-1 (the conjugation that adds the two halves of the slots).
- Parameters
batchSize – the number of slots to be summed.
m – the cyclotomic order.
- Returns
the set of automorphism indices.
-
static std::set<uint32_t> GenerateIndices2nComplex(uint32_t batchSize, uint32_t m)
Automorphism indices needed by EvalSum for CKKS packing in a power-of-two cyclotomic ring: the radix fold generated by 5 over batchSize slots.
- Parameters
batchSize – the number of slots to be summed.
m – the cyclotomic order.
- Returns
the set of automorphism indices.
-
static std::set<uint32_t> GenerateIndices2nComplexRows(uint32_t rowSize, uint32_t m)
Automorphism indices needed by EvalSumRows for CKKS packing: the radix fold generated by 5^rowSize mod m over the m/(4*rowSize) rows of the matrix.
- Parameters
rowSize – the number of columns of the matrix (size of a row).
m – the cyclotomic order (or subring dimension).
- Returns
the set of automorphism indices.
-
static std::set<uint32_t> GenerateIndices2nComplexCols(uint32_t batchSize, uint32_t m)
Automorphism indices needed by EvalSumCols for CKKS packing: the radix fold generated by 5^-1 mod m over batchSize slots.
- Parameters
batchSize – the number of slots to be summed.
m – the cyclotomic order.
- Returns
the set of automorphism indices.
-
static std::set<uint32_t> GenerateEvalSumIndices(uint32_t g0, uint32_t size, uint32_t m)
Automorphism-index set of the radix-configured EvalSum fold (compile-time PARTIAL_SUM_RADIX): {g0^(i*radix^level) mod m : i in [1, radix)}, bounded so the fold covers size slots. Power-of-two m only.
- Parameters
g0 – generator of the automorphism group used by the fold (5, 5^rowSize or 5^-1 mod m).
size – the number of slots the fold covers.
m – the cyclotomic order (power of two).
- Returns
the set of automorphism indices.
-
static std::set<uint32_t> GenerateIndexListForEvalSum(const PrivateKey<Element> &privateKey)
Automorphism indices needed by EvalSum for the batch size and cyclotomic order of the crypto parameters of the private key: GenerateIndices2nComplex (CKKS) or GenerateIndices_2n for power-of-two cyclotomics, and the successive squares of the plaintext generator for arbitrary cyclotomics.
- Parameters
privateKey – the private key the EvalSum keys are generated for.
- Returns
the set of automorphism indices.