Template Class LeveledSHEBase
Defined in File base-leveledshe.h
Page Contents
Template Parameter Order
class Element
Class Documentation
-
template<class Element>
class lbcrypto::LeveledSHEBase Abstract interface class for LBC SHE algorithms.
- Template Parameters
Element – a ring element.
Public Functions
-
virtual ~LeveledSHEBase() = default
-
virtual Ciphertext<Element> EvalNegate(ConstCiphertext<Element> &ciphertext) const
Virtual function to define the homomorphic negation of ciphertext.
- Parameters
ciphertext – the input ciphertext.
- Returns
new ciphertext.
-
virtual void EvalNegateInPlace(Ciphertext<Element> &ciphertext) const
Virtual function to define the interface for in-place homomorphic negation of ciphertext.
- Parameters
ciphertext – the input/output ciphertext.
-
virtual Ciphertext<Element> EvalAdd(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Virtual function to define the interface for homomorphic addition of ciphertexts.
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
- Returns
the new ciphertext.
-
virtual void EvalAddInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Virtual function to define the interface for in-place homomorphic addition of ciphertexts.
- Parameters
ciphertext1 – the input/output ciphertext.
ciphertext2 – the input ciphertext.
-
inline virtual Ciphertext<Element> EvalAddMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Virtual function to define the interface for homomorphic addition of ciphertexts. This is the mutable version - input ciphertexts may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
- Returns
the new ciphertext.
-
inline virtual void EvalAddMutableInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Virtual function to define the interface for in-place homomorphic addition of ciphertexts. This is the mutable version - input ciphertexts may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – the input/output ciphertext.
ciphertext2 – the input ciphertext.
-
virtual Ciphertext<Element> EvalAdd(ConstCiphertext<Element> &ciphertext, ConstPlaintext &plaintext) const
Virtual function to define the interface for homomorphic addition of ciphertexts.
- Parameters
ciphertext – the input ciphertext.
plaintext – the input plaintext.
- Returns
the new ciphertext.
-
virtual void EvalAddInPlace(Ciphertext<Element> &ciphertext, ConstPlaintext &plaintext) const
Virtual function to define the interface for in-place homomorphic addition of a ciphertext and a plaintext.
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the input plaintext.
-
inline virtual Ciphertext<Element> EvalAddMutable(Ciphertext<Element> &ciphertext, Plaintext &plaintext) const
Virtual function to define the interface for homomorphic addition of ciphertexts. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input ciphertext.
plaintext – the input plaintext.
- Returns
the new ciphertext.
-
inline virtual void EvalAddMutableInPlace(Ciphertext<Element> &ciphertext, Plaintext &plaintext) const
Virtual function to define the interface for in-place homomorphic addition of a ciphertext and a plaintext. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the input plaintext.
-
inline virtual Ciphertext<Element> EvalAdd(ConstCiphertext<Element> &ciphertext, NativeInteger scalar) const
Virtual function to define the interface for homomorphic addition of an integer scalar to a ciphertext. Not implemented by any of the current schemes; the base implementation throws NOT_IMPLEMENTED_ERROR.
- Parameters
ciphertext – the input ciphertext.
scalar – the integer scalar to add.
- Returns
the new ciphertext.
-
inline virtual void EvalAddInPlace(Ciphertext<Element> &ciphertext, NativeInteger scalar) const
Virtual function to define the interface for in-place homomorphic addition of an integer scalar to a ciphertext. Not implemented by any of the current schemes; the base implementation throws NOT_IMPLEMENTED_ERROR.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the integer scalar to add.
-
inline virtual Ciphertext<Element> EvalAdd(ConstCiphertext<Element> &ciphertext, double scalar) const
Adds a real constant to every slot of a ciphertext (CKKS): the constant is scaled by the scaling factor of the ciphertext and added to its first element.
- Parameters
ciphertext – the input ciphertext.
scalar – the real constant to add.
- Returns
the new ciphertext.
-
inline virtual void EvalAddInPlace(Ciphertext<Element> &ciphertext, double scalar) const
In-place addition of a real constant to every slot of a ciphertext (CKKS): the constant is scaled by the scaling factor of the ciphertext and added to its first element.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the real constant to add.
-
inline virtual Ciphertext<Element> EvalAdd(ConstCiphertext<Element> &ciphertext, std::complex<double> scalar) const
Adds a complex constant to every slot of a ciphertext (CKKS): the constant is scaled by the scaling factor of the ciphertext and added to its first element.
- Parameters
ciphertext – the input ciphertext.
scalar – the complex constant to add.
- Returns
the new ciphertext.
-
inline virtual void EvalAddInPlace(Ciphertext<Element> &ciphertext, std::complex<double> scalar) const
In-place addition of a complex constant to every slot of a ciphertext (CKKS): the constant is scaled by the scaling factor of the ciphertext and added to its first element.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the complex constant to add.
-
virtual Ciphertext<Element> EvalSub(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Virtual function to define the interface for homomorphic subtraction of ciphertexts.
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
- Returns
the new ciphertext.
-
virtual void EvalSubInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Virtual function to define the interface for homomorphic subtraction of ciphertexts.
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
-
inline virtual Ciphertext<Element> EvalSubMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Virtual function to define the interface for homomorphic subtraction of ciphertexts. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
- Returns
the new ciphertext.
-
inline virtual void EvalSubMutableInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Virtual function to define the interface for in-place homomorphic subtraction of ciphertexts. This is the mutable version - input ciphertexts may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – the input/output ciphertext.
ciphertext2 – the input ciphertext.
-
virtual Ciphertext<Element> EvalSub(ConstCiphertext<Element> &ciphertext, ConstPlaintext &plaintext) const
Virtual function to define the interface for homomorphic subtraction of ciphertexts.
- Parameters
ciphertext – the input ciphertext.
plaintext – the input plaintext.
- Returns
the new ciphertext.
-
virtual void EvalSubInPlace(Ciphertext<Element> &ciphertext, ConstPlaintext &plaintext) const
Virtual function to define the interface for in-place homomorphic subtraction of a plaintext from a ciphertext.
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the input plaintext.
-
inline virtual Ciphertext<Element> EvalSubMutable(Ciphertext<Element> &ciphertext, Plaintext &plaintext) const
Virtual function to define the interface for homomorphic subtraction of ciphertexts. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input ciphertext.
plaintext – the input plaintext.
- Returns
the new ciphertext.
-
inline virtual void EvalSubMutableInPlace(Ciphertext<Element> &ciphertext, Plaintext &plaintext) const
Virtual function to define the interface for in-place homomorphic subtraction of a plaintext from a ciphertext. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the input plaintext.
-
inline virtual Ciphertext<Element> EvalSub(ConstCiphertext<Element> &ciphertext, NativeInteger scalar) const
Virtual function to define the interface for homomorphic subtraction of an integer scalar from a ciphertext. Not implemented by any of the current schemes; the base implementation throws NOT_IMPLEMENTED_ERROR.
- Parameters
ciphertext – the input ciphertext.
scalar – the integer scalar to subtract.
- Returns
the new ciphertext.
-
inline virtual void EvalSubInPlace(Ciphertext<Element> &ciphertext, NativeInteger scalar) const
Virtual function to define the interface for in-place homomorphic subtraction of an integer scalar from a ciphertext. Not implemented by any of the current schemes; the base implementation throws NOT_IMPLEMENTED_ERROR.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the integer scalar to subtract.
-
inline virtual Ciphertext<Element> EvalSub(ConstCiphertext<Element> &ciphertext, double scalar) const
Subtracts a real constant from every slot of a ciphertext (CKKS): the constant is scaled by the scaling factor of the ciphertext and subtracted from its first element.
- Parameters
ciphertext – the input ciphertext.
scalar – the real constant to subtract.
- Returns
the new ciphertext.
-
inline virtual void EvalSubInPlace(Ciphertext<Element> &ciphertext, double scalar) const
In-place subtraction of a real constant from every slot of a ciphertext (CKKS): the constant is scaled by the scaling factor of the ciphertext and subtracted from its first element.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the real constant to subtract.
-
virtual EvalKey<Element> EvalMultKeyGen(const PrivateKey<Element> privateKey) const
Virtual function to define the interface for generating an evaluation key which is used after each multiplication.
- Parameters
privateKey – the private key the relinearization key is generated for.
- Returns
the relinearization (evaluation) key for s^2.
-
virtual std::vector<EvalKey<Element>> EvalMultKeysGen(const PrivateKey<Element> privateKey) const
Virtual function to define the interface for generating a evaluation key which is used after each multiplication for depth more than 2.
- Parameters
privateKey – the private key the relinearization keys are generated for.
- Returns
the vector of relinearization (evaluation) keys for s^2, s^3, …
-
inline virtual Ciphertext<Element> EvalMult(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Virtual function to define the interface for multiplicative homomorphic evaluation of ciphertext.
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
- Returns
the new ciphertext.
-
inline virtual Ciphertext<Element> EvalMultMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Virtual function to define the interface for multiplicative homomorphic evaluation of ciphertext. This is the mutable version - input ciphertexts may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – the input ciphertext.
ciphertext2 – the input ciphertext.
- Returns
the new ciphertext.
-
inline virtual Ciphertext<Element> EvalSquare(ConstCiphertext<Element> &ciphertext1) const
Virtual function to define the interface for homomorphic squaring of ciphertext.
- Parameters
ciphertext1 – the input ciphertext.
- Returns
the new ciphertext.
-
inline virtual Ciphertext<Element> EvalSquareMutable(Ciphertext<Element> &ciphertext1) const
Virtual function to define the interface for homomorphic squaring of ciphertext. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – the input ciphertext.
- Returns
the new ciphertext.
-
virtual Ciphertext<Element> EvalMult(ConstCiphertext<Element> &ciphertext, ConstPlaintext &plaintext) const
Virtual function to define the interface for multiplication of ciphertext by plaintext.
- Parameters
ciphertext – the input ciphertext.
plaintext – the input plaintext.
- Returns
the new ciphertext.
-
virtual void EvalMultInPlace(Ciphertext<Element> &ciphertext, ConstPlaintext &plaintext) const
Virtual function to define the interface for in-place multiplication of a ciphertext by a plaintext: every ciphertext element is multiplied by the plaintext polynomial (in EVALUATION format).
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the input plaintext.
-
inline virtual Ciphertext<Element> EvalMultMutable(Ciphertext<Element> &ciphertext, Plaintext &plaintext) const
Virtual function to define the interface for multiplication of ciphertext by plaintext. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input ciphertext.
plaintext – the input plaintext.
- Returns
the new ciphertext.
-
inline virtual void EvalMultMutableInPlace(Ciphertext<Element> &ciphertext, Plaintext &plaintext) const
Virtual function to define the interface for in-place multiplication of ciphertext by plaintext. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the input plaintext.
-
inline virtual Ciphertext<Element> MultByMonomial(ConstCiphertext<Element> &ciphertext, uint32_t power) const
Multiplies the ciphertext by the monomial x^power of the cyclotomic ring, i.e., performs a negacyclic shift of the encrypted coefficients (power is reduced modulo 2N; powers in [N, 2N) flip the sign). The scaling factor and noise are not changed.
- Parameters
ciphertext – the input ciphertext.
power – the exponent of the monomial.
- Returns
the new ciphertext.
-
inline virtual void MultByMonomialInPlace(Ciphertext<Element> &ciphertext, uint32_t power) const
In-place multiplication of the ciphertext by the monomial x^power of the cyclotomic ring (negacyclic shift of the encrypted coefficients); see MultByMonomial.
- Parameters
ciphertext – the input/output ciphertext.
power – the exponent of the monomial.
-
inline virtual Ciphertext<Element> EvalMult(ConstCiphertext<Element> &ciphertext, NativeInteger scalar) const
Virtual function to define the interface for multiplication of a ciphertext by an integer scalar. Not implemented by any of the current schemes; the base implementation throws NOT_IMPLEMENTED_ERROR.
- Parameters
ciphertext – the input ciphertext.
scalar – the integer scalar.
- Returns
the new ciphertext.
-
inline virtual void EvalMultInPlace(Ciphertext<Element> &ciphertext, NativeInteger scalar) const
Virtual function to define the interface for in-place multiplication of a ciphertext by an integer scalar. Not implemented by any of the current schemes; the base implementation throws NOT_IMPLEMENTED_ERROR.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the integer scalar.
-
inline virtual Ciphertext<Element> EvalMult(ConstCiphertext<Element> &ciphertext, double scalar) const
Multiplies a ciphertext by a real constant (CKKS): the constant is encoded at the scaling factor of the current level, so the noise scale degree of the result is one higher than that of the input (the automatic scaling techniques first rescale an input of noise scale degree 2).
- Parameters
ciphertext – the input ciphertext.
scalar – the real constant.
- Returns
the new ciphertext.
-
inline virtual void EvalMultInPlace(Ciphertext<Element> &ciphertext, double scalar) const
In-place multiplication of a ciphertext by a real constant (CKKS); see EvalMult.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the real constant.
-
inline virtual Ciphertext<Element> EvalMult(ConstCiphertext<Element> &ciphertext, std::complex<double> scalar) const
Multiplies a ciphertext by a complex constant (CKKS): the constant is encoded at the scaling factor of the current level, so the noise scale degree of the result is one higher than that of the input (the automatic scaling techniques first rescale an input of noise scale degree 2).
- Parameters
ciphertext – the input ciphertext.
scalar – the complex constant.
- Returns
the new ciphertext.
-
inline virtual void EvalMultInPlace(Ciphertext<Element> &ciphertext, std::complex<double> scalar) const
In-place multiplication of a ciphertext by a complex constant (CKKS); see EvalMult.
- Parameters
ciphertext – the input/output ciphertext.
scalar – the complex constant.
-
inline virtual Ciphertext<Element> MultByInteger(ConstCiphertext<Element> &ciphertext, uint64_t integer) const
Multiplies every element of the ciphertext by a positive integer without encoding it at the scaling factor: the encrypted values are scaled by the integer exactly and the scaling factor and noise scale degree of the ciphertext are left unchanged (CKKS).
- Parameters
ciphertext – the input ciphertext.
integer – the positive integer to multiply by.
- Returns
the new ciphertext.
-
inline virtual void MultByIntegerInPlace(Ciphertext<Element> &ciphertext, uint64_t integer) const
In-place multiplication of every element of the ciphertext by a positive integer without changing the scaling factor or the noise scale degree (CKKS); see MultByInteger.
- Parameters
ciphertext – the input/output ciphertext.
integer – the positive integer to multiply by.
-
virtual Ciphertext<Element> EvalMult(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2, const EvalKey<Element> evalKey) const
Virtual function to define the interface for multiplicative homomorphic evaluation of ciphertext using the evaluation key.
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
evalKey – is the evaluation key to make the new ciphertext decryptable by the same secret key as that of ciphertext1 and ciphertext2.
- Returns
the new ciphertext.
-
virtual void EvalMultInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2, const EvalKey<Element> evalKey) const
Virtual function to define the interface for in-place multiplicative homomorphic evaluation of ciphertexts followed by relinearization with the evaluation key (the third element of the product is key switched back to two elements).
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input ciphertext.
evalKey – is the evaluation key to make the resulting ciphertext decryptable by the same secret key as that of ciphertext1 and ciphertext2.
-
virtual Ciphertext<Element> EvalMultMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2, const EvalKey<Element> evalKey) const
Virtual function to define the interface for multiplicative homomorphic evaluation of ciphertext using the evaluation key. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
evalKey – is the evaluation key to make the new ciphertext decryptable by the same secret key as that of ciphertext1 and ciphertext2.
- Returns
the new ciphertext.
-
virtual void EvalMultMutableInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2, const EvalKey<Element> evalKey) const
Virtual function to define the interface for multiplicative homomorphic evaluation of ciphertext using the evaluation key. This is the mutable version - input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input ciphertext.
evalKey – is the evaluation key to make the resulting ciphertext decryptable by the same secret key as that of ciphertext1 and ciphertext2.
-
virtual Ciphertext<Element> EvalSquare(ConstCiphertext<Element> &ciphertext, const EvalKey<Element> evalKey) const
Homomorphic squaring of a ciphertext followed by relinearization with the evaluation key.
- Parameters
ciphertext – the input ciphertext.
evalKey – the relinearization key for s^2.
- Returns
the new ciphertext with two elements.
-
virtual void EvalSquareInPlace(Ciphertext<Element> &ciphertext1, const EvalKey<Element> evalKey) const
In-place homomorphic squaring of a ciphertext followed by relinearization with the evaluation key.
- Parameters
ciphertext1 – the input/output ciphertext.
evalKey – the relinearization key for s^2.
-
virtual Ciphertext<Element> EvalSquareMutable(Ciphertext<Element> &ciphertext, const EvalKey<Element> evalKey) const
Homomorphic squaring of a ciphertext followed by relinearization with the evaluation key. This is the mutable version - the input ciphertext may change (automatically rescaled, or towers dropped).
- Parameters
ciphertext – the input ciphertext.
evalKey – the relinearization key for s^2.
- Returns
the new ciphertext with two elements.
-
virtual Ciphertext<Element> EvalMultAndRelinearize(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2, const std::vector<EvalKey<Element>> &evalKeyVec) const
Virtual function to define the interface for multiplicative homomorphic evaluation of ciphertext followed by relinearization using the evaluation keys.
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
evalKeyVec – are the evaluation keys to make the new ciphertext decryptable by the same secret key as that of ciphertext1 and ciphertext2.
- Returns
the new resulting ciphertext.
-
virtual Ciphertext<Element> Relinearize(ConstCiphertext<Element> &ciphertext, const std::vector<EvalKey<Element>> &evalKeyVec) const
Virtual function to do relinearization
- Parameters
ciphertext – input ciphertext.
evalKeyVec – are the evaluation keys to make the new ciphertext decryptable by the same secret key as that of the input ciphertext.
- Returns
the new resulting ciphertext.
-
virtual void RelinearizeInPlace(Ciphertext<Element> &ciphertext, const std::vector<EvalKey<Element>> &evalKeyVec) const
Virtual function to do relinearization in-place
- Parameters
ciphertext – input/output ciphertext.
evalKeyVec – are the evaluation keys to make the resulting ciphertext decryptable by the same secret key as that of the input ciphertext.
-
virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalAutomorphismKeyGen(const PrivateKey<Element> privateKey, const std::vector<uint32_t> &indexList) const
Virtual function to generate automophism keys for a given private key; Uses the private key for encryption
- Parameters
privateKey – private key.
indexList – list of automorphism indices to be computed
- Returns
returns the evaluation keys
-
virtual Ciphertext<Element> EvalAutomorphism(ConstCiphertext<Element> &ciphertext, uint32_t i, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap, CALLER_INFO_ARGS_HDR) const
Virtual function for evaluating automorphism of ciphertext at index i
- Parameters
ciphertext – the input ciphertext.
i – automorphism index
evalKeyMap – - reference to the map of evaluation keys generated by EvalAutomorphismKeyGen.
- Returns
resulting ciphertext
Shared core for evaluating an automorphism from precomputed key-switch digits. Both EvalAutomorphism and EvalFastRotation delegate here, so every rotation entry point (EvalRotate/EvalAtIndex, hoisted fast rotations, conjugation) applies the same operation sequence and produces bit-identical ciphertexts.
- Parameters
ciphertext – the input ciphertext.
autoIndex – automorphism index.
digits – the digit decomposition of the second ciphertext element, as produced by EvalFastRotationPrecompute.
evalKey – the automorphism key for autoIndex.
- Returns
resulting ciphertext
Virtual function for the automorphism and key switching step of hoisted automorphisms.
- Parameters
ciphertext – the input ciphertext to perform the automorphism on
index – the index of the rotation. Positive indices correspond to left rotations and negative indices correspond to right rotations.
m – is the cyclotomic order
digits – the digit decomposition created by EvalFastRotationPrecompute at the precomputation step.
- Returns
the rotated ciphertext
-
virtual std::shared_ptr<std::vector<Element>> EvalFastRotationPrecompute(ConstCiphertext<Element> &ciphertext) const
Virtual function for the precomputation step of hoisted automorphisms.
- Parameters
ciphertext – the input ciphertext on which to do the precomputation (digit decomposition)
- Returns
the digit decomposition of the ciphertext
Hoisted (fast) rotation in the extended CRT basis Q*P, supported only with HYBRID key switching: applies the key switching for the automorphism of rotation index
indexto the precomputed digit decomposition and then the automorphism itself. The result stays in the extended basis (see KeySwitchDown), which lets several rotations be accumulated with a single modulus reduction.- Parameters
ciphertext – the input ciphertext.
index – the rotation index (positive for left, negative for right).
expandedCiphertext – the digit decomposition of the second ciphertext element in the extended basis, as produced by EvalFastRotationPrecompute.
addFirst – if true, the first ciphertext element (scaled up by P) is added to the result so that it is a complete ciphertext; if false, only the key-switched part is returned.
evalKeys – the map of automorphism keys generated by EvalAutomorphismKeyGen.
- Returns
the rotated ciphertext in the extended basis Q*P.
-
virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalAtIndexKeyGen(const PrivateKey<Element> privateKey, const std::vector<int32_t> &indexList) const
Generates evaluation keys for a list of indices Currently works only for power-of-two and cyclic-group cyclotomics
- Parameters
privateKey – private key the rotation keys are generated for.
indexList – list of indices to be computed
- Returns
returns the evaluation keys
-
virtual Ciphertext<Element> EvalAtIndex(ConstCiphertext<Element> &ciphertext, int32_t index, const std::map<uint32_t, EvalKey<Element>> &evalKeyMap) const
Rotates the slots of the ciphertext by index
- Parameters
ciphertext – the input ciphertext.
index – the rotation index (positive for left, negative for right).
evalKeyMap – - reference to the map of evaluation keys generated by EvalAtIndexKeyGen.
- Returns
resulting ciphertext
-
inline virtual uint32_t FindAutomorphismIndex(uint32_t index, uint32_t m) const
Maps a rotation index to the automorphism index (Galois element) that realizes it for the cyclotomic order m; the mapping depends on the packing of the scheme (real packing for BGV/BFV, complex packing for CKKS).
- Parameters
index – the rotation index (positive for left, negative for right).
m – the cyclotomic order.
- Returns
the automorphism index.
-
inline virtual Ciphertext<Element> ModReduce(ConstCiphertext<Element> &ciphertext, size_t levels) const
Method for Modulus Reduction.
- Parameters
ciphertext – Ciphertext to perform mod reduce on.
levels – the number of towers to drop.
- Returns
ciphertext after the modulus reduction.
-
inline virtual void ModReduceInPlace(Ciphertext<Element> &ciphertext, size_t levels) const
Method for In-place Modulus Reduction.
- Parameters
ciphertext – Ciphertext to perform mod reduce on.
levels – the number of towers to drop.
-
virtual Ciphertext<Element> ComposedEvalMult(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2, const EvalKey<Element> evalKey) const
Method for Composed EvalMult (multiplication, relinearization and modulus reduction)
- Parameters
ciphertext1 – first input ciphertext to perform multiplication on.
ciphertext2 – second input ciphertext to perform multiplication on.
evalKey – is the relinearization key for the quadratic secret key after multiplication.
- Returns
the resulting ciphertext that can be decrypted with the secret key of the particular level.
-
virtual Ciphertext<Element> LevelReduce(ConstCiphertext<Element> &ciphertext1, const EvalKey<Element> evalKey, size_t levels) const
Method for Level Reduction. Drops the given number of towers of the ciphertext without changing the underlying plaintext.
- Parameters
ciphertext1 – is the original ciphertext to be level reduced.
evalKey – evaluation key (currently unused; kept for API compatibility).
levels – the number of towers to drop.
- Returns
the resulting ciphertext.
-
inline virtual void LevelReduceInPlace(Ciphertext<Element> &ciphertext1, const EvalKey<Element> evalKey, size_t levels) const
Method for in-place Level Reduction. Drops the given number of towers of the ciphertext without changing the underlying plaintext.
- Parameters
ciphertext1 – is the ciphertext to be level reduced in-place.
evalKey – evaluation key (currently unused; kept for API compatibility).
levels – the number of towers to drop.
-
inline virtual Ciphertext<Element> Compress(ConstCiphertext<Element> &ciphertext, size_t towersLeft, size_t noiseScaleDeg) const
Compresses a ciphertext to reduce its size for communication: rescales it until its noise scale degree is at most
noiseScaleDegand then drops towers untiltowersLefttowers remain. For the composite scaling techniques,towersLeftmust be a multiple of the composite degree.- Parameters
ciphertext – the input ciphertext.
towersLeft – the number of RNS towers to keep.
noiseScaleDeg – the noise scale degree the ciphertext is rescaled to before towers are dropped.
- Returns
the compressed ciphertext.
-
inline virtual Ciphertext<Element> ModReduceInternal(ConstCiphertext<Element> &ciphertext, size_t levels) const
Method for rescaling.
- Parameters
ciphertext – is the ciphertext to perform modreduce on.
levels – the number of towers to drop.
- Returns
ciphertext after the modulus reduction performed.
-
inline virtual void ModReduceInternalInPlace(Ciphertext<Element> &ciphertext, size_t levels) const
Method for rescaling in-place.
ciphertextwill have modulus reduction performed in-place.- Parameters
ciphertext – is the ciphertext to perform modreduce on.
levels – the number of towers to drop.
-
inline virtual Ciphertext<Element> LevelReduceInternal(ConstCiphertext<Element> &ciphertext, size_t levels) const
Method for Level Reduction in the CKKS scheme. It just drops “levels” number of the towers of the ciphertext without changing the underlying plaintext.
- Parameters
ciphertext – is the original ciphertext to be level reduced.
levels – the number of towers to drop.
- Returns
resulting ciphertext.
-
inline virtual void LevelReduceInternalInPlace(Ciphertext<Element> &ciphertext, size_t levels) const
Method for in-place Level Reduction in the CKKS scheme. It just drops “levels” number of the towers of the ciphertext without changing the underlying plaintext.
- Parameters
ciphertext – is the ciphertext to be level reduced in-place
levels – the number of towers to drop.
-
inline virtual void AdjustLevelsInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Brings two ciphertexts to the same number of RNS towers by dropping towers from the one with more towers (LevelReduceInternalInPlace); noise scale degrees are not changed.
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input/output ciphertext.
-
inline virtual void AdjustLevelsAndDepthInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Brings two ciphertexts to the same level and noise scale degree so that they can be added or subtracted (used by the automatic scaling techniques): the ciphertext at the lower level or degree is rescaled, or multiplied by the appropriate scaling factor, and level reduced as needed.
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input/output ciphertext.
-
inline virtual void AdjustLevelsAndDepthToOneInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Brings two ciphertexts to the same level and noise scale degree as AdjustLevelsAndDepthInPlace and then rescales both to noise scale degree 1 if they are at degree 2; used before a multiplication.
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input/output ciphertext.
-
inline virtual void AdjustForAddOrSubInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Prepares two operands for addition or subtraction according to the scaling technique: FIXEDMANUAL only matches the number of towers (and scales a single-element operand obtained from a plaintext up to the noise scale degree of the other operand); the automatic techniques call AdjustLevelsAndDepthInPlace; NORESCALE does nothing.
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input/output ciphertext.
-
inline virtual void AdjustForMultInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Prepares two operands for multiplication according to the scaling technique: FIXEDMANUAL only matches the number of towers; the automatic techniques call AdjustLevelsAndDepthToOneInPlace; NORESCALE does nothing.
- Parameters
ciphertext1 – first input/output ciphertext.
ciphertext2 – second input/output ciphertext.
-
virtual Ciphertext<Element> MorphPlaintext(ConstPlaintext &plaintext, ConstCiphertext<Element> &ciphertext) const
Wraps a plaintext in a single-element ciphertext that shares the metadata of
ciphertext(crypto context, key tag) and carries the slots, level, noise scale degree and scaling factors of the plaintext, so that a plaintext operand can go through the ciphertext level/depth adjustment helpers (AdjustForAddOrSubInPlace, AdjustForMultInPlace).- Parameters
plaintext – the plaintext to wrap.
ciphertext – the ciphertext whose metadata is used for the result.
- Returns
a ciphertext with one element holding the plaintext polynomial in EVALUATION format.
Protected Functions
-
void VerifyNumOfTowers(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext, CALLER_INFO_ARGS_HDR) const
Throws if the two ciphertexts do not have the same number of RNS towers. The trailing CALLER_INFO arguments carry the location of the caller for the error message.
- Parameters
ciphertext1 – first ciphertext.
ciphertext – second ciphertext.
-
void VerifyNumOfTowers(ConstCiphertext<Element> &ciphertext, const Element &plaintext, CALLER_INFO_ARGS_HDR) const
Throws if the ciphertext and the plaintext polynomial do not have the same number of RNS towers. The trailing CALLER_INFO arguments carry the location of the caller for the error message.
- Parameters
ciphertext – the ciphertext.
plaintext – the plaintext polynomial.
-
virtual Ciphertext<Element> EvalAddCore(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Internal function for homomorphic addition of ciphertexts. This method does not check whether input ciphertexts are at the same level.
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
- Returns
result of homomorphic addition of input ciphertexts.
-
void EvalAddCoreInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Internal function for in-place homomorphic addition of ciphertexts. This method does not check whether input ciphertexts are at the same level.
- Parameters
ciphertext1 – first input/output ciphertext; on return it contains the result of the homomorphic addition of the input ciphertexts.
ciphertext2 – second input ciphertext.
-
virtual Ciphertext<Element> EvalSubCore(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Internal function for homomorphic subtraction of ciphertexts. This method does not check whether input ciphertexts are at the same level.
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
- Returns
result of homomorphic subtraction of input ciphertexts.
-
void EvalSubCoreInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Internal function for in-place homomorphic subtraction of ciphertexts. This method does not check whether input ciphertexts are at the same level.
- Parameters
ciphertext1 – first input/output ciphertext; on return it contains the result of the homomorphic subtraction of the input ciphertexts.
ciphertext2 – second input ciphertext.
-
Ciphertext<Element> EvalMultCore(ConstCiphertext<Element> &ciphertext1, ConstCiphertext<Element> &ciphertext2) const
Internal function for homomorphic multiplication of ciphertexts. This method does not check whether input ciphertexts are at the same level.
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
- Returns
result of homomorphic multiplication of input ciphertexts.
-
Ciphertext<Element> EvalMultCore(ConstCiphertext<Element> &ciphertext, const Element &plaintext) const
Internal function for multiplication of a ciphertext by a plaintext polynomial: every ciphertext element is multiplied by the polynomial. Only the number of towers is checked; the metadata (scaling factor, noise scale degree) of the result is not updated.
- Parameters
ciphertext – the input ciphertext.
plaintext – the plaintext polynomial (same format and number of towers as the ciphertext).
- Returns
the product ciphertext.
-
void EvalMultCoreInPlace(Ciphertext<Element> &ciphertext, const Element &plaintext) const
Internal in-place multiplication of a ciphertext by a plaintext polynomial; see EvalMultCore.
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the plaintext polynomial (same format and number of towers as the ciphertext).
-
virtual Ciphertext<Element> EvalAddCore(ConstCiphertext<Element> &ciphertext, const Element &plaintext) const
Internal function for addition of a plaintext polynomial to a ciphertext: the polynomial is added to the first ciphertext element. Only the number of towers is checked.
- Parameters
ciphertext – the input ciphertext.
plaintext – the plaintext polynomial (same format and number of towers as the ciphertext).
- Returns
the sum ciphertext.
-
void EvalAddCoreInPlace(Ciphertext<Element> &ciphertext, const Element &plaintext) const
Internal in-place addition of a plaintext polynomial to the first ciphertext element; see EvalAddCore.
- Parameters
ciphertext – the input/output ciphertext.
plaintext – the plaintext polynomial (same format and number of towers as the ciphertext).
-
virtual Ciphertext<Element> EvalSubCore(ConstCiphertext<Element> &ciphertext1, const Element &plaintext) const
Internal function for subtraction of a plaintext polynomial from a ciphertext: the polynomial is subtracted from the first ciphertext element. Only the number of towers is checked.
- Parameters
ciphertext1 – the input ciphertext.
plaintext – the plaintext polynomial (same format and number of towers as the ciphertext).
- Returns
the difference ciphertext.
-
void EvalSubCoreInPlace(Ciphertext<Element> &ciphertext1, const Element &plaintext) const
Internal in-place subtraction of a plaintext polynomial from the first ciphertext element; see EvalSubCore.
- Parameters
ciphertext1 – the input/output ciphertext.
plaintext – the plaintext polynomial (same format and number of towers as the ciphertext).
-
Ciphertext<Element> EvalSquareCore(ConstCiphertext<Element> &ciphertext) const
Internal function for homomorphic squaring of a ciphertext (tensor product with itself, using the symmetry to halve the number of polynomial multiplications). An input with n elements gives a result with 2n-1 elements, doubled noise scale degree and squared scaling factor. This method does not check the level of the input.
- Parameters
ciphertext – the input ciphertext.
- Returns
result of homomorphic squaring of the input ciphertext.