OpenFheContext#
- class OpenFheContext#
An abstract class for all OpenFHE context classes.
- clear_all_contexts() None #
Clears all global OpenFHE context objects from memory.
- clear_keys(self: pyhelayers.OpenFheContext) None #
Clears the multiplication and rotation keys from memory. In OpenFHE, the context object is global, and public keys are not cleared unless explicitly asked for.
-
class OpenFheContext : public helayers::HeContext#
An abstract class for all OpenFHE context classes.
It contains their common functionality. Note that it currently geared towards the PKE schemes. It may be further split in the future. OpenFHE supports cross-platform IO, meaning that a context that is saved using one operation system can be read using another operation system.
Subclassed by helayers::OpenFheBgvContext, helayers::OpenFheCkksContext, helayers::OpenFheTfheContext
Public Functions
-
OpenFheContext()#
Construct an uninitialized object.
-
virtual ~OpenFheContext()#
-
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 std::shared_ptr<AbstractBootstrapEvaluator> createAbstractBootstrapEvaluator(const BootstrapConfig &bsConfig = BootstrapConfig()) 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).
-
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.
-
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.
-
int chainIndexToOpenFheLevel(int chainIndex) const#
Maps the received chain index in terms of HELayers to the corresponding level in terms of OpenFHE.
Note that in HELayers chain indexes start from a positive integer and decrease on each multiplication, levels in OpenFHE start from zero and increase on multiplications. This function does the mapping
- Parameters:
chainIndex – [in] Input chain index to translate to OpenFHE’s level
-
int openFheLevelToChainIndex(uint32_t level) const#
Maps the received level in terms of OpenFHE to the corresponding chain index in terms of HeLayers.
See chainIndexToOpenFheLevel().
- Parameters:
level – [in] OpenFHE’s level to translate to chain index
-
virtual int getChainIndexAfterBootstrapping() const override#
Assuming this HeContext is bootstrappable, returns the level of ciphertexts after bootstrapping.
-
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).
-
void clearKeys()#
Clears the multiplication and rotation keys from memory.
In OpenFHE, the context object is global, and public keys are not cleared unless explicitly asked for.
Public Static Functions
-
static void clearAllContexts()#
Clears all global OpenFHE context objects from memory.
-
OpenFheContext()#