An abstract main class representing an underlying HE library & scheme, configured, initialized, and ready to start working. More...

#include <HeContext.h>

Inheritance diagram for helayers::HeContext:
helayers::HelibContext helayers::HelibBgvContext helayers::HelibCkksContext

Public Member Functions

 HeContext ()
 Constructs an empty object.
 
 HeContext (const HeContext &src)=delete
 Copy constructor. More...
 
HeContextoperator= (const HeContext &src)=delete
 Copy from another object. More...
 
virtual void init (const HeConfigRequirement &req)=0
 Internal use.
 
virtual bool isConfigRequirementFeasible (const HeConfigRequirement &req) const =0
 Internal use.
 
virtual std::shared_ptr< AbstractCiphertextcreateAbstractCipher ()=0
 Do not use. Should be made private.
 
virtual std::shared_ptr< AbstractPlaintextcreateAbstractPlain ()=0
 Do not use. Should be made private.
 
virtual std::shared_ptr< AbstractEncodergetEncoder ()=0
 Do not use. Should be made private.
 
virtual std::shared_ptr< AbstractFunctionEvaluatorgetFunctionEvaluator ()
 Do not use. Should be made private.
 
virtual std::shared_ptr< AbstractBitwiseEvaluatorgetBitwiseEvaluator ()
 Do not use. Should be made private.
 
const HeTraitsgetTraits ()
 Returns an HeTraits object containing various properties of the underlying scheme.
 
virtual bool hasSecretKey () const =0
 Returns whether this context contains a secret key. More...
 
virtual int slotCount () const =0
 The number of slots in each CTile (ciphertext) or PTile (plaintext) created over this context.
 
virtual int getTopChainIndex () const =0
 Returns the highest available chain index (for schemes where it is applicable).
 
virtual int getSecurityLevel () const =0
 Returns the security level supplied by this context.
 
virtual void printSignature (std::ostream &out=std::cout) const =0
 Prints a summary of library details and configuration params. More...
 
virtual void debugPrint (const std::string &title="", int verbose=0, std::ostream &out=std::cout) const =0
 Prints detailed information for debug purposes. More...
 
virtual std::shared_ptr< std::vector< uint64_t > > getModulusChain () const
 Returns the modulus chain bit length for each prime in the chain (where applicable).
 
virtual void save (std::ostream &out, bool withSecretKey)
 Saves this context to a stream in binary form. More...
 
virtual void load (std::istream &in)
 Loads context saved by the save() method. More...
 
virtual void saveSecretKey (std::ostream &out)=0
 Save secret key to the given ostream. More...
 
virtual void loadSecretKey (std::istream &in)=0
 Load secret key from the given istream. More...
 
void saveToFile (const std::string &fileName, bool withSecretKey)
 Saves this context to a file in binary form. More...
 
void loadFromFile (const std::string &fileName)
 Loads context saved by the saveToFile() method. More...
 
void saveSecretKeyToFile (const std::string &fileName)
 save secret key to the given file. More...
 
void loadSecretKeyFromFile (const std::string &fileName)
 load secret key from the given file. More...
 
virtual double getDefaultScale () const
 Returns default scale used in encoding (where applicable).
 
virtual void setDefaultScale (double v)
 Sets the default scale to be used in encoding (where applicable). More...
 
virtual std::string getLibraryName () const =0
 Returns the name of the underlying library.
 
virtual std::string getSchemeName () const =0
 Returns the name of the underlying scheme.
 
virtual std::string getSignature () const
 Returns a signature of the context that distinguishes it enough to be able to load previously stored contexts based on their signatures.
 
virtual std::shared_ptr< JsonWrappergetEstimatedLatencies () const
 For internal use.
 
virtual std::shared_ptr< HeContextclone () const
 Returns an uninitialized context of the same type. More...
 

Static Public Member Functions

static std::shared_ptr< HeContextloadHeContextFromFile (const std::string &fileName)
 Returns a pointer to a context initialized from file. More...
 
static std::shared_ptr< HeContextloadHeContext (std::istream &in)
 Returns a pointer to a context initialized from stream. More...
 
static bool internalRegisterContext (const HeContext *context)
 Registers a context object for the purpose of dynamic loading. More...
 

Protected Attributes

HeTraits traits
 

Detailed Description

An abstract main class representing an underlying HE library & scheme, configured, initialized, and ready to start working.

Upon initaliation, use on of the inheriting concrete classes such as HelibCkksContext. Then continue with a generic reference to HeContext to allow scheme obliviousness

This class bundles together all the data structures required for performing HE operations, including the keys. It either contains a public/private key pair, allowing all operations including decryption, or just the public key allowing everything but decryption.

It is used as input in constructor of many other classes in this library. For example, to create a ciphertext using the library represent by an HeContext, write: CTile c(he);

It can be further used to query various properties of the underlying scheme and library.

Constructor & Destructor Documentation

◆ HeContext()

helayers::HeContext::HeContext ( const HeContext src)
delete

Copy constructor.

Parameters
[in]srcObject to copy.

Member Function Documentation

◆ clone()

std::shared_ptr< HeContext > helayers::HeContext::clone ( ) const
virtual

Returns an uninitialized context of the same type.

Used for dynamic type loading among others.

Reimplemented in helayers::HelibCkksContext.

◆ debugPrint()

virtual void helayers::HeContext::debugPrint ( const std::string &  title = "",
int  verbose = 0,
std::ostream &  out = std::cout 
) const
pure virtual

Prints detailed information for debug purposes.

Parameters
[in]titleTitle to print along with the information.
[in]verboseVerbosity level
[in]outOutput stream to print to

Implemented in helayers::HelibContext.

◆ hasSecretKey()

virtual bool helayers::HeContext::hasSecretKey ( ) const
pure virtual

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).

Implemented in helayers::HelibContext.

◆ internalRegisterContext()

bool helayers::HeContext::internalRegisterContext ( const HeContext context)
static

Registers a context object for the purpose of dynamic loading.

Don't call this directly. Use REGISTER_CONTEXT (see above)

◆ load()

void helayers::HeContext::load ( std::istream &  in)
virtual

Loads context saved by the save() method.

Parameters
[in]outinput stream to read from

Reimplemented in helayers::HelibCkksContext, helayers::HelibContext, and helayers::HelibBgvContext.

◆ loadFromFile()

void helayers::HeContext::loadFromFile ( const std::string &  fileName)

Loads context saved by the saveToFile() method.

Parameters
[in]fileNamefile to read from

◆ loadHeContext()

std::shared_ptr< HeContext > helayers::HeContext::loadHeContext ( std::istream &  in)
static

Returns a pointer to a context initialized from stream.

Context type is dynamically determined by content of stream.

Parameters
[in]instream to read from

◆ loadHeContextFromFile()

std::shared_ptr< HeContext > helayers::HeContext::loadHeContextFromFile ( const std::string &  fileName)
static

Returns a pointer to a context initialized from file.

Context type is dynamically determined by content of file.

Parameters
[in]fileNamefile to read from

◆ loadSecretKey()

virtual void helayers::HeContext::loadSecretKey ( std::istream &  in)
pure virtual

Load secret key from the given istream.


Parameters
[in]istreamthe binary stream to load from.
Exceptions
runtime_errorif this HeContext already has a secret key. i.e. hasSecretKey() is ture.

Implemented in helayers::HelibContext.

◆ loadSecretKeyFromFile()

void helayers::HeContext::loadSecretKeyFromFile ( const std::string &  fileName)

load secret key from the given file.


Parameters
[in]fileNamethe path of the file to load from
Exceptions
runtime_errorif this HeContext already has a secret key. i.e. hasSecretKey() is ture.

◆ operator=()

HeContext& helayers::HeContext::operator= ( const HeContext src)
delete

Copy from another object.

Parameters
[in]srcObject to copy.

◆ printSignature()

virtual void helayers::HeContext::printSignature ( std::ostream &  out = std::cout) const
pure virtual

Prints a summary of library details and configuration params.

Parameters
[in]outoutput stream to write to

Implemented in helayers::HelibContext, and helayers::HelibBgvContext.

◆ save()

void helayers::HeContext::save ( std::ostream &  out,
bool  withSecretKey 
)
virtual

Saves this context to a stream in binary form.

Parameters
[in]outoutput stream to write to
[in]withSecretKeywhether to include the secret key

Reimplemented in helayers::HelibContext.

◆ saveSecretKey()

virtual void helayers::HeContext::saveSecretKey ( std::ostream &  out)
pure virtual

Save secret key to the given ostream.


Parameters
[out]ostreamthe binary stream to save to.
Exceptions
runtime_errorif this HeContext doesn't have a secret key. i.e. hasSecretKey() is false.

Implemented in helayers::HelibContext.

◆ saveSecretKeyToFile()

void helayers::HeContext::saveSecretKeyToFile ( const std::string &  fileName)

save secret key to the given file.


Parameters
[out]fileNamethe path of the file to save to.
Exceptions
runtime_errorif this HeContext doesn't have a secret key. i.e. hasSecretKey() is false.

◆ saveToFile()

void helayers::HeContext::saveToFile ( const std::string &  fileName,
bool  withSecretKey 
)

Saves this context to a file in binary form.

Parameters
[in]fileNamefile to write to
[in]withSecretKeywhether to include the secret key

◆ setDefaultScale()

virtual void helayers::HeContext::setDefaultScale ( double  v)
inlinevirtual

Sets the default scale to be used in encoding (where applicable).

Parameters
[in]vthe default scale

The documentation for this class was generated from the following files:
  • /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/HeContext.h
  • /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/HeContext.cpp