HeaanContext#
- class HeaanContext#
An implementation of HeContext using the HEaaN CKKS backend.
- get_parameter_preset_str(self: pyhelayers.HeaanContext) str #
Returns a string with the name of the HEaaN Parameter Preset of this HeaanContext object
- init(self: pyhelayers.HeaanContext, req: pyhelayers.HeConfigRequirement) None #
Initializes this HeaanContext 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.
- save_public_keys_to_dir(self: pyhelayers.HeaanContext, arg0: str) None #
Saves the public keys of this HeaanContext to the given directory
- Parameters:
dir – The path of the directory to save to.
- save_secret_key_to_dir(self: pyhelayers.HeaanContext, arg0: str) None #
Loads the secret keys of this HeaanContext from the given directory
- Parameters:
dir – The path of the directory to load from.
-
class HeaanContext : public helayers::HeContext#
An implementation of HeContext for HEaaN.
It can be either initialized via parameters, via an HeConfigRequirement, or loaded from a file.
It is recommended not to use directly after initialization, but use an HeContext reference instead.
Public Functions
-
HeaanContext()#
A constructor.
-
~HeaanContext() override#
-
virtual void init(const HeConfigRequirement &req) override#
Internal use.
-
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 HeConfigRequirement getActualConfigRequirement(const HeConfigRequirement &req) const override#
Returns the actual config requirement that will be enabled by the HE context when provided with the given config requirement.
Some parameters may differ from the original object and be “better”, e.g. higher multiplication depth.
- Parameters:
req – The given config requirement.
-
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.
-
int getMaxPolyModulusLength(int securityLevel, int polyModulusDegree) const#
-
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<AbstractMessage> createAbstractMessage() 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 std::shared_ptr<AbstractBootstrapEvaluator> createAbstractBootstrapEvaluator(const BootstrapConfig &bsConfig = BootstrapConfig()) const override#
Do not use. Should be made private.
-
inline virtual int getTopChainIndex() const override#
Returns the highest available chain index (for schemes where it is applicable).
-
virtual std::shared_ptr<std::vector<uint64_t>> getModulusChain() const override#
Returns the modulus chain: the value of each prime in the chain (where applicable).
-
inline int getLogSlots() const#
Returns the log number of slots of ciphertexts and plaintexts created by this HeaanContext.
-
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 const HEaaN::Context &getContext() const#
Returns the Context object of the underlying HEaaN library.
-
const HEaaN::SecretKey &getSecretKey(DeviceType deviceType = DEVICE_CPU, int deviceId = 0) const#
Returns the SecretKey object of the underlying HEaaN library.
- Parameters:
deviceType – The device type of the secret key.
deviceId – The device ID of the secret key.
- Throws:
runtime_error – if this HeaanContext does not have a secret key.
-
inline const HEaaN::KeyPack &getKeyPack() const#
Returns the KeyPack object of the underlying HEaaN library.
-
inline const HEaaN::EnDecoder &getEndecoder() const#
Returns the EnDecoder object of the underlying HEaaN library.
-
inline const HEaaN::Encryptor &getEncryptor() const#
Returns the Encryptor object of the underlying HEaaN library.
-
inline const HEaaN::HomEvaluator &getEvaluator() const#
Returns the Evaluator object of the underlying HEaaN library.
-
inline const HEaaN::Bootstrapper &getBootstrapper() const#
Returns the Bootstrapper object of the underlying HEaaN library.
-
inline const HEaaN::Decryptor &getDecryptor() const#
Returns the Decryptor object of the underlying HEaaN library.
- Throws:
runtime_error – if this HeaanContext does not have a secret key.
-
virtual double getDefaultScale() const override#
Returns default scale used in encoding (where applicable).
-
double getDefaultScale(int chainIndex) const#
Returns the default scale of ciphertexts and plaintexts created by this HeaanContext at a specific chain index.
- Parameters:
chainIndex – The chain index.
-
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.
-
virtual std::string getSignature() const override#
Returns a signature of the context that distinguishes it enough to be able to load previously stored contexts based on their signatures.
-
virtual std::map<std::string, int64_t> getEstimatedMeasures() const override#
For internal use.
-
virtual std::shared_ptr<HeContext> clone() const override#
Returns an uninitialized context of the same type.
Used for dynamic type loading among others.
-
virtual double getAccurateScale(int chainIndex) const override#
Returns the accurate scale to be used for a given chain index.
Only supported when accurate scaling mode is enabled. Cannot be called before the context is initialized.
- Parameters:
chainIndex – the chain index to get the scale of.
- Throws:
runtime_error – If this SealCkksContext is not initialized.
runtime_error – If accurate scaling is not enabled.
-
virtual int getMinChainIndexForBootstrapping() const override#
Assuming this HeContext is bootstrappable, returns the minimum level in which ciphertexts can be bootstrapped.
-
virtual int getChainIndexAfterBootstrapping() const override#
Assuming this HeContext is bootstrappable, returns the level of ciphertexts after bootstrapping.
-
virtual BootstrapConfig getBootstrapChainIndexes(const HeConfigRequirement &req) const override#
Returns a bootstrap config object with two chain index values: the minimum level in which ciphertexts can be bootstrapped and the level of ciphertexts after bootstrapping.
- Parameters:
req – The requirement, must indicate a bootstrappable object.
-
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 std::vector<double> getMaxAllowedValues() const override#
Returns the maximal absolute value allowed for each chain index.
Values lower than the threshold are guaranteed to not produce overflows. The value in position i corresponds to the limit for chain index i.
-
virtual double getMaxAllowedBsValue() const override#
Returns the maximal absolute value allowed for values going through a bootstrap operation.
-
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.
-
inline virtual int getNumDevicesOfType(DeviceType type) const override#
Returns the number of devices of the given type available for this HeContext to use.
- Parameters:
type – [in] The device type.
-
HeaanParameterPreset getHeaanParameterPreset() const#
Returns the HeaanParameterPreset object corresponding to the parameterPreset object of this HeaanContext.
-
std::string getParameterPresetStr() const#
Returns a string with the name of the HEaaN Parameter Preset of this HeaanContext object.
-
virtual void cudaDeviceSynchronize() const override#
Wait for GPU to finish all jobs.
Kernel execution is normally asynchronous, so while the GPU device is executing a kernel the CPU can continue to work on some other commands, issue more instructions to the GPU, etc. However, when using this synchronization command, the CPU is instead forced to idle until all the GPU work has completed before doing anything else. Use when measuring GPU operations run times with HELAYERS_TIMER. Notice that this synchronization slows down the entire execution, so use carefully.
Public Static Functions
-
static int getHeaanMinChainIndexForBootstrapping(BootstrapRange range = DEFAULT_RANGE)#
-
static inline std::map<HEaaN::ParameterPreset, HeaanParameterPreset> getParameterPresetsMap()#
Returns a mapping of HEAAN’s presets to their corresponding HeaanParameterPreset objects, which contains details on these presets (e.g.
numSlots and topChainIndex)
-
static inline DeviceType deviceTypeFromHeaanDeviceType(HEaaN::DeviceType deviceType)#
Given an HEaaN library DeviceType returns the corresponding HElayers DeviceType.
- Parameters:
deviceType – The HEaaN library DeviceType.
-
static inline HEaaN::DeviceType heaanDeviceTypeFromDeviceType(DeviceType deviceType)#
Given an HElayers DeviceType returns the corresponding HEaaN library DeviceType.
- Parameters:
deviceType – The HElayers DeviceType.
Public Static Attributes
-
static const int heaanMinCustomPrimeSize#
Min prime size for custom presets in the underlying HEaaN library.
-
static const int heaanMaxCustomPrimeSize#
Max prime size for custom presets in the underlying HEaaN library.
-
static const int heaanMaxCustomChainLength#
Max primes chain length for custom presets in the underlying HEaaN library.
-
HeaanContext()#