Template Class CryptoContextImpl
Defined in File cryptocontext.h
Inheritance Relationships
Base Type
public lbcrypto::Serializable
(Class Serializable)
Template Parameter Order
typename Element
Class Documentation
-
template<typename Element>
class lbcrypto::CryptoContextImpl : public lbcrypto::Serializable Inheritence diagram for lbcrypto::CryptoContextImpl:
Collaboration diagram for lbcrypto::CryptoContextImpl:
A CryptoContextImpl is the object used to access the OpenFHE library
All OpenFHE functionality is accessed by way of an instance of a CryptoContextImpl; we say that various objects are “created in” a context, and can only be used in the context in which they were created
All OpenFHE methods are accessed through CryptoContextImpl methods. Guards are implemented to make certain that only valid objects that have been created in the context are used
Contexts are created using GenCryptoContext(), and can be serialized and recovered from a serialization
Public Functions
-
inline void SetPrivateKey(const PrivateKey<Element> privateKey)
This stores the private key in the crypto context. This is only intended for debugging and should not be used in production systems. Please define DEBUG_KEY in openfhe.h to enable this.
If used, one can create a key pair and store the secret key in th crypto context like this:
auto keys = cc->KeyGen(); cc->SetPrivateKey(keys.secretKey);
After that, anyone in the code, one can access the secret key by getting the crypto context and doing the following:
auto sk = cc->GetPrivateKey();
This key can be used for decrypting any intermediate ciphertexts for debugging purposes.
- Parameters
sk – the secret key
-
inline const PrivateKey<Element> GetPrivateKey()
This gets the private key from the crypto context. This is only intended for debugging and should not be used in production systems. Please define DEBUG_KEY in openfhe.h to enable this.
If used, one can create a key pair and store the secret key in th crypto context like this:
auto keys = cc->KeyGen(); cc->SetPrivateKey(keys.secretKey);
After that, anyone in the code, one can access the secret key by getting the crypto context and doing the following:
auto sk = cc->GetPrivateKey();
This key can be used for decrypting any intermediate ciphertexts for debugging purposes.
- Returns
the secret key
-
inline CryptoContextImpl(CryptoParametersBase<Element> *params = nullptr, SchemeBase<Element> *scheme = nullptr, SCHEME schemeId = SCHEME::INVALID_SCHEME)
CryptoContextImpl constructor from pointers to parameters and scheme
- Parameters
params – pointer to CryptoParameters
scheme – pointer to Crypto Scheme object
schemeId – scheme identifier
CryptoContextImpl constructor from shared pointers to parameters and scheme
- Parameters
params – shared pointer to CryptoParameters
scheme – sharedpointer to Crypto Scheme object
schemeId – scheme identifier
-
inline CryptoContextImpl(const CryptoContextImpl<Element> &c)
Copy constructor
- Parameters
c – - source
-
inline CryptoContextImpl<Element> &operator=(const CryptoContextImpl<Element> &rhs)
Assignment
- Parameters
rhs – - assigning from
- Returns
this
-
inline operator bool() const
A CryptoContextImpl is only valid if the shared pointers are both valid
-
inline void Enable(PKESchemeFeature feature)
Enable a particular feature for use with this CryptoContextImpl
- Parameters
feature – - the feature that should be enabled
-
inline void Enable(usint featureMask)
Enable several features at once
- Parameters
featureMask – - bitwise or of several PKESchemeFeatures
-
inline const std::shared_ptr<SchemeBase<Element>> GetScheme() const
Getter for Scheme
- Returns
scheme
-
inline const std::shared_ptr<CryptoParametersBase<Element>> GetCryptoParameters() const
Getter for CryptoParams
- Returns
params
-
inline size_t GetKeyGenLevel() const
For future use: getter for the level at which evaluation keys should be generated
-
inline void SetKeyGenLevel(size_t level)
For future use: setter for the level at which evaluation keys should be generated
-
inline const std::shared_ptr<ParmType> GetElementParams() const
Getter for element params
- Returns
-
inline const EncodingParams GetEncodingParams() const
Getter for encoding params
- Returns
-
inline const IntType &GetModulus() const
Get the ciphertext modulus used for this context
- Returns
-
inline const IntType &GetRootOfUnity() const
Get the ciphertext modulus used for this context
- Returns
-
inline Plaintext MakeStringPlaintext(const std::string &str) const
MakeStringPlaintext constructs a StringEncoding in this context
- Parameters
str – string to be encoded
- Returns
plaintext
-
inline Plaintext MakeCoefPackedPlaintext(const std::vector<int64_t> &value, size_t noiseScaleDeg = 1, uint32_t level = 0) const
MakeCoefPackedPlaintext constructs a CoefPackedEncoding in this context
- Parameters
value – vector of signed integers mod t
noiseScaleDeg – is degree of the scaling factor to encode the plaintext at
level – is the level to encode the plaintext at
- Returns
plaintext
-
inline Plaintext MakePackedPlaintext(const std::vector<int64_t> &value, size_t noiseScaleDeg = 1, uint32_t level = 0) const
MakePackedPlaintext constructs a PackedEncoding in this context
- Parameters
value – vector of signed integers mod t
noiseScaleDeg – is degree of the scaling factor to encode the plaintext at
level – is the level to encode the plaintext at
- Returns
plaintext
COMPLEX ARITHMETIC IS NOT AVAILABLE, AND THIS METHOD BE DEPRECATED. USE THE REAL-NUMBER METHOD INSTEAD. MakeCKKSPackedPlaintext constructs a CKKSPackedEncoding in this context from a vector of complex numbers
- Parameters
value – - input vector of complex number
scaleDeg – - degree of scaling factor used to encode the vector
level – - level at each the vector will get encrypted
params – - parameters to be usef for the ciphertext
- Returns
plaintext
MakeCKKSPackedPlaintext constructs a CKKSPackedEncoding in this context from a vector of real numbers
- Parameters
value – - input vector of real numbers
scaleDeg – - degree of scaling factor used to encode the vector
level – - level at each the vector will get encrypted
params – - parameters to be usef for the ciphertext
- Returns
plaintext
-
inline KeyPair<Element> KeyGen()
KeyGen generates a key pair using this algorithm’s KeyGen method
- Returns
a public/secret key pair
-
inline KeyPair<Element> SparseKeyGen()
NOT SUPPORTED BY ANY CRYPTO SCHEME NOW SparseKeyGen generates a key pair with special structure, and without full entropy, for use in special cases like Ring Reduction
- Returns
a public/secret key pair
-
inline Ciphertext<Element> Encrypt(const Plaintext &plaintext, const PublicKey<Element> publicKey) const
Encrypt a plaintext using a given public key
- Parameters
plaintext – plaintext
publicKey – public key
- Returns
ciphertext (or null on failure)
-
inline Ciphertext<Element> Encrypt(const PublicKey<Element> publicKey, Plaintext plaintext) const
Encrypt a plaintext using a given public key
- Parameters
publicKey – public key
plaintext – plaintext
- Returns
ciphertext (or null on failure)
-
inline Ciphertext<Element> Encrypt(const Plaintext &plaintext, const PrivateKey<Element> privateKey) const
Encrypt a plaintext using a given private key
- Parameters
plaintext – input plaintext
privateKey – private key
- Returns
ciphertext (or null on failure)
-
inline Ciphertext<Element> Encrypt(const PrivateKey<Element> privateKey, Plaintext plaintext) const
Encrypt a plaintext using a given private key
- Parameters
privateKey – private key
plaintext – input plaintext
- Returns
ciphertext (or null on failure)
-
DecryptResult Decrypt(ConstCiphertext<Element> ciphertext, const PrivateKey<Element> privateKey, Plaintext *plaintext)
Decrypt a single ciphertext into the appropriate plaintext
- Parameters
ciphertext – - ciphertext to decrypt
privateKey – - decryption key
plaintext – - resulting plaintext object pointer is here
- Returns
-
inline DecryptResult Decrypt(const PrivateKey<Element> privateKey, ConstCiphertext<Element> ciphertext, Plaintext *plaintext)
Decrypt a single ciphertext into the appropriate plaintext
- Parameters
privateKey – - decryption key
ciphertext – - ciphertext to decrypt
plaintext – - resulting plaintext object pointer is here
- Returns
-
inline EvalKey<Element> KeySwitchGen(const PrivateKey<Element> oldPrivateKey, const PrivateKey<Element> newPrivateKey) const
KeySwitchGen creates a key that can be used with the OpenFHE KeySwitch operation
- Parameters
oldPrivateKey – input secrey key
newPrivateKey – output secret key
- Returns
new evaluation key
-
inline Ciphertext<Element> KeySwitch(ConstCiphertext<Element> ciphertext, const EvalKey<Element> evalKey) const
KeySwitch - OpenFHE KeySwitch method
- Parameters
ciphertext – - ciphertext
evalKey – - evaluation key used for key switching
- Returns
new CiphertextImpl after applying key switch
-
inline void KeySwitchInPlace(Ciphertext<Element> &ciphertext, const EvalKey<Element> evalKey) const
KeySwitchInPlace - OpenFHE KeySwitchInPlace method
- Parameters
ciphertext – - ciphertext
evalKey – - evaluation key used for key switching
-
inline Ciphertext<Element> EvalNegate(ConstCiphertext<Element> ciphertext) const
Negates a ciphertext
- Parameters
ciphertext – input ciphertext
- Returns
new ciphertext -ct
-
inline void EvalNegateInPlace(Ciphertext<Element> &ciphertext) const
In-place negation of a ciphertext
- Parameters
ciphertext – input ciphertext
-
inline Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2) const
Homomorphic addition of two ciphertexts
- Parameters
ciphertext1 – first addend
ciphertext2 – second addend
- Returns
the result as a new ciphertext
-
inline void EvalAddInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> ciphertext2) const
In-place homomorphic addition of two ciphertexts
- Parameters
ciphertext1 – first addend
ciphertext2 – second addend
- Returns
ciphertext1
containsciphertext1
+ciphertext2
-
inline Ciphertext<Element> EvalAddMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Homomorphic addition of two mutable ciphertexts (they can be changed during the operation)
- Parameters
ciphertext1 – first addend
ciphertext2 – second addend
- Returns
the result as a new ciphertext
-
inline void EvalAddMutableInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
In-place homomorphic addition of two mutable ciphertexts (they can be changed during the operation)
- Parameters
ciphertext1 – first addend
ciphertext2 – second addend
- Returns
ciphertext1
containsciphertext1
+ciphertext2
-
inline Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext) const
EvalAdd - OpenFHE EvalAdd method for a ciphertext and plaintext
- Parameters
ciphertext – input ciphertext
plaintext – input plaintext
- Returns
new ciphertext for ciphertext + plaintext
-
inline Ciphertext<Element> EvalAdd(ConstPlaintext plaintext, ConstCiphertext<Element> ciphertext) const
EvalAdd - OpenFHE EvalAdd method for a ciphertext and plaintext
- Parameters
plaintext – input plaintext
ciphertext – input ciphertext
- Returns
new ciphertext for ciphertext + plaintext
-
inline void EvalAddInPlace(Ciphertext<Element> &ciphertext, ConstPlaintext plaintext) const
In-place addition for a ciphertext and plaintext
- Parameters
ciphertext – input ciphertext
plaintext – input plaintext
-
inline void EvalAddInPlace(ConstPlaintext plaintext, Ciphertext<Element> &ciphertext) const
In-place addition for a ciphertext and plaintext
- Parameters
plaintext – input plaintext
ciphertext – input ciphertext
-
inline Ciphertext<Element> EvalAddMutable(Ciphertext<Element> &ciphertext, Plaintext plaintext) const
Homomorphic addition a mutable ciphertext and plaintext
- Parameters
ciphertext – input ciphertext
plaintext – input plaintext
- Returns
new ciphertext for ciphertext + plaintext
-
inline Ciphertext<Element> EvalAddMutable(Plaintext plaintext, Ciphertext<Element> &ciphertext) const
Homomorphic addition a mutable ciphertext and plaintext
- Parameters
plaintext – input plaintext
ciphertext – input ciphertext
- Returns
new ciphertext for ciphertext + plaintext
-
inline Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext, double constant) const
EvalAdd - OpenFHE EvalAdd method for a ciphertext and a real number. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
constant – a real number
- Returns
new ciphertext for ciphertext + constant
-
inline Ciphertext<Element> EvalAdd(double constant, ConstCiphertext<Element> ciphertext) const
EvalAdd - OpenFHE EvalAdd method for a ciphertext and a real number. Supported only in CKKS.
- Parameters
constant – a real number
ciphertext – input ciphertext
- Returns
new ciphertext for ciphertext + constant
-
inline void EvalAddInPlace(Ciphertext<Element> &ciphertext, double constant) const
In-place addition of a ciphertext and a real number. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
constant – a real number
-
inline void EvalAddInPlace(double constant, Ciphertext<Element> &ciphertext) const
In-place addition of a ciphertext and a real number. Supported only in CKKS.
- Parameters
constant – a real number
ciphertext – input ciphertext
-
inline Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2) const
Homomorphic subtraction of two ciphertexts
- Parameters
ciphertext1 – minuend
ciphertext2 – subtrahend
- Returns
the result as a new ciphertext
-
inline void EvalSubInPlace(Ciphertext<Element> &ciphertext1, ConstCiphertext<Element> ciphertext2) const
In-place homomorphic subtraction of two ciphertexts
- Parameters
ciphertext1 – minuend
ciphertext2 – subtrahend
- Returns
the result as a new ciphertext
-
inline Ciphertext<Element> EvalSubMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
Homomorphic subtraction of two mutable ciphertexts
- Parameters
ciphertext1 – minuend
ciphertext2 – subtrahend
- Returns
the result as a new ciphertext
-
inline void EvalSubMutableInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
In-place homomorphic subtraction of two mutable ciphertexts
- Parameters
ciphertext1 – minuend
ciphertext2 – subtrahend
- Returns
the updated minuend
-
inline Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext) const
Homomorphic subtraction of a ciphertext and plaintext
- Parameters
ciphertext – minuend
plaintext – subtrahend
- Returns
new ciphertext for ciphertext - plaintext
-
inline Ciphertext<Element> EvalSub(ConstPlaintext plaintext, ConstCiphertext<Element> ciphertext) const
Homomorphic subtraction of a ciphertext and plaintext
- Parameters
plaintext – minuend
ciphertext – subtrahend
- Returns
new ciphertext for plaintext - ciphertext
-
inline Ciphertext<Element> EvalSubMutable(Ciphertext<Element> &ciphertext, Plaintext plaintext) const
Homomorphic subtraction of mutable ciphertext and plaintext
- Parameters
ciphertext – minuend
plaintext – subtrahend
- Returns
new ciphertext for ciphertext - plaintext
-
inline Ciphertext<Element> EvalSubMutable(Plaintext plaintext, Ciphertext<Element> &ciphertext) const
Homomorphic subtraction of mutable ciphertext and plaintext
- Parameters
plaintext – minuend
ciphertext – subtrahend
- Returns
new ciphertext for plaintext - ciphertext
-
inline Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext, double constant) const
Subtraction of a ciphertext and a real number. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
constant – a real number
- Returns
new ciphertext for ciphertext - constant
-
inline Ciphertext<Element> EvalSub(double constant, ConstCiphertext<Element> ciphertext) const
Subtraction of a ciphertext and a real number. Supported only in CKKS.
- Parameters
constant – a real number
ciphertext – input ciphertext
- Returns
new ciphertext for constant - ciphertext
-
inline void EvalSubInPlace(Ciphertext<Element> &ciphertext, double constant) const
In-place subtraction of a ciphertext and a real number. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
constant – a real number
-
inline void EvalSubInPlace(double constant, Ciphertext<Element> &ciphertext) const
In-placve subtraction of ciphertext from a real number. Supported only in CKKS.
- Parameters
constant – a real number
ciphertext – input ciphertext
-
void EvalMultKeyGen(const PrivateKey<Element> key)
EvalMultKeyGen creates a relinearization key (for s^2) that can be used with the OpenFHE EvalMult operator the new evaluation key is stored in cryptocontext
- Parameters
key – secret key
-
void EvalMultKeysGen(const PrivateKey<Element> key)
EvalMultsKeyGen creates a vector evalmult keys that can be used with the OpenFHE EvalMult operator 1st key (for s^2) is used for multiplication of ciphertexts of depth 1 2nd key (for s^3) is used for multiplication of ciphertexts of depth 2, etc. a vector of new evaluation keys is stored in crytpocontext
- Parameters
key – secret key
-
inline Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2) const
EvalMult - OpenFHE EvalMult method for a pair of ciphertexts (uses a relinearization key from the crypto context)
- Parameters
ciphertext1 – multiplier
ciphertext2 – multiplicand
- Returns
new ciphertext for ciphertext1 * ciphertext2
-
inline Ciphertext<Element> EvalMultMutable(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
EvalMult - OpenFHE EvalMult method for a pair of mutable ciphertexts (uses a relinearization key from the crypto context)
- Parameters
ciphertext1 – multiplier
ciphertext2 – multiplicand
- Returns
new ciphertext for ciphertext1 * ciphertext2
-
inline void EvalMultMutableInPlace(Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2) const
In-place EvalMult method for a pair of mutable ciphertexts (uses a relinearization key from the crypto context)
- Parameters
ciphertext1 – multiplier
ciphertext2 – multiplicand
-
inline Ciphertext<Element> EvalSquare(ConstCiphertext<Element> ciphertext) const
Efficient homomorphic squaring of a ciphertext - uses a relinearization key stored in the crypto context
- Parameters
ciphertext – input ciphertext
- Returns
squared ciphertext
-
inline Ciphertext<Element> EvalSquareMutable(Ciphertext<Element> &ciphertext) const
Efficient homomorphic squaring of a mutable ciphertext - uses a relinearization key stored in the crypto context
- Parameters
ciphertext – input ciphertext
- Returns
squared ciphertext
-
inline void EvalSquareInPlace(Ciphertext<Element> &ciphertext) const
In-place homomorphic squaring of a mutable ciphertext - uses a relinearization key stored in the crypto context
- Parameters
ciphertext – input ciphertext
- Returns
squared ciphertext
-
inline Ciphertext<Element> EvalMultNoRelin(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2) const
Homomorphic multiplication of two ciphertexts withour relinearization
- Parameters
ciphertext1 – multiplier
ciphertext2 – multiplicand
- Returns
new ciphertext for ciphertext1 * ciphertext2
-
inline Ciphertext<Element> Relinearize(ConstCiphertext<Element> ciphertext) const
Function for relinearization of a ciphertext to the lowest level (with 2 polynomials per ciphertext).
- Parameters
ciphertext – input ciphertext.
- Returns
relinearized ciphertext
-
inline void RelinearizeInPlace(Ciphertext<Element> &ciphertext) const
In-place relinearization of a ciphertext to the lowest level (with 2 polynomials per ciphertext).
- Parameters
ciphertext – input ciphertext.
-
inline Ciphertext<Element> EvalMultAndRelinearize(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2) const
Homomorphic multiplication of two ciphertexts followed by relinearization to the lowest level
- Parameters
ciphertext1 – first input ciphertext.
ciphertext2 – second input ciphertext.
- Returns
new ciphertext
-
inline Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext) const
Multiplication of a ciphertext by a plaintext
- Parameters
ciphertext – multiplier
plaintext – multiplicand
- Returns
the result of multiplication
-
inline Ciphertext<Element> EvalMult(ConstPlaintext plaintext, ConstCiphertext<Element> ciphertext) const
Multiplication of a plaintext by a ciphertext
- Parameters
plaintext – multiplier
ciphertext – multiplicand
- Returns
the result of multiplication
-
inline Ciphertext<Element> EvalMultMutable(Ciphertext<Element> &ciphertext, Plaintext plaintext) const
Multiplication of mutable ciphertext and plaintext
- Parameters
ciphertext – multiplier
plaintext – multiplicand
- Returns
the result of multiplication
-
inline Ciphertext<Element> EvalMultMutable(Plaintext plaintext, Ciphertext<Element> &ciphertext) const
Multiplication of mutable plaintext and ciphertext
- Parameters
plaintext – multiplier
ciphertext – multiplicand
- Returns
the result of multiplication
-
inline Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext, double constant) const
Multiplication of a ciphertext by a real number. Supported only in CKKS.
- Parameters
ciphertext – multiplier
constant – multiplicand
- Returns
the result of multiplication
-
inline Ciphertext<Element> EvalMult(double constant, ConstCiphertext<Element> ciphertext) const
Multiplication of a ciphertext by a real number. Supported only in CKKS.
- Parameters
constant – multiplier
ciphertext – multiplicand
- Returns
the result of multiplication
-
inline void EvalMultInPlace(Ciphertext<Element> &ciphertext, double constant) const
In-place multiplication of a ciphertext by a real number. Supported only in CKKS.
- Parameters
ciphertext – multiplier
constant – multiplicand
-
inline void EvalMultInPlace(double constant, Ciphertext<Element> &ciphertext) const
In-place multiplication of a ciphertext by a real number. Supported only in CKKS.
- Parameters
constant – multiplier (real number)
ciphertext – multiplicand
-
inline std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalAutomorphismKeyGen(const PrivateKey<Element> privateKey, const std::vector<usint> &indexList) const
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
-
inline std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalAutomorphismKeyGen(const PublicKey<Element> publicKey, const PrivateKey<Element> privateKey, const std::vector<usint> &indexList) const
-
inline Ciphertext<Element> EvalAutomorphism(ConstCiphertext<Element> ciphertext, usint i, const std::map<usint, EvalKey<Element>> &evalKeyMap, CALLER_INFO_ARGS_HDR) const
Function for evaluating automorphism of ciphertext at index i
- Parameters
ciphertext – the input ciphertext.
i – automorphism index
&evalKeys – - reference to the vector of evaluation keys generated by EvalAutomorphismKeyGen.
- Returns
resulting ciphertext
-
inline usint FindAutomorphismIndex(const usint idx) const
Finds an automorphism index for a given vector index using a scheme-specific algorithm
- Parameters
idx – regular vector index
- Returns
the automorphism index
-
inline std::vector<usint> FindAutomorphismIndices(const std::vector<usint> &idxList) const
Finds automorphism indices for a given list of vector indices using a scheme-specific algorithm
- Parameters
idxList – vector of indices
- Returns
a vector of automorphism indices
-
inline Ciphertext<Element> EvalRotate(ConstCiphertext<Element> ciphertext, int32_t index) const
Rotates a ciphertext by an index (positive index is a left shift, negative index is a right shift). Uses a rotation key stored in a crypto context. Calls EvalAtIndex under the hood.
- Parameters
ciphertext – input ciphertext
index – rotation index
- Returns
a rotated ciphertext
-
inline std::shared_ptr<std::vector<Element>> EvalFastRotationPrecompute(ConstCiphertext<Element> ciphertext) const
EvalFastRotationPrecompute implements the precomputation step of hoisted automorphisms.
Please refer to Section 5 of Halevi and Shoup, “Faster Homomorphic
linear transformations in HELib.” for more details, link:
https://eprint.iacr.org/2018/244.Generally, automorphisms are performed with three steps: (1) the automorphism is applied on the ciphertext, (2) the automorphed values are decomposed into digits, and (3) key switching is applied to make it possible to further compute on the ciphertext.
Hoisted automorphisms is a technique that performs the digit decomposition for the original ciphertext first, and then performs the automorphism and the key switching on the decomposed digits. The benefit of this is that the digit decomposition is independent of the automorphism rotation index, so it can be reused for multiple different indices. This can greatly improve performance when we have to compute many automorphisms on the same ciphertext. This routinely happens when we do permutations (EvalPermute).
EvalFastRotationPrecompute implements the digit decomposition step of hoisted automorphisms.
- Parameters
ciphertext – the input ciphertext on which to do the precomputation (digit decomposition)
EvalFastRotation implements the automorphism and key switching step of hoisted automorphisms.
Please refer to Section 5 of Halevi and Shoup, “Faster Homomorphic
linear transformations in HELib.” for more details, link:
https://eprint.iacr.org/2018/244.Generally, automorphisms are performed with three steps: (1) the automorphism is applied on the ciphertext, (2) the automorphed values are decomposed into digits, and (3) key switching is applied to make it possible to further compute on the ciphertext.
Hoisted automorphisms is a technique that performs the digit decomposition for the original ciphertext first, and then performs the automorphism and the key switching on the decomposed digits. The benefit of this is that the digit decomposition is independent of the automorphism rotation index, so it can be reused for multiple different indices. This can greatly improve performance when we have to compute many automorphisms on the same ciphertext. This routinely happens when we do permutations (EvalPermute).
EvalFastRotation implements the automorphism and key swithcing step of hoisted automorphisms.
This method assumes that all required rotation keys exist. This may not be true if we are using baby-step/giant-step key switching. Please refer to Section 5.1 of the above reference and EvalPermuteBGStepHoisted to see how to deal with this issue.
- 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.
Only supported for hybrid key switching. Performs fast (hoisted) rotation and returns the results in the extended CRT basis P*Q
- Parameters
ciphertext – input ciphertext
index – the rotation index.
digits – the precomputed digits for the ciphertext
addFirst – if true, the the first element c0 is also computed (otherwise ignored)
- Returns
resulting ciphertext
-
inline Ciphertext<Element> KeySwitchDown(ConstCiphertext<Element> ciphertext) const
Only supported for hybrid key switching. Takes a ciphertext in the extended basis P*Q and scales down to Q.
- Parameters
ciphertext – input ciphertext in the extended basis
- Returns
resulting ciphertext
-
inline Element KeySwitchDownFirstElement(ConstCiphertext<Element> ciphertext) const
Only supported for hybrid key switching. Scales down the polynomial c0 from extended basis P*Q to Q.
- Parameters
ciphertext – input ciphertext in the extended basis
- Returns
resulting polynomial
-
inline Ciphertext<Element> KeySwitchExt(ConstCiphertext<Element> ciphertext, bool addFirst) const
Only supported for hybrid key switching. Takes a ciphertext in the normal basis Q and extends it to extended basis P*Q.
- Parameters
ciphertext – input ciphertext in basis Q
- Returns
resulting ciphertext in basis P*Q
-
void EvalAtIndexKeyGen(const PrivateKey<Element> privateKey, const std::vector<int32_t> &indexList, const PublicKey<Element> publicKey = nullptr)
EvalAtIndexKeyGen generates evaluation keys for a list of rotation indices
- Parameters
privateKey – private key.
indexList – list of indices.
publicKey – public key (used in NTRU schemes). Not used anymore.
-
inline void EvalRotateKeyGen(const PrivateKey<Element> privateKey, const std::vector<int32_t> &indexList, const PublicKey<Element> publicKey = nullptr)
EvalRotateKeyGen generates evaluation keys for a list of rotation indices. Calls EvalAtIndexKeyGen under the hood.
- Parameters
privateKey – private key.
indexList – list of indices.
publicKey – public key (used in NTRU schemes).
-
Ciphertext<Element> EvalAtIndex(ConstCiphertext<Element> ciphertext, int32_t index) const
Rotates a ciphertext by an index (positive index is a left shift, negative index is a right shift). Uses a rotation key stored in a crypto context.
- Parameters
ciphertext – input ciphertext
index – rotation index
- Returns
a rotated ciphertext
-
inline Ciphertext<Element> ComposedEvalMult(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2) const
ComposedEvalMult - calls multiplication, relinearization, and then modulus switching/rescaling. Uses a relinearization key stored in the crypto context.
- Parameters
ciphertext1 – - first ciphertext
ciphertext2 – - second ciphertext
-
inline Ciphertext<Element> Rescale(ConstCiphertext<Element> ciphertext) const
Rescale - An alias for OpenFHE ModReduce method. This is because ModReduce is called Rescale in CKKS.
- Parameters
ciphertext – - ciphertext
- Returns
rescaled ciphertext
-
inline void RescaleInPlace(Ciphertext<Element> &ciphertext) const
Rescale - An alias for OpenFHE ModReduceInPlace method. This is because ModReduceInPlace is called RescaleInPlace in CKKS.
- Parameters
ciphertext – - ciphertext to be rescaled in-place
-
inline Ciphertext<Element> ModReduce(ConstCiphertext<Element> ciphertext) const
ModReduce - OpenFHE ModReduce method used only for BGV/CKKS.
- Parameters
ciphertext – - ciphertext
- Returns
mod reduced ciphertext
-
inline void ModReduceInPlace(Ciphertext<Element> &ciphertext) const
ModReduce - OpenFHE ModReduceInPlace method used only for BGV/CKKS.
- Parameters
ciphertext – - ciphertext to be mod-reduced in-place
-
inline Ciphertext<Element> LevelReduce(ConstCiphertext<Element> ciphertext, const EvalKey<Element> evalKey, size_t levels = 1) const
LevelReduce - drops unnecessary RNS limbs (levels) from the ciphertext and evaluation key
- Parameters
ciphertext – input ciphertext. Supported only in BGV/CKKS.
evalKey – input evaluation key (modified in place)
- Returns
the ciphertext with reduced number opf RNS limbs
-
inline void LevelReduceInPlace(Ciphertext<Element> &ciphertext, const EvalKey<Element> evalKey, size_t levels = 1) const
LevelReduceInPlace - drops unnecessary RNS limbs (levels) from the ciphertext and evaluation key. Supported only in BGV/CKKS.
- Parameters
ciphertext – input ciphertext (modified in place)
evalKey – input evaluation key (modified in place)
-
inline Ciphertext<Element> Compress(ConstCiphertext<Element> ciphertext, uint32_t towersLeft = 1) const
Compress - Reduces the size of ciphertext modulus to minimize the communication cost before sending the encrypted result for decryption. Similar to ModReduce but for BFV where ModReduce is not exposed directly.
- Parameters
ciphertext – - input ciphertext
numTowers – - number of RNS limbs after compressing (default is 1)
- Returns
compressed ciphertext
-
inline Ciphertext<Element> EvalAddMany(const std::vector<Ciphertext<Element>> &ciphertextVec) const
EvalAddMany - Evaluate addition on a vector of ciphertexts. It computes the addition in a binary tree manner.
- Parameters
ctList – is the list of ciphertexts.
- Returns
new ciphertext.
-
inline Ciphertext<Element> EvalAddManyInPlace(std::vector<Ciphertext<Element>> &ciphertextVec) const
EvalAddManyInPlace - Evaluate addition on a vector of ciphertexts. Addition is computed in a binary tree manner. Difference with EvalAddMany is that EvalAddManyInPlace uses the input ciphertext vector to store intermediate results, to avoid the overhead of using extra tepmorary space.
- Parameters
ctList – is the list of ciphertexts.
- Returns
new ciphertext.
-
inline Ciphertext<Element> EvalMultMany(const std::vector<Ciphertext<Element>> &ciphertextVec) const
EvalMultMany - OpenFHE function for evaluating multiplication on ciphertext followed by relinearization operation (at the end). It computes the multiplication in a binary tree manner. Also, it reduces the number of elements in the ciphertext to two after each multiplication. Currently it assumes that the consecutive two input arguments have total number of ring elements smaller than the supported one (for the secret key degree used by EvalMultsKeyGen). Otherwise, it throws an error.
- Parameters
ciphertextVec – is the ciphertext list.
- Returns
new ciphertext.
-
inline Ciphertext<Element> EvalLinearWSum(std::vector<ConstCiphertext<Element>> &ciphertextVec, const std::vector<double> &constantVec) const
EvalLinearWSum - OpenFHE EvalLinearWSum method to compute a linear weighted sum. Supported only in CKKS.
- Parameters
ciphertextVec& – a list of ciphertexts
constantVec& – a list of weights
- Returns
new ciphertext containing the weighted sum
-
inline Ciphertext<Element> EvalLinearWSum(const std::vector<double> &constantsVec, std::vector<ConstCiphertext<Element>> &ciphertextVec) const
EvalLinearWSum - OpenFHE EvalLinearWSum method to compute a linear weighted sum. Supported only in CKKS.
- Parameters
constantVec& – a list of weights
ciphertextVec& – a list of ciphertexts
- Returns
new ciphertext containing the weighted sum
-
inline Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>> &ciphertextVec, const std::vector<double> &constantsVec) const
EvalLinearWSum - OpenFHE EvalLinearWSum method to compute a linear weighted sum (mutable version). Supported only in CKKS.
- Parameters
ciphertextVec& – ciphertexts a list of mutable ciphertexts
constantVec& – constants a list of weights
- Returns
new ciphertext containing the weighted sum
-
inline Ciphertext<Element> EvalLinearWSumMutable(const std::vector<double> &constantsVec, std::vector<Ciphertext<Element>> &ciphertextVec) const
EvalLinearWSum - OpenFHE EvalLinearWSum method to compute a linear weighted sum (mutable version). Supported only in CKKS.
- Parameters
constantVec& – constants a list of weights
ciphertextVec& – ciphertexts a list of mutable ciphertexts
- Returns
new ciphertext containing the weighted sum
-
inline virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients) const
Method for evaluation for polynomials represented as power series. Supported only in CKKS. If the degree of the polynomial is less than 5, use EvalPolyLinear (naive linear method), otherwise, use EvalPolyPS (Paterson-Stockmeyer method).
- 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 Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients) const
Naive method for polynomial evaluation for polynomials represented in the power series (fast only for small-degree polynomials; less than 10). Uses a binary tree computation of the polynomial powers. Supported only in CKKS.
- Parameters
cipherText – input ciphertext
&coefficients – is the vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial
- Returns
the result of polynomial evaluation.
-
inline Ciphertext<Element> EvalPolyPS(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients) const
Paterson-Stockmeyer method for evaluation for polynomials represented in the power series. Supported only in CKKS.
- Parameters
cipherText – input ciphertext
&coefficients – is the vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial
- Returns
the result of polynomial evaluation.
-
inline 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 (naive linear method), otherwise, use EvalChebyshevSeriesPS (Paterson-Stockmeyer method). Supported only in CKKS.
- 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 Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients, double a, double b) const
Naive linear 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). Supported only in CKKS.
- 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 Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element> ciphertext, const std::vector<double> &coefficients, double a, double b) const
Paterson-Stockmeyer 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). Supported only in CKKS.
- 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.
-
Ciphertext<Element> EvalChebyshevFunction(std::function<double(double)> func, ConstCiphertext<Element> ciphertext, double a, double b, uint32_t degree) const
Method for calculating Chebyshev evaluation on a ciphertext for a smooth input function over the range [a,b]. Supported only in CKKS.
- Parameters
func – is the function to be approximated
ciphertext – input ciphertext
a – - lower bound of argument for which the coefficients were found
b – - upper bound of argument for which the coefficients were found
degree – Desired degree of approximation
- Returns
the coefficients of the Chebyshev approximation.
-
Ciphertext<Element> EvalSin(ConstCiphertext<Element> ciphertext, double a, double b, uint32_t degree) const
Evaluate approximate sine function on a ciphertext using the Chebyshev approximation. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
a – - lower bound of argument for which the coefficients were found
b – - upper bound of argument for which the coefficients were found
degree – Desired degree of approximation
- Returns
the result of polynomial evaluation.
-
Ciphertext<Element> EvalCos(ConstCiphertext<Element> ciphertext, double a, double b, uint32_t degree) const
Evaluate approximate cosine function on a ciphertext using the Chebyshev approximation. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
a – - lower bound of argument for which the coefficients were found
b – - upper bound of argument for which the coefficients were found
degree – Desired degree of approximation
- Returns
the result of polynomial evaluation.
-
Ciphertext<Element> EvalLogistic(ConstCiphertext<Element> ciphertext, double a, double b, uint32_t degree) const
Evaluate approximate logistic function 1/(1 + exp(-x)) on a ciphertext using the Chebyshev approximation. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
a – - lower bound of argument for which the coefficients were found
b – - upper bound of argument for which the coefficients were found
degree – Desired degree of approximation
- Returns
the result of polynomial evaluation.
-
Ciphertext<Element> EvalDivide(ConstCiphertext<Element> ciphertext, double a, double b, uint32_t degree) const
Evaluate approximate division function 1/x where x >= 1 on a ciphertext using the Chebyshev approximation. Supported only in CKKS.
- Parameters
ciphertext – input ciphertext
a – - lower bound of argument for which the coefficients were found
b – - upper bound of argument for which the coefficients were found
degree – Desired degree of approximation
- Returns
the result of polynomial evaluation.
-
void EvalSumKeyGen(const PrivateKey<Element> privateKey, const PublicKey<Element> publicKey = nullptr)
EvalSumKeyGen Generates the key map to be used by EvalSum
- Parameters
privateKey – private key.
publicKey – public key (used in NTRU schemes).
-
std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalSumRowsKeyGen(const PrivateKey<Element> privateKey, const PublicKey<Element> publicKey = nullptr, usint rowSize = 0, usint subringDim = 0)
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
-
std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalSumColsKeyGen(const PrivateKey<Element> privateKey, const PublicKey<Element> publicKey = nullptr)
Generates the automorphism keys for EvalSumCols; works only for packed encoding
- Parameters
privateKey – private key.
publicKey – public key.
- Returns
returns the evaluation keys
-
Ciphertext<Element> EvalSum(ConstCiphertext<Element> ciphertext, usint batchSize) const
Function for evaluating a sum of all components in a vector.
- Parameters
ciphertext – the input ciphertext.
batchSize – size of the batch
- Returns
resulting ciphertext
-
Ciphertext<Element> EvalSumRows(ConstCiphertext<Element> ciphertext, usint rowSize, const std::map<usint, EvalKey<Element>> &evalSumKeyMap, usint subringDim = 0) 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
&evalSumKeyMap – - 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.
- Returns
resulting ciphertext
-
Ciphertext<Element> EvalSumCols(ConstCiphertext<Element> ciphertext, usint rowSize, const std::map<usint, EvalKey<Element>> &evalSumKeyMap) 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 matrix
&evalSumKeyMap – - reference to the map of evaluation keys generated by
- Returns
resulting ciphertext
-
Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2, usint batchSize) const
Evaluates inner product in packed encoding (uses EvalSum)
- Parameters
ciphertext1 – first vector.
ciphertext2 – second vector.
batchSize – size of the batch to be summed up
- Returns
resulting ciphertext
-
Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext, usint batchSize) const
Evaluates inner product in packed encoding (uses EvalSum)
- Parameters
ciphertext1 – first vector - ciphertext.
plaintext – second vector - plaintext.
batchSize – size of the batch to be summed up
- Returns
resulting ciphertext
-
Ciphertext<Element> EvalMerge(const std::vector<Ciphertext<Element>> &ciphertextVec) 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. Requires the generation of rotation keys for the indices that are needed.
- Parameters
ciphertextVector – vector of ciphertexts to be merged.
- Returns
resulting ciphertext
-
inline EvalKey<Element> ReKeyGen(const PrivateKey<Element> oldPrivateKey, const PublicKey<Element> newPublicKey) const
ReKeyGen produces an Eval Key that OpenFHE can use for Proxy Re-Encryption
- Parameters
oldPrivateKey – original secret key
newPublicKey – public key for the new secret key
- Returns
new evaluation key
-
EvalKey<Element> ReKeyGen(const PrivateKey<Element> originalPrivateKey, const PrivateKey<Element> newPrivateKey) const __attribute__((deprecated("functionality removed from OpenFHE")))
ReKeyGen produces an Eval Key that OpenFHE can use for Proxy Re-Encryption NOTE this functionality has been completely removed from OpenFHE
- Parameters
oldPrivateKey – original secret key
newPrivateKey – new secret key
- Returns
new evaluation key
-
inline Ciphertext<Element> ReEncrypt(ConstCiphertext<Element> ciphertext, EvalKey<Element> evalKey, const PublicKey<Element> publicKey = nullptr) const
ReEncrypt - Proxy Re-Encryption mechanism for OpenFHE
- Parameters
ciphertext – - input ciphertext
evalKey – - evaluation key from the PRE keygen method
publicKey – the public key of the recipient of the re-encrypted ciphertext.
- Returns
the resulting ciphertext
-
inline KeyPair<Element> MultipartyKeyGen(const std::vector<PrivateKey<Element>> &privateKeyVec)
Threshold FHE: Generates a public key from a vector of secret shares. ONLY FOR DEBUGGIN PURPOSES. SHOULD NOT BE USED IN PRODUCTION.
- Parameters
&privateKeyVec – secrete key shares.
- Returns
key pair including the private for the current party and joined public key
-
inline KeyPair<Element> MultipartyKeyGen(const PublicKey<Element> publicKey, bool makeSparse = false, bool fresh = false)
Threshold FHE: Generation of a public key derived from a previous joined public key (for prior secret shares) and the secret key share of the current party.
- Parameters
publicKey – joined public key from prior parties.
makeSparse – set to true if ring reduce by a factor of 2 is to be used. NOT SUPPORTED BY ANY SCHEME ANYMORE.
fresh – set to true if proxy re-encryption is used in the multi-party protocol or star topology is used
- Returns
key pair including the secret share for the current party and joined public key
-
inline std::vector<Ciphertext<Element>> MultipartyDecryptLead(const std::vector<Ciphertext<Element>> &ciphertextVec, const PrivateKey<Element> privateKey) const
Threshold FHE: Method for decryption operation run by the lead decryption client
- Parameters
&ciphertextVec – a vector of ciphertexts
privateKey – secret key share used for decryption. @returm vector of partially decrypted ciphertexts.
-
inline std::vector<Ciphertext<Element>> MultipartyDecryptMain(const std::vector<Ciphertext<Element>> &ciphertextVec, const PrivateKey<Element> privateKey) const
Threshold FHE: “Partial” decryption computed by all parties except for the lead one
- Parameters
&ciphertextVec – a vector of ciphertexts
privateKey – secret key share used for decryption. @returm vector of partially decrypted ciphertexts.
-
inline DecryptResult MultipartyDecryptFusion(const std::vector<Ciphertext<Element>> &partialCiphertextVec, Plaintext *plaintext) const
Threshold FHE: Method for combining the partially decrypted ciphertexts and getting the final decryption in the clear.
- Parameters
&partialCiphertextVec – vector of “partial” decryptions.
*plaintext – the plaintext output.
- Returns
the decoding result.
-
inline EvalKey<Element> MultiKeySwitchGen(const PrivateKey<Element> originalPrivateKey, const PrivateKey<Element> newPrivateKey, const EvalKey<Element> evalKey) const
Threshold FHE: Generates a joined evaluation key from the current secret share and a prior joined evaluation key
- Parameters
originalPrivateKey – secret key transformed from.
newPrivateKey – secret key transformed to.
ek – the prior joined evaluation key.
- Returns
the new joined evaluation key.
Threshold FHE: Generates joined automorphism keys from the current secret share and prior joined automorphism keys
- Parameters
privateKey – secret key share.
evalKeyMap – a dictionary with prior joined automorphism keys.
&indexList – a vector of automorphism indices.
keyId – - new key identifier used for the resulting evaluation key
- Returns
a dictionary with new joined automorphism keys.
Threshold FHE: Generates joined rotation keys from the current secret share and prior joined rotation keys
- Parameters
privateKey – secret key share.
evalKeyMap – a dictionary with prior joined rotation keys.
&indexList – a vector of rotation indices.
keyId – - new key identifier used for the resulting evaluation key
- Returns
a dictionary with new joined rotation keys.
Threshold FHE: Generates joined summation evaluation keys from the current secret share and prior joined summation keys
- Parameters
privateKey – secret key share.
evalKeyMap – a dictionary with prior joined summation keys.
keyId – - new key identifier used for the resulting evaluation key
- Returns
new joined summation keys.
-
inline EvalKey<Element> MultiAddEvalKeys(EvalKey<Element> evalKey1, EvalKey<Element> evalKey2, const std::string &keyId = "")
Threshold FHE: Adds two prior evaluation keys
- Parameters
evalKey1 – first evaluation key.
evalKey2 – second evaluation key.
keyId – - new key identifier used for the resulting evaluation key
- Returns
the new joined key.
-
inline EvalKey<Element> MultiMultEvalKey(PrivateKey<Element> privateKey, EvalKey<Element> evalKey, const std::string &keyId = "")
Threshold FHE: Generates a partial evaluation key for homomorphic multiplication based on the current secret share and an existing partial evaluation key
- Parameters
privateKey – current secret share.
evalKey – prior evaluation key.
keyId – - new key identifier used for the resulting evaluation key
- Returns
the new joined key.
Threshold FHE: Adds two prior evaluation key sets for summation
- Parameters
evalKeyMap1 – first summation key set.
evalKeyMap2 – second summation key set.
keyId – - new key identifier used for the resulting evaluation key
- Returns
the new joined key set for summation.
Threshold FHE: Adds two prior evaluation key sets for automorphisms
- Parameters
evalKeyMap1 – first automorphism key set.
evalKeyMap2 – second automorphism key set.
keyId – - new key identifier used for the resulting evaluation key.
- Returns
the new joined key set for summation.
-
inline PublicKey<Element> MultiAddPubKeys(PublicKey<Element> publicKey1, PublicKey<Element> publicKey2, const std::string &keyId = "")
Threshold FHE: Adds two partial public keys
- Parameters
publicKey1 – first public key.
publicKey2 – second public key.
keyId – - new key identifier used for the resulting evaluation key.
- Returns
the new joined key.
-
inline EvalKey<Element> MultiAddEvalMultKeys(EvalKey<Element> evalKey1, EvalKey<Element> evalKey2, const std::string &keyId = "")
Threshold FHE: Adds two partial evaluation keys for multiplication
- Parameters
evalKey1 – first evaluation key.
evalKey2 – second evaluation key.
keyId – - new key identifier used for the resulting evaluation key.
- Returns
the new joined key.
-
Ciphertext<Element> IntMPBootAdjustScale(ConstCiphertext<Element> ciphertext) const
Threshold FHE: Prepare a ciphertext for Multi-Party Interactive Bootstrapping.
- Parameters
ciphertext – Input Ciphertext
- Returns
: Resulting Ciphertext
-
Ciphertext<Element> IntMPBootRandomElementGen(const PublicKey<Element> publicKey) const
Threshold FHE: Generate a common random polynomial for Multi-Party Interactive Bootstrapping
- Parameters
publicKey – the scheme public key (you can also provide the lead party’s public-key)
- Returns
: Resulting ring element
-
std::vector<Ciphertext<Element>> IntMPBootDecrypt(const PrivateKey<Element> privateKey, ConstCiphertext<Element> ciphertext, ConstCiphertext<Element> a) const
Threshold FHE: Does masked decryption as part of Multi-Party Interactive Bootstrapping. Each party calls this function as part of the protocol
- Parameters
privateKey – secret key share for party i
ciphertext – input ciphertext
a – input common random polynomial
- Returns
: Resulting masked decryption
-
std::vector<Ciphertext<Element>> IntMPBootAdd(std::vector<std::vector<Ciphertext<Element>>> &sharesPairVec) const
Threshold FHE: Aggregates a vector of masked decryptions and re-encryotion shares, which is the second step of the interactive multiparty bootstrapping procedure.
- Parameters
sharesPairVec – vector of pair of ciphertexts, each element of this vector contains (h_0i, h_1i) - the masked-decryption and encryption shares ofparty i
- Returns
: aggregated pair of shares ((h_0, h_1)
-
Ciphertext<Element> IntMPBootEncrypt(const PublicKey<Element> publicKey, const std::vector<Ciphertext<Element>> &sharesPair, ConstCiphertext<Element> a, ConstCiphertext<Element> ciphertext) const
Threshold FHE: Does public key encryption of lead party’s masked decryption as part of interactive multi-party bootstrapping, which increases the ciphertext modulus and enables future computations. This operation is done by the lead party as the final step of interactive multi-party bootstrapping.
- Parameters
publicKey – the lead party’s public key
sharesPair – aggregated decryption and re-encryption shares
a – common random ring element
ciphertext – input ciphertext
- Returns
: Resulting encryption
Threshold FHE with aborts: secret sharing of secret key for aborts
- Parameters
&sk – secret key to be shared.
N – total number of parties.
threshold – - threshold number of parties.
index – - index of the party invoking the function.
shareType – - Type of secret sharing to be used - additive or shamir sharing.
- Returns
the secret shares of the secret key sk.
Threshold FHE with aborts: Recovers a secret key share from other existing secret shares.
- Parameters
&sk – secret recovered from the secret shares.
&sk_shares – secret shares.
N – total number of parties.
threshold – - threshold number of parties.
shareType – - Type of secret sharing to be used - additive or shamir sharing
- Returns
the recovered key from the secret shares assigned to sk.
-
inline void EvalBootstrapSetup(std::vector<uint32_t> levelBudget = {5, 4}, std::vector<uint32_t> dim1 = {0, 0}, uint32_t slots = 0, uint32_t correctionFactor = 0, bool precompute = true)
Bootstrap functionality: There are three methods that have to be called in this specific order:
EvalBootstrapSetup: computes and encodes the coefficients for encoding and decoding and stores the necessary parameters
EvalBootstrapKeyGen: computes and stores the keys for rotations and conjugation
EvalBootstrapPrecompute: computes and stores the plaintexts for encoding and decoding if not already done in EvalBootstrapSetup
EvalBootstrap: refreshes the given ciphertext Sets all parameters for both linear and FFT-like methods. Supported in CKKS only.
- Parameters
levelBudget – - vector of budgets for the amount of levels in encoding and decoding
dim1 – - vector of inner dimension in the baby-step giant-step routine for encoding and decoding
slots – - number of slots to be bootstrapped
correctionFactor – - value to internally rescale message by to improve precision of bootstrapping. If set to 0, we use the default logic. This value is only used when NATIVE_SIZE=64
precompute – - flag specifying whether to precompute the plaintexts for encoding and decoding.
-
inline void EvalBootstrapKeyGen(const PrivateKey<Element> privateKey, uint32_t slots)
Generates all automorphism keys for EvalBootstrap. Supported in CKKS only. EvalBootstrapKeyGen uses the baby-step/giant-step strategy.
- Parameters
privateKey – private key.
slots – number of slots to support permutations on
-
inline void EvalBootstrapPrecompute(uint32_t slots = 0)
Computes the plaintexts for encoding and decoding for both linear and FFT-like methods. Supported in CKKS only.
- Parameters
slots – - number of slots to be bootstrapped
-
inline Ciphertext<Element> EvalBootstrap(ConstCiphertext<Element> ciphertext, uint32_t numIterations = 1, uint32_t precision = 0) const
Defines the bootstrapping evaluation of ciphertext using either the FFT-like method or the linear method
- Parameters
ciphertext – the input ciphertext.
numIterations – number of iterations to run iterative bootstrapping (Meta-BTS). Increasing the iterations increases the precision of bootstrapping.
precision – precision of initial bootstrapping algorithm. This value is determined by the user experimentally by first running EvalBootstrap with numIterations = 1 and precision = 0 (unused).
- Returns
the refreshed ciphertext.
-
inline LWEPrivateKey EvalCKKStoFHEWSetup(SchSwchParams params)
Scheme switching between CKKS and FHEW functionality There are three methods that have to be called in this specific order:
EvalCKKStoFHEWSetup: generates a FHEW cryptocontext and returns the key, computes and encodes the coefficients for encoding and decoding and stores the necessary parameters
EvalCKKStoFHEWKeyGen: computes and stores the keys for rotations and conjugation
EvalCKKStoFHEW: returns the FHEW/CGGI ciphertext 1’. EvalFHEWtoCKKSwitchetup: takes in the CKKS cryptocontext and sets the parameters 2’. EvalFHEWtoCKKSKeyGen: computes and stores the switching key and the keys for rotations and conjugation 3’. EvalFHEWtoCKKS: returns the CKKS ciphertext 1’’. EvalSchemeSwitchingSetup: generates a FHEW cryptocontext and returns the key, computes and encodes the coefficients for encoding and decoding and stores the necessary parameters 2’’. EvalSchemeSwitchingKeyGen: computes and stores the switching key and the keys for rotations and conjugation 3’’. EvalCompareSchemeSwitching/EvalFuncSchemeSwitching: returns the CKKS ciphertext of the function specified Sets all parameters for switching from CKKS to FHEW
- Parameters
params – objects holding all necessary paramters
- Returns
the FHEW secret key TODO: add an overload for when BinFHEContext is already generated and fed as a parameter
-
inline void EvalCKKStoFHEWKeyGen(const KeyPair<Element> &keyPair, ConstLWEPrivateKey &lwesk)
Generates all keys for scheme switching: the rotation keys for the linear transform in the homomorphic decoding, conjugation keys, switching key from CKKS to FHEW
- Parameters
keypair – CKKS key pair
lwesk – FHEW secret key
-
inline void EvalCKKStoFHEWPrecompute(double scale = 1.0)
Performs precomputations for the homomorphic decoding in CKKS. Given as a separate method than EvalCKKStoFHEWSetup to allow the user to specify a scale that depends on the CKKS and FHEW cryptocontexts
- Parameters
scale – factor with which to scale the matrix in the linear transform
-
inline std::vector<std::shared_ptr<LWECiphertextImpl>> EvalCKKStoFHEW(ConstCiphertext<Element> ciphertext, uint32_t numCtxts = 0)
Performs the scheme switching on a CKKS ciphertext
- Parameters
ciphertext – CKKS ciphertext to switch
numCtxts – number of coefficients to extract from the CKKS ciphertext. If it is zero, it defaults to number of slots
- Returns
a vector of LWE ciphertexts of length the numCtxts
Sets all parameters for switching from FHEW to CKKS. The CKKS cryptocontext to switch to is already generated.
- Parameters
ccLWE – the FHEW cryptocontext from which to switch
numSlotsCKKS – number of FHEW ciphertexts that becomes the number of slots in CKKS encryption
logQ – size of ciphertext modulus in FHEW for large-precision evaluation
-
inline void EvalFHEWtoCKKSKeyGen(const KeyPair<Element> &keyPair, ConstLWEPrivateKey &lwesk, uint32_t numSlots = 0, uint32_t numCtxts = 0, uint32_t dim1 = 0, uint32_t L = 0)
Generates all keys for scheme switching: the rotation keys for the baby-step/giant-step strategy in the linear transform for the partial decryption, the switching key from FHEW to CKKS
- Parameters
keypair – CKKS key pair
lwesk – FHEW secret key
numSlots – number of slots for the CKKS encryption of the FHEW secret key
numCtxts – number of values to encrypt from the LWE ciphertexts in the new CKKS ciphertext
dim1 – baby-step for the linear transform
L – level on which the hom. decoding matrix should be. We want the hom. decoded ciphertext to be on the last level
Performs the scheme switching on a vector of FHEW ciphertexts
- Parameters
LWECiphertexts – FHEW/LWE ciphertexts to switch
numCtxts – number of values to encrypt from the LWE ciphertexts in the new CKKS ciphertext
numSlots – number of slots to use in the encoding in the new CKKS/RLWE ciphertext
p – plaintext modulus to use to decide postscaling, by default p = 4
pmin, pmax – plaintext space of the resulting messages (by default [0,2] assuming the LWE ciphertext had plaintext modulus p = 4 and only bits were encrypted)
dim1 – baby-step for the linear transform, necessary only for argmin
- Returns
a CKKS ciphertext encrypting in its slots the messages in the LWE ciphertexts
-
inline void SetParamsFromCKKSCryptocontext(SchSwchParams ¶ms)
Gets data from CKKS cryptocontext to set some parameters for scheme switching
-
inline LWEPrivateKey EvalSchemeSwitchingSetup(SchSwchParams ¶ms)
Sets all parameters for switching from CKKS to FHEW and back
- Parameters
params – objects holding all necessary paramters
- Returns
the FHEW secret key TODO: add an overload for when BinFHEContext is already generated and fed as a parameter
-
inline void EvalSchemeSwitchingKeyGen(const KeyPair<Element> &keyPair, ConstLWEPrivateKey &lwesk)
Generates all keys for scheme switching: the rotation keys for the linear transform for the homomorphic encoding and partial decryption, the switching key from FHEW to CKKS
- Parameters
keypair – CKKS key pair
lwesk – FHEW secret key
-
inline void EvalCompareSwitchPrecompute(uint32_t pLWE = 0, double scaleSign = 1.0, bool unit = false)
Performs precomputations for the homomorphic decoding in CKKS. Given as a separate method than EvalSchemeSwitchingSetup to allow the user to specify a scale that depends on the CKKS and FHEW cryptocontexts
- Parameters
pLWE – the desired plaintext modulus for the new FHEW ciphertexts
scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this
unit – whether the input messages are normalized to the unit circle
-
inline Ciphertext<Element> EvalCompareSchemeSwitching(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2, uint32_t numCtxts = 0, uint32_t numSlots = 0, uint32_t pLWE = 0, double scaleSign = 1.0, bool unit = false)
Performs the scheme switching on the difference of two CKKS ciphertexts to compare, evaluates the sign function over the resulting FHEW ciphertexts, then performs the scheme switching back to a CKKS ciphertext
- Parameters
ciphertext1, ciphertext2 – CKKS ciphertexts of messages that need to be compared
numCtxts – number of coefficients to extract from the CKKS ciphertext
numSlots – number of slots to encode the new CKKS ciphertext with
pLWE – the desired plaintext modulus for the new FHEW ciphertexts
scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this pLWE and scaleSign are given here only if the homomorphic decoding matrix is not scaled with the desired values
unit – whether the input messages are normalized to the unit circle
- Returns
a CKKS ciphertext encrypting in its slots the sign of messages in the LWE ciphertexts
-
inline std::vector<Ciphertext<Element>> EvalMinSchemeSwitching(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues = 0, uint32_t numSlots = 0, uint32_t pLWE = 0, double scaleSign = 1.0)
Computes the minimum and argument of the first numValues packed in a CKKS ciphertext via repeated scheme switchings to FHEW and back.
- Parameters
ciphertext – CKKS ciphertexts of values that need to be compared
publicKey – public key of the CKKS cryptocontext
numValues – number of values to extract from the CKKS ciphertext. We always assume for the moment numValues is a power of two
numSlots – number of slots to encode the new CKKS ciphertext with
pLWE – the desired plaintext modulus for the new FHEW ciphertexts
scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this pLWE and scaleSign are given here only if the homomorphic decoding matrix is not scaled with the desired values
- Returns
a vector of two CKKS ciphertexts where the first encrypts the minimum value and the second encrypts the index (in the representation specified by oneHot). The ciphertexts have junk after the first slot in the first ciphertext and after numValues in the second ciphertext if oneHot=true and after the first slot if oneHot=false.
-
inline std::vector<Ciphertext<Element>> EvalMinSchemeSwitchingAlt(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues = 0, uint32_t numSlots = 0, uint32_t pLWE = 0, double scaleSign = 1.0)
Same as EvalMinSchemeSwitching but performs more operations in FHEW than in CKKS. Slightly better precision but slower.
-
inline std::vector<Ciphertext<Element>> EvalMaxSchemeSwitching(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues = 0, uint32_t numSlots = 0, uint32_t pLWE = 0, double scaleSign = 1.0)
Computes the maximum and argument of the first numValues packed in a CKKS ciphertext via repeated scheme switchings to FHEW and back.
- Parameters
ciphertext – CKKS ciphertexts of values that need to be compared
publicKey – public key of the CKKS cryptocontext
numValues – number of values to extract from the CKKS ciphertext. We always assume for the moment numValues is a power of two
numSlots – number of slots to encode the new CKKS ciphertext with
pLWE – the desired plaintext modulus for the new FHEW ciphertexts
scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this pLWE and scaleSign are given here only if the homomorphic decoding matrix is not scaled with the desired values
- Returns
a vector of two CKKS ciphertexts where the first encrypts the maximum value and the second encrypts the index (in the representation specified by oneHot). The ciphertexts have junk after the first slot in the first ciphertext and after numValues in the second ciphertext if oneHot=true and after the first slot if oneHot=false.
-
inline std::vector<Ciphertext<Element>> EvalMaxSchemeSwitchingAlt(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues = 0, uint32_t numSlots = 0, uint32_t pLWE = 0, double scaleSign = 1.0)
Same as EvalMaxSchemeSwitching but performs more operations in FHEW than in CKKS. Slightly better precision but slower.
-
inline std::shared_ptr<lbcrypto::BinFHEContext> GetBinCCForSchemeSwitch()
-
inline Ciphertext<Element> GetSwkFC()
-
inline void SetSwkFC(Ciphertext<Element> FHEWtoCKKSswk)
-
inline virtual std::string SerializedObjectName() const override
-
DecryptResult Decrypt(ConstCiphertext<DCRTPoly> ciphertext, const PrivateKey<DCRTPoly> privateKey, Plaintext *plaintext)
-
DecryptResult MultipartyDecryptFusion(const std::vector<Ciphertext<DCRTPoly>> &partialCiphertextVec, Plaintext *plaintext) const
-
DecryptResult MultipartyDecryptFusion(const std::vector<Ciphertext<DCRTPoly>> &partialCiphertextVec, Plaintext *plaintext) const
Public Static Functions
-
template<typename ST>
static inline bool SerializeEvalMultKey(std::ostream &ser, const ST &sertype, std::string id = "") SerializeEvalMultKey for a single EvalMult key or all EvalMult keys
- Parameters
ser – - stream to serialize to
sertype – - type of serialization
id – for key to serialize - if empty std::string, serialize them all
- Returns
true on success
-
template<typename ST>
static inline bool SerializeEvalMultKey(std::ostream &ser, const ST &sertype, const CryptoContext<Element> cc) SerializeEvalMultKey for all EvalMultKeys made in a given context
- Parameters
ser – stream to serialize to
sertype – type of serialization
cc – whose keys should be serialized
- Returns
true on success (false on failure or no keys found)
-
template<typename ST>
static inline bool DeserializeEvalMultKey(std::istream &ser, const ST &sertype) DeserializeEvalMultKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContextImpl if necessary
- Parameters
serObj – - stream with a serialization
sertype – type of serialization
- Returns
true on success
-
static void ClearEvalMultKeys()
ClearEvalMultKeys - flush EvalMultKey cache
-
static void ClearEvalMultKeys(const std::string &id)
ClearEvalMultKeys - flush EvalMultKey cache for a given id
- Parameters
id – the correponding key id
-
static void ClearEvalMultKeys(const CryptoContext<Element> cc)
ClearEvalMultKeys - flush EvalMultKey cache for a given context
- Parameters
cc – crypto context
-
static void InsertEvalMultKey(const std::vector<EvalKey<Element>> &evalKeyVec)
InsertEvalMultKey - add the given vector of keys to the map, replacing the existing vector if there
- Parameters
evalKeyVec – vector of keys
-
template<typename ST>
static inline bool SerializeEvalSumKey(std::ostream &ser, const ST &sertype, std::string id = "") SerializeEvalSumKey for a single EvalSum key or all of the EvalSum keys
- Parameters
ser – - stream to serialize to
sertype – - type of serialization
id – - key to serialize; empty std::string means all keys
- Returns
true on success
-
template<typename ST>
static inline bool SerializeEvalSumKey(std::ostream &ser, const ST &sertype, const CryptoContext<Element> cc) SerializeEvalSumKey for all of the EvalSum keys for a context
- Parameters
ser – - stream to serialize to
sertype – - type of serialization
cc – - context
- Returns
true on success
-
template<typename ST>
static inline bool DeserializeEvalSumKey(std::istream &ser, const ST &sertype) DeserializeEvalSumKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContextImpl if necessary
- Parameters
ser – - stream to serialize from
sertype – - type of serialization
- Returns
true on success
-
static void ClearEvalSumKeys()
ClearEvalSumKeys - flush EvalSumKey cache
-
static void ClearEvalSumKeys(const std::string &id)
ClearEvalSumKeys - flush EvalSumKey cache for a given id
ClearEvalMultKeys - flush EvalMultKey cache for a given id
- Parameters
id – key id
id –
-
static void ClearEvalSumKeys(const CryptoContext<Element> cc)
ClearEvalSumKeys - flush EvalSumKey cache for a given context
ClearEvalMultKeys - flush EvalMultKey cache for a given context
- Parameters
cc – crypto context
cc –
InsertEvalSumKey - add the given map of keys to the map, replacing the existing map if there
- Parameters
evalKeyMap – key map
-
template<typename ST>
static inline bool SerializeEvalAutomorphismKey(std::ostream &ser, const ST &sertype, std::string id = "") SerializeEvalAutomorphismKey for a single EvalAuto key or all of the EvalAuto keys
- Parameters
ser – - stream to serialize to
sertype – - type of serialization
id – - key to serialize; empty std::string means all keys
- Returns
true on success
-
template<typename ST>
static inline bool SerializeEvalAutomorphismKey(std::ostream &ser, const ST &sertype, const CryptoContext<Element> cc) SerializeEvalAutomorphismKey for all of the EvalAuto keys for a context
- Parameters
ser – - stream to serialize to
sertype – - type of serialization
cc – - context
- Returns
true on success
-
template<typename ST>
static inline bool DeserializeEvalAutomorphismKey(std::istream &ser, const ST &sertype) DeserializeEvalAutomorphismKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContextImpl if necessary
- Parameters
ser – - stream to serialize from
sertype – - type of serialization
- Returns
true on success
-
static void ClearEvalAutomorphismKeys()
ClearEvalAutomorphismKeys - flush EvalAutomorphismKey cache
-
static void ClearEvalAutomorphismKeys(const std::string &id)
ClearEvalAutomorphismKeys - flush EvalAutomorphismKey cache for a given id
- Parameters
id –
-
static void ClearEvalAutomorphismKeys(const CryptoContext<Element> cc)
ClearEvalAutomorphismKeys - flush EvalAutomorphismKey cache for a given context
- Parameters
cc –
InsertEvalAutomorphismKey - add the given map of keys to the map, replacing the existing map if there
- Parameters
mapToInsert –
-
static std::map<std::string, std::vector<EvalKey<Element>>> &GetAllEvalMultKeys()
Get a map of relinearization keys for all secret keys
-
static const std::vector<EvalKey<Element>> &GetEvalMultKeyVector(const std::string &keyID)
Get relinearization keys for a specific secret key tag
-
static std::map<std::string, std::shared_ptr<std::map<usint, EvalKey<Element>>>> &GetAllEvalAutomorphismKeys()
Get a map of automorphism keys for all secret keys
-
static std::shared_ptr<std::map<usint, EvalKey<Element>>> GetEvalAutomorphismKeyMapPtr(const std::string &keyID)
Get automorphism keys for a specific secret key tag
-
static inline std::map<usint, EvalKey<Element>> &GetEvalAutomorphismKeyMap(const std::string &keyID)
-
static std::map<std::string, std::shared_ptr<std::map<usint, EvalKey<Element>>>> &GetAllEvalSumKeys()
Get a map of summation keys (each is composed of several automorphism keys) for all secret keys
-
static const std::map<usint, EvalKey<Element>> &GetEvalSumKeyMap(const std::string &id)
Get a map of summation keys (each is composed of several automorphism keys) for a specific secret key tag
-
static Plaintext GetPlaintextForDecrypt(PlaintextEncodings pte, std::shared_ptr<ParmType> evp, EncodingParams ep)
GetPlaintextForDecrypt returns a new Plaintext to be used in decryption.
- Parameters
pte – Type of plaintext we want to return
evp – Element parameters
ep – Encoding parameters
- Returns
plaintext
-
static std::vector<uint32_t> GetExistingEvalAutomorphismKeyIndices(const std::string &keyTag)
GetExistingEvalAutomorphismKeyIndices gets indices for all existing automorphism keys.
- Parameters
keyTag – map search id for the automorphism keys
- Returns
vector with all indices in the map. if nothing is found for the given keyTag, then the vector is empty
-
static std::vector<uint32_t> GetUniqueValues(std::vector<uint32_t> oldValues, std::vector<uint32_t> newValues)
GetUniqueValues compares 2 vectors to generate a vector with unique values from the 2nd vector.
- Parameters
oldValues – vector of integers to compare against (passed by value)
newValues – vector of integers to find unique values from (passed by value)
- Returns
vector with unique values from newValues
-
static inline uint32_t SerializedVersion()
Protected Functions
-
inline void TypeCheck(const ConstCiphertext<Element> a, const ConstCiphertext<Element> b, CALLER_INFO_ARGS_HDR) const
TypeCheck makes sure that an operation between two ciphertexts is permitted
- Parameters
a –
b –
-
inline void TypeCheck(const ConstCiphertext<Element> a, const ConstPlaintext &b, CALLER_INFO_ARGS_HDR) const
TypeCheck makes sure that an operation between a ciphertext and a plaintext is permitted
- Parameters
a –
b –
-
inline bool Mismatched(const CryptoContext<Element> a) const
-
inline void ValidateCiphertext(const ConstCiphertext<Element> &ciphertext, CALLER_INFO_ARGS_HDR) const
Protected Attributes
-
std::shared_ptr<CryptoParametersBase<Element>> params = {nullptr}
-
std::shared_ptr<SchemeBase<Element>> scheme = {nullptr}
-
SCHEME m_schemeId = {SCHEME::INVALID_SCHEME}
-
uint32_t m_keyGenLevel = {0}
-
PrivateKey<Element> privateKey
Friends
-
inline friend bool operator==(const CryptoContextImpl<Element> &a, const CryptoContextImpl<Element> &b)
Private method to compare two contexts; this is only used internally and is not generally available
- Parameters
a – - operand 1
b – - operand 2
- Returns
true if the implementations have identical parms and scheme
-
inline friend bool operator!=(const CryptoContextImpl<Element> &a, const CryptoContextImpl<Element> &b)
Private method to compare two contexts; this is only used internally and is not generally available
-
inline void SetPrivateKey(const PrivateKey<Element> privateKey)