PalisadeCkksContext#
- class PalisadeCkksContext#
An implementation of HeContext using the Palisade CKKS backend.
- init(self: pyhelayers.PalisadeCkksContext, req: pyhelayers.HeConfigRequirement) None #
Initializes this PalisadeCkksContext according the given requirement.
- Parameters:
req – an HeConfigRequirement object, indicating the required configuration parameters (e.g. securityLevel, numSlots).
- Raises:
RuntimeError – if it is not possible to fulfill the given requirement.
-
class PalisadeCkksContext : public helayers::HeContext#
Public Functions
-
PalisadeCkksContext()#
-
~PalisadeCkksContext()#
-
virtual void init(const HeConfigRequirement &req) override#
Internal use.
-
void init(const PalisadeCkksConfig &conf)#
-
void init(const PalisadeCkksConfig &conf, const PublicFunctions &publicFunctions)#
-
inline const vector<int32_t> &getRotateIndexes() const#
Get the rotation indexes supported by this context.
-
lbcrypto::LPKeyPair<lbcrypto::DCRTPoly> multiPartyKeyGen()#
Generates a multi-key key this party.
-
lbcrypto::LPKeyPair<lbcrypto::DCRTPoly> multiPartyKeyGen(lbcrypto::LPPublicKey<lbcrypto::DCRTPoly> pk)#
Generates a multi-key key for this party based on a given public key.
- Parameters:
pk – A public key on which to base the generation of a multi-key key
-
lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> keySwitchGen(const lbcrypto::LPPrivateKey<lbcrypto::DCRTPoly> key1, const lbcrypto::LPPrivateKey<lbcrypto::DCRTPoly> key2)#
-
lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> multiKeySwitchGen(const lbcrypto::LPPrivateKey<lbcrypto::DCRTPoly> originalPrivateKey, const lbcrypto::LPPrivateKey<lbcrypto::DCRTPoly> newPrivateKey, const lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> ek)#
-
lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> multiAddEvalKeys(lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> a, lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> b, const std::string &keyId = "")#
-
lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> multiMultEvalKey(lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> evalKey, lbcrypto::LPPrivateKey<lbcrypto::DCRTPoly> sk, const std::string &keyId = "")#
-
void insertEvalMultKey(const std::vector<lbcrypto::LPEvalKey<lbcrypto::DCRTPoly>> &vectorToInsert)#
-
lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> multiAddEvalMultKeys(lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> evalKey1, lbcrypto::LPEvalKey<lbcrypto::DCRTPoly> evalKey2, const std::string &keyId = "")#
-
lbcrypto::LPPublicKey<lbcrypto::DCRTPoly> multiAddPubKeys(lbcrypto::LPPublicKey<lbcrypto::DCRTPoly> pubKey1, lbcrypto::LPPublicKey<lbcrypto::DCRTPoly> pubKey2, const std::string &keyId)#
-
virtual std::shared_ptr<MultiPartyUtils> getMultiPartyUtils() override#
Get a MultiPartyUtils for this context.
-
virtual std::shared_ptr<MultiPartyUtils> getMultiPartyUtils() const override#
-
virtual void printSignature(std::ostream &out) const override#
Prints a summary of library details and configuration params.
- Parameters:
out – [in] output stream to write to
-
virtual bool isConfigRequirementFeasible(const HeConfigRequirement &req) const override#
Internal use.
-
virtual int getBestFeasibleFractionalPartPrecision(const HeConfigRequirement &req) const override#
Returns the best feasible fractional part precision under the given configuration requirement.
If there is no such a fractional part precision, returns -1. All the fields of the given requirement other than req.fractionalPartPrecision are expected to be present, while any value in req.fractionalPartPrecision will be ignored.
- Parameters:
req – The requirement to get best fractional part precision for.
-
virtual int getBestFeasibleMulDepth(const HeConfigRequirement &req) const override#
Returns the best feasible multiplication depth under the given configuration requirement.
If there is no such a multiplication depth, returns -1. All the fields of the given requirement other than req.multiplicationDepth are expected to be present, while any value in req.multiplicationDepth will be ignored.
- Parameters:
req – The requirement to get best multiplication depth for.
-
virtual std::shared_ptr<AbstractCiphertext> createAbstractCipher() const override#
Do not use. Should be made private.
-
virtual std::shared_ptr<AbstractPlaintext> createAbstractPlain() const override#
Do not use. Should be made private.
-
virtual std::shared_ptr<AbstractEncoder> getEncoder() const override#
Do not use. Should be made private.
-
virtual int getTopChainIndex() const override#
Returns the highest available chain index (for schemes where it is applicable).
-
inline virtual int slotCount() const override#
The number of slots in each CTile (ciphertext) or PTile (plaintext) created over this context.
-
virtual int getSecurityLevel() const override#
Returns the security level supplied by this context.
-
inline virtual bool hasSecretKey() const override#
Returns whether this context contains a secret key.
If not, decryption and other operations relying on decryption will not be available (will throw an exception).
-
virtual void saveSecretKey(std::ostream &out, bool seedOnly = false) override#
Save secret key to the given ostream.
- Parameters:
out – The binary stream to save to.
seedOnly – If true, only the seed used to control the secret key’s randomness will be saved, rather than the whole secret key.
- Throws:
runtime_error – If this HeContext doesn’t have a secret key. i.e. hasSecretKey() is false.
runtime_error – If seedOnly is true but the underlying HeContext does not support secret key I/O using seeds.
-
virtual void loadSecretKey(std::istream &in, bool seedOnly = false) override#
Load secret key from the given istream.
- Parameters:
in – The binary stream to load from.
seedOnly – If true, the seed of the secret key will be loaded from the given binary stream and the secret key will be generated using this seed.
- Throws:
runtime_error – If this HeContext already has a secret key. i.e. hasSecretKey() is true.
runtime_error – If seedOnly is true but the underlying HeContext does not support secret key I/O using seeds.
-
inline virtual std::string getLibraryName() const override#
Returns the name of the underlying library.
-
inline virtual std::string getSchemeName() const override#
Returns the name of the underlying scheme.
-
inline lbcrypto::CryptoContext<lbcrypto::DCRTPoly> getContext() const#
-
inline lbcrypto::RescalingTechnique getRescaleTechnique() const#
-
int sealChainIndexToPalisadeLevel(int chainIndex) const#
Maps the received chain index (in terms of SealCKKS) to the corresponding level (in terms of PalisadeCKKS).
Note that while the “chainIndex” term in SealCKKS corresponds to the “level” term in PalisadeCKKS, chain indexes in Seal start from a positive integer and decrease on each multiplication, levels in Palisade start from zero and increase on multiplications. This function does the mapping
- Parameters:
chainIndex – [in] Seal’s chain index to translate to Palisade’s level
-
int palisadeLevelToSealChainIndex(uint32_t level) const#
Maps the received level (in terms of PalisadeCKKS) to the corresponding chain index (in terms of SealCKKS).
Note that while the “chainIndex” term in SealCKKS corresponds to the “level” term in PalisadeCKKS, chain indexes in Seal start from a positive integer and decrease on each multiplication, levels in Palisade start from
- Parameters:
level – [in] Seal’s chain index to translate to Palisade’s level
-
inline lbcrypto::LPPublicKey<lbcrypto::DCRTPoly> getCollectivePublicKey() const#
-
inline void setCollectivePublicKey(lbcrypto::LPPublicKey<lbcrypto::DCRTPoly> collectivePublicKey)#
-
inline lbcrypto::LPKeyPair<lbcrypto::DCRTPoly> getKeys() const#
-
virtual std::shared_ptr<HeContext> clone() const override#
Returns an uninitialized context of the same type.
Used for dynamic type loading among others.
-
virtual int getMinSupportedNumSlots() const override#
Returns the minimal number of slots supported by this HE context.
-
virtual int getMaxSupportedNumSlots() const override#
Returns the maximal number of slots supported by this HE context.
-
virtual void assertSavePublicFunctionsSupported(const PublicFunctions &publicFunctions) const override#
Verifies that this HeContext supports calling save() method with the given PublicFunctions object.
- Parameters:
publicFunctions – The PublicFunctions object.
- Throws:
invalid_argument – If saving the given PublicFunctions object is not supported by this HeContext.
-
virtual bool publicFunctionsSupported(const PublicFunctions &publicFunctions) const override#
Returns whether the given PublicFunctions object is supported by this HeContext.
The given PublicFunctions object is assumed to be valid (see also PublicFunctions::validate()).
- Parameters:
publicFunctions – The PublicFunctions object.
-
virtual std::map<std::string, int64_t> getEstimatedMeasures() const override#
Returns a map estimating the run time and memory consumed by different operations made with this PalisadeCkksContext.
This function assumes the existence of a palisade.json file storing the required measures.
- Throws:
runtime_error – If the palisade.json file which is expected to contain the required measures, does not exist.
-
void clearKeys()#
Clears the multiplication and rotation keys, which are stored internally in PALISADE.
Public Static Functions
-
static lbcrypto::SecurityLevel intSecurityToPalisadeSecurity(int sec)#
Converts the given security level to Palisade’s SecurityLevel type.
- Parameters:
sec – The security level
-
static int getPolyModulusLength(int multiplicationDepth, int integerPartPrecision, int fractionalPartPrecision)#
Returns the modulus length corresponding to the given parameters.
- Parameters:
multiplicationDepth – The multiplication depth
integerPartPrecision – The integer part precision
fractionalPartPrecision – The fractional part precision
-
static PalisadeCkksConfig heConfReqToPalisadeConf(const HeConfigRequirement &req)#
Translates the given HeConfigRequirement to a PalisadeCkksConfig.
- Parameters:
req – The HeConfigRequirement.
-
static void clearAllContexts()#
Clears all contexts from the PALISADE internal contexts vector.
-
PalisadeCkksContext()#