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

A class generating public (encryption/evaluation) keys from a secret key. More...

#include <KeyGenerator.hpp>

Collaboration diagram for HEaaN::KeyGenerator:
Collaboration graph
[legend]

Public Member Functions

 KeyGenerator (const Context &context, const SecretKey &sk)
 Create a KeyGenerator object. More...
 
 KeyGenerator (const Context &context, const SecretKey &sk, const KeyPack &pack)
 Create a KeyGenerator object from an existing KeyPack object. More...
 
 KeyGenerator (const Context &context, const Context &context_sparse, const SecretKey &sk)
 Create a KeyGenerator object which can generate key that can perform sparse secret encapsulation, with the same parameter which context is constructed for. More...
 
 KeyGenerator (const Context &context, const Context &context_sparse, const SecretKey &sk, const KeyPack &pack)
 Create a KeyGenerator object from an existing pack object which can generate key that can which can perform sparse secret encapsulation, with the same parameter which context is constructed for. More...
 
void genEncryptionKey (void) const
 Generate an encryption key into the internal KeyPack object. More...
 
void genMultiplicationKey (void) const
 Generate a multiplication key into the internal KeyPack object. More...
 
void genConjugationKey (void) const
 Generate a conjugation key into the internal KeyPack object. More...
 
void genLeftRotationKey (u64 rot) const
 Generate a rotation key for the left rotation with rot steps, into the internal KeyPack object. More...
 
void genRightRotationKey (u64 rot) const
 Generate a rotation key for the right rotation with rot steps, into the internal KeyPack object. More...
 
void genRotationKeyBundle (void) const
 Generate a bundle of rotation keys. More...
 
void genSparseSecretEncapsulationKey (void) const
 Generate a pair of keys for sparse secret encapsulation. More...
 
void genCommonKeys (void) const
 Generate commonly used keys. More...
 
void genRotKeysForBootstrap (const u64 log_slots) const
 Generate rotation keys used for accelerating the bootstrapping process. More...
 
void save (const std::string &dir_path) const
 Save the generated keys in the internal KeyPack object into files. More...
 
void flush (void)
 Discard current internal KeyPack object. More...
 
KeyPack getKeyPack () const
 Extract the internal KeyPack object. More...
 

Private Attributes

const Context context_
 
const std::optional< Contextcontext_sparse_
 
KeyPack pack_
 The internal keypack object. More...
 
std::shared_ptr< KeyGeneratorImpl > impl_
 

Detailed Description

A class generating public (encryption/evaluation) keys from a secret key.

Constructor & Destructor Documentation

◆ KeyGenerator() [1/4]

HEaaN::KeyGenerator::KeyGenerator ( const Context context,
const SecretKey sk 
)
explicit

Create a KeyGenerator object.

This generator internally creates a KeyPack object, which the user can later extract by getKeyPack() function. The SecretKey sk_ should have the same context as the input context context_. Otherwise, throws 'RuntimeException'.

◆ KeyGenerator() [2/4]

HEaaN::KeyGenerator::KeyGenerator ( const Context context,
const SecretKey sk,
const KeyPack pack 
)
explicit

Create a KeyGenerator object from an existing KeyPack object.

The SecretKey sk should have the same context as the input context context. Otherwise, throws 'RuntimeException'.

◆ KeyGenerator() [3/4]

HEaaN::KeyGenerator::KeyGenerator ( const Context context,
const Context context_sparse,
const SecretKey sk 
)
explicit

Create a KeyGenerator object which can generate key that can perform sparse secret encapsulation, with the same parameter which context is constructed for.

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

◆ KeyGenerator() [4/4]

HEaaN::KeyGenerator::KeyGenerator ( const Context context,
const Context context_sparse,
const SecretKey sk,
const KeyPack pack 
)
explicit

Create a KeyGenerator object from an existing pack object which can generate key that can which can perform sparse secret encapsulation, with the same parameter which context is constructed for.

Exceptions
RuntimeExceptionif context_sparse is not a context constructed with the corresponding sparse parameter of context. Please refer to SparseParameterPresetFor() on ParameterPreset.hpp for the sparse parameters.

Member Function Documentation

◆ flush()

void HEaaN::KeyGenerator::flush ( void  )

Discard current internal KeyPack object.

◆ genCommonKeys()

void HEaaN::KeyGenerator::genCommonKeys ( void  ) const
inline

Generate commonly used keys.

Be cautious that for bigger parameter sets, this function creates a lot of public keys in the internal KeyPack object, causing a high memory usage. In order to prevent this, the user might want to not use this function directly, and do use other key generation functions in the class separately, and use save() and flush() between the key generation.

◆ genConjugationKey()

void HEaaN::KeyGenerator::genConjugationKey ( void  ) const

Generate a conjugation key into the internal KeyPack object.

◆ genEncryptionKey()

void HEaaN::KeyGenerator::genEncryptionKey ( void  ) const

Generate an encryption key into the internal KeyPack object.

◆ genLeftRotationKey()

void HEaaN::KeyGenerator::genLeftRotationKey ( u64  rot) const

Generate a rotation key for the left rotation with rot steps, into the internal KeyPack object.

◆ genMultiplicationKey()

void HEaaN::KeyGenerator::genMultiplicationKey ( void  ) const

Generate a multiplication key into the internal KeyPack object.

◆ genRightRotationKey()

void HEaaN::KeyGenerator::genRightRotationKey ( u64  rot) const

Generate a rotation key for the right rotation with rot steps, into the internal KeyPack object.

◆ genRotationKeyBundle()

void HEaaN::KeyGenerator::genRotationKeyBundle ( void  ) const

Generate a bundle of rotation keys.

This function creates rotations keys for the left and right rotations with all power-of-two steps, so that any arbitrary rotation can be decomposed as a composition of these base rotations.

◆ genRotKeysForBootstrap()

void HEaaN::KeyGenerator::genRotKeysForBootstrap ( const u64  log_slots) const

Generate rotation keys used for accelerating the bootstrapping process.

Parameters
[in]log_slots

This function generates only rotation keys. Bootstrapping process requires multiplication key and conjugation key, which are not generated in this function.

◆ genSparseSecretEncapsulationKey()

void HEaaN::KeyGenerator::genSparseSecretEncapsulationKey ( void  ) const

Generate a pair of keys for sparse secret encapsulation.

This function creates switching keys between the dense secret key and the sparse secret key so the sparse secret encapsulation can be performed during bootstrapping.

Exceptions
RuntimeException

◆ getKeyPack()

KeyPack HEaaN::KeyGenerator::getKeyPack ( ) const
inline

Extract the internal KeyPack object.

Keys might be generated again into the keypack after this getter function is called.

◆ save()

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

Save the generated keys in the internal KeyPack object into files.

Parameters
[in]dir_pathmust indicate a valid directory.

This function creates a subdirectory PK/ inside dirPath directory, and save all the keys in the cache of the KeyPack object into this subdirectory.

Member Data Documentation

◆ context_

const Context HEaaN::KeyGenerator::context_
private

◆ context_sparse_

const std::optional<Context> HEaaN::KeyGenerator::context_sparse_
private

◆ impl_

std::shared_ptr<KeyGeneratorImpl> HEaaN::KeyGenerator::impl_
private

◆ pack_

KeyPack HEaaN::KeyGenerator::pack_
private

The internal keypack object.


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