HEaaN
Crypto Lab's great homomorphic encryption library
Public Member Functions | Private Attributes | Friends | List of all members
HEaaN::KeyPack Class Reference

Class managing public keys. More...

#include <KeyPack.hpp>

Public Member Functions

 KeyPack (const Context &context)
 Create a KeyPack object. More...
 
 KeyPack (const Context &context, const Context &context_sparse)
 Create a KeyPack object which is capable of holding key for sparse secret encapsulation. More...
 
 KeyPack (const Context &context, const std::string &key_dir_path)
 Create a KeyPack object with a designated directory for saved keys. More...
 
 KeyPack (const Context &context, const Context &context_sparse, const std::string &key_dir_path)
 Create a KeyPack object with a designated directory for saved keys, for parameter supporting sparse secret encapsulation. More...
 
void loadEncKey (void)
 Load encryption key from a file to the memory. More...
 
void loadEncKey (std::istream &stream)
 
void loadMultKey (void)
 Load multiplication key from a file to the memory. More...
 
void loadMultKey (std::istream &stream)
 
void loadConjKey (void)
 Load conjugation key from file to memory. More...
 
void loadConjKey (std::istream &stream)
 
void loadLeftRotKey (const u64 rot)
 Load left rotation key (by rot) from file to memory. More...
 
void loadLeftRotKey (const u64 rot, std::istream &stream)
 
void loadRightRotKey (const u64 rot)
 Load right rotation key (by rot) from file to memory. More...
 
void loadRightRotKey (const u64 rot, std::istream &stream)
 
void loadSparseSecretEncapsulationKey (void)
 Load key for sparse secret encapsulation from file to memory. More...
 
void loadSparseSecretEncapsulationKey (std::istream &stream)
 
bool isEncKeyLoaded (void) const
 Check whether the Encryption Key is loaded in memory. More...
 
bool isMultKeyLoaded (void) const
 Check whether the Multiplication Key is loaded in memory. More...
 
bool isLeftRotKeyLoaded (const u64 rot) const
 Check whether the Left Rotation Key is loaded in memory. More...
 
bool isRightRotKeyLoaded (const u64 rot) const
 Check whether the Right Rotation Key is loaded in memory. More...
 
bool isConjKeyLoaded (void) const
 Check whether the Conjugation Key is loaded in memory. More...
 
bool isLeftRotKeyFileAvailable (const u64 rot) const
 Check whether the Left Rotation Key file is accessible. More...
 
bool isSparseSecretEncapsulationKeyLoaded () const
 Check whether the sparse secret encapsulation key is loaded in memory. More...
 
std::shared_ptr< EncryptionKey > getEncKey (void) const
 Get a pointer to the encryption key. More...
 
std::shared_ptr< EvaluationKey > getMultKey (void) const
 Get a pointer to the multiplication key. More...
 
std::shared_ptr< EvaluationKey > getLeftRotKey (const u64 rot) const
 Get a pointer to the left rotation key. More...
 
std::shared_ptr< EvaluationKey > getRightRotKey (const u64 rot) const
 Get a pointer to the right roation key. More...
 
std::shared_ptr< EvaluationKey > getConjKey (void) const
 Get a pointer to the conjugation key. More...
 
std::shared_ptr< SparseSecretEncapsulationKey > getSparseSecretEncapsulationKey (void) const
 Get a pointer to the key for sparse secret encapsulation. More...
 
void setKeyDirPath (const std::string &key_dir_path)
 Set the key directory for the keys in the current object. More...
 
void to (const Device &device)
 Make all the keys only usable at device. This can be useful in memory-constrained environment since it frees the spaces allocated for keys in other devices. More...
 
void save (std::ostream &stream) const
 Save multiplication, conjugation, encryption, sparse secret encapsulation, and all rotation keys to stream . More...
 
void load (std::istream &stream)
 Load multiplication, conjugation, encryption, sparse secret encapsulation, and all rotation keys from stream . The context used to construct this KeyPack should match that of the keys in the stream; otherwise, it is undefined behavior. More...
 
void save (const std::string &dir_path) const
 Save multiplication, conjugation, encryption, sparse secret encapsulation, and all rotation keys under a directory. More...
 

Private Attributes

std::shared_ptr< KeyPackImpl > impl_
 Pointer to the implementation class. More...
 
u64 num_max_slots_
 Maximal number of slots for the current context object. More...
 

Friends

class KeyGenerator
 

Detailed Description

Class managing public keys.

Constructor & Destructor Documentation

◆ KeyPack() [1/4]

HEaaN::KeyPack::KeyPack ( const Context context)
explicit

Create a KeyPack object.

◆ KeyPack() [2/4]

HEaaN::KeyPack::KeyPack ( const Context context,
const Context context_sparse 
)
explicit

Create a KeyPack object which is capable of holding key for sparse secret encapsulation.

◆ KeyPack() [3/4]

HEaaN::KeyPack::KeyPack ( const Context context,
const std::string &  key_dir_path 
)
explicit

Create a KeyPack object with a designated directory for saved keys.

Exceptions
RuntimeExceptionif either keyDirPath or keyDirPath + "/PK" (the designated location for public keys) is not a valid directory

◆ KeyPack() [4/4]

HEaaN::KeyPack::KeyPack ( const Context context,
const Context context_sparse,
const std::string &  key_dir_path 
)
explicit

Create a KeyPack object with a designated directory for saved keys, for parameter supporting sparse secret encapsulation.

Exceptions
RuntimeExceptionif either keyDirPath or keyDirPath + "/PK" (the designated location for public keys) is not a valid directory
RuntimeExceptionif context_sparse is not a context constructed with the corresponding sparse parameter of which constructed context. Please refer to SparseParameterPresetFor() on ParameterPreset.hpp for the sparse parameters.

Member Function Documentation

◆ getConjKey()

std::shared_ptr<EvaluationKey> HEaaN::KeyPack::getConjKey ( void  ) const

Get a pointer to the conjugation key.

This function first checks if the Conjugation Key is loaded in the memory (isConjKeyLoaded()). If it fails, then it tries to load the key from the file in the path, and if it fails again, then this function finally returns nullptr.

◆ getEncKey()

std::shared_ptr<EncryptionKey> HEaaN::KeyPack::getEncKey ( void  ) const

Get a pointer to the encryption key.

This function first checks if the Encryption Key is loaded in the memory (isEncKeyLoaded()). If it fails, then it tries to load the key from the file in the path, and if it fails again, then this function finally returns nullptr.

◆ getLeftRotKey()

std::shared_ptr<EvaluationKey> HEaaN::KeyPack::getLeftRotKey ( const u64  rot) const

Get a pointer to the left rotation key.

Parameters
[in]rotThe rotation index

This function first checks if the Rotation Key is loaded in the memory (isLeftRotKeyLoaded()). If it fails, then it tries to load the key from the file in the path, and if it fails again, then this function finally returns nullptr.

◆ getMultKey()

std::shared_ptr<EvaluationKey> HEaaN::KeyPack::getMultKey ( void  ) const

Get a pointer to the multiplication key.

This function first checks if the Multiplication Key is loaded in the memory (isMultKeyLoaded()). If it fails, then it tries to load the key from the file in the path, and if it fails again, then this function finally returns nullptr.

◆ getRightRotKey()

std::shared_ptr<EvaluationKey> HEaaN::KeyPack::getRightRotKey ( const u64  rot) const

Get a pointer to the right roation key.

Parameters
[in]rotThhe rotation index

This function first checks if the Rotation Key is loaded in the memory (isRightRotKeyLoaded()). If it fails, then it tries to load the key from the file in the path, and if it fails again, then this function finally returns nullptr.

◆ getSparseSecretEncapsulationKey()

std::shared_ptr<SparseSecretEncapsulationKey> HEaaN::KeyPack::getSparseSecretEncapsulationKey ( void  ) const

Get a pointer to the key for sparse secret encapsulation.

This function first checks if sparse secret encryption keys are loaded in the memory (isSparseSecretEncapsulationKeyLoaded()). If it fails, then it tries to load the keys from the file in the path, and if it fails again, then this function finally returns nullptr.

◆ isConjKeyLoaded()

bool HEaaN::KeyPack::isConjKeyLoaded ( void  ) const

Check whether the Conjugation Key is loaded in memory.

◆ isEncKeyLoaded()

bool HEaaN::KeyPack::isEncKeyLoaded ( void  ) const

Check whether the Encryption Key is loaded in memory.

◆ isLeftRotKeyFileAvailable()

bool HEaaN::KeyPack::isLeftRotKeyFileAvailable ( const u64  rot) const

Check whether the Left Rotation Key file is accessible.

◆ isLeftRotKeyLoaded()

bool HEaaN::KeyPack::isLeftRotKeyLoaded ( const u64  rot) const

Check whether the Left Rotation Key is loaded in memory.

Parameters
[in]rotRotation Key index.

◆ isMultKeyLoaded()

bool HEaaN::KeyPack::isMultKeyLoaded ( void  ) const

Check whether the Multiplication Key is loaded in memory.

◆ isRightRotKeyLoaded()

bool HEaaN::KeyPack::isRightRotKeyLoaded ( const u64  rot) const

Check whether the Right Rotation Key is loaded in memory.

Parameters
[in]rotRotation Key index.

◆ isSparseSecretEncapsulationKeyLoaded()

bool HEaaN::KeyPack::isSparseSecretEncapsulationKeyLoaded ( ) const

Check whether the sparse secret encapsulation key is loaded in memory.

◆ load()

void HEaaN::KeyPack::load ( std::istream &  stream)

Load multiplication, conjugation, encryption, sparse secret encapsulation, and all rotation keys from stream . The context used to construct this KeyPack should match that of the keys in the stream; otherwise, it is undefined behavior.

◆ loadConjKey() [1/2]

void HEaaN::KeyPack::loadConjKey ( std::istream &  stream)

◆ loadConjKey() [2/2]

void HEaaN::KeyPack::loadConjKey ( void  )

Load conjugation key from file to memory.

If the key is already loaded in the memory or it cannot find the key file, this function does nothing. If stream is specified, load from the stream.

◆ loadEncKey() [1/2]

void HEaaN::KeyPack::loadEncKey ( std::istream &  stream)

◆ loadEncKey() [2/2]

void HEaaN::KeyPack::loadEncKey ( void  )

Load encryption key from a file to the memory.

If the key is already loaded in the memory or it cannot find the key file, this function does nothing. If a stream is specified, load from the stream.

◆ loadLeftRotKey() [1/2]

void HEaaN::KeyPack::loadLeftRotKey ( const u64  rot)

Load left rotation key (by rot) from file to memory.

Parameters
[in]rotRotation index (left rotation)

If the key is already loaded in the memory or it cannot find the key file, this function does nothing. If stream is specified, load from the stream.

◆ loadLeftRotKey() [2/2]

void HEaaN::KeyPack::loadLeftRotKey ( const u64  rot,
std::istream &  stream 
)

◆ loadMultKey() [1/2]

void HEaaN::KeyPack::loadMultKey ( std::istream &  stream)

◆ loadMultKey() [2/2]

void HEaaN::KeyPack::loadMultKey ( void  )

Load multiplication key from a file to the memory.

If the key is already loaded in the memory or it cannot find the key file, this function does nothing. If stream is specified, load from the stream.

◆ loadRightRotKey() [1/2]

void HEaaN::KeyPack::loadRightRotKey ( const u64  rot)

Load right rotation key (by rot) from file to memory.

Parameters
[in]rotRotation index (right rotation)

If the key is already loaded in the memory or it cannot find the key file, this function does nothing. If stream is specified, load from the stream.

◆ loadRightRotKey() [2/2]

void HEaaN::KeyPack::loadRightRotKey ( const u64  rot,
std::istream &  stream 
)

◆ loadSparseSecretEncapsulationKey() [1/2]

void HEaaN::KeyPack::loadSparseSecretEncapsulationKey ( std::istream &  stream)

◆ loadSparseSecretEncapsulationKey() [2/2]

void HEaaN::KeyPack::loadSparseSecretEncapsulationKey ( void  )

Load key for sparse secret encapsulation from file to memory.

If the key is already loaded in the memory or it cannot find the key file, this function does nothing. If stream is specified, load from the stream.

◆ save() [1/2]

void HEaaN::KeyPack::save ( const std::string &  dir_path) const

Save multiplication, conjugation, encryption, sparse secret encapsulation, and all rotation keys under a directory.

◆ save() [2/2]

void HEaaN::KeyPack::save ( std::ostream &  stream) const

Save multiplication, conjugation, encryption, sparse secret encapsulation, and all rotation keys to stream .

◆ setKeyDirPath()

void HEaaN::KeyPack::setKeyDirPath ( const std::string &  key_dir_path)

Set the key directory for the keys in the current object.

◆ to()

void HEaaN::KeyPack::to ( const Device device)

Make all the keys only usable at device. This can be useful in memory-constrained environment since it frees the spaces allocated for keys in other devices.

Friends And Related Function Documentation

◆ KeyGenerator

friend class KeyGenerator
friend

Member Data Documentation

◆ impl_

std::shared_ptr<KeyPackImpl> HEaaN::KeyPack::impl_
private

Pointer to the implementation class.

◆ num_max_slots_

u64 HEaaN::KeyPack::num_max_slots_
private

Maximal number of slots for the current context object.


The documentation for this class was generated from the following file: