HEaaN
Crypto Lab's great homomorphic encryption library
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
HEaaN Namespace Reference

Namespaces

 CudaTools
 

Classes

class  Bootstrapper
 A class consisting of bootstrap and its related functions. More...
 
class  Ciphertext
 A class of ciphertexts each of which contains a vector of polynomials of length > 1. More...
 
struct  CollectiveKeyGenConfig
 Configuration for collective key generation on which key to generate. More...
 
class  CollectiveKeyGenData
 A class to describe data being transfered between parties on the process of generating public keys from secret keys provided by multiple parties. More...
 
class  CollectiveKeyGenerator
 A class generating public keys from secret keys provided by multiple parties. More...
 
class  Decryptor
 Abstract entity for decrypting ciphertexts. More...
 
class  Device
 
class  Encryptor
 Abstract entity for encrypting messages into ciphertexts. More...
 
class  EnDecoder
 Class containing functions dealing with message/plaintext encoding and decoding. More...
 
class  HomEvaluator
 A class consisting of basic operation of Ciphertext and Message. More...
 
class  KeyGenerator
 A class generating public (encryption/evaluation) keys from a secret key. More...
 
class  KeyPack
 Class managing public keys. More...
 
class  Message
 
class  Plaintext
 A class of plaintexts each of which is simply a polynomial. More...
 
class  Pointer
 A class holding unique_ptr but is copied with deepcopy. More...
 
class  RuntimeException
 
class  ScopedCudaDeviceSelector
 
class  SecretKey
 Secret key class. More...
 

Typedefs

using Context = std::shared_ptr< ContextContent >
 
using u64 = std::uint64_t
 
using i64 = std::int64_t
 
using u32 = std::uint32_t
 
using i32 = std::int32_t
 
using SeedType = std::array< u64, SEED_SIZE_IN_BYTES/8 >
 
using Real = double
 Default type for representing a real number. More...
 
using Complex = std::complex< Real >
 Default type for representing a complex number. More...
 
using DeviceSet = std::set< Device >
 
using CudaDeviceIds = std::set< int >
 

Enumerations

enum  DeviceType { DeviceType::CPU, DeviceType::GPU, DeviceType::UNDEFINED, DeviceType::CPU_PINNED }
 

Functions

HEAAN_API Context makeContext (const ParameterPreset &preset, const CudaDeviceIds &cuda_device_ids={})
 Make a context object based on a given parameter preset. More...
 
HEAAN_API Context makeContext (const u64 log_dimension, const u64 chain_length, const u64 bpsize, const u64 qpsize, const u64 tpsize, const u64 gadget_rank, const CudaDeviceIds &cuda_device_ids={})
 Make a context based on custom parameters. More...
 
HEAAN_API Context makeContextFromFile (const std::string &filename, const CudaDeviceIds &cuda_device_ids={})
 Make a context object from a "context file". More...
 
HEAAN_API void saveContextToFile (const Context &context, const std::string &filename)
 Save a context object into a file. More...
 
HEAAN_API u64 getLogFullSlots (const Context &context)
 Get the maximal logarithmic (base of 2) number of slots for the given context object. More...
 
HEAAN_API u64 getEncryptionLevel (const Context &context)
 Get the level of a fresh ciphertext, which is the maximum level that users can encrypt a ciphertext to. More...
 
HEAAN_API std::vector< RealgetDefaultScaleFactorList (const Context &context)
 Get the default list of scale factors. More...
 
HEAAN_API std::vector< u64getPrimeList (const Context &context)
 Get the list of primes. More...
 
HEAAN_API bool isBootstrappableParameter (const Context &context)
 Get whether the bootstrapping is supported. More...
 
HEAAN_API bool isSparseSecretEncapsulationSupported (const Context &context)
 Get whether the given context supports sparse secret encapsulation or not. More...
 
HEAAN_API bool isExtendedBootstrapSupported (const Context &context)
 Get whether the bootstrapping for extended range supported. More...
 
HEAAN_API std::set< i64getRotIndicesForBootstrap (const Context &context, u64 log_slots)
 Get the list of rotation key index for the bootstrapping process. More...
 
HEAAN_API SecurityLevel getSecurityLevel (const Context &context)
 Get the security level of the given context. More...
 
HEAAN_API void save (const EvaluationKey &key, std::ostream &stream)
 Save key to a given stream. More...
 
HEAAN_API void save (const EncryptionKey &key, std::ostream &stream)
 
HEAAN_API void save (const SparseSecretEncapsulationKey &key, std::ostream &stream)
 
HEAAN_API void load (EvaluationKey &key, std::istream &stream)
 Load key from a given stream. More...
 
HEAAN_API void load (EncryptionKey &key, std::istream &stream)
 
HEAAN_API void load (SparseSecretEncapsulationKey &key, std::istream &stream)
 
HEAAN_API ParameterPreset getSparseParameterPresetFor (ParameterPreset preset)
 Returns the parameter preset which is required to perform sparse secret encapsulation on bootstrapping for certain parameters. More...
 
HEAAN_API SeedType getSeed ()
 Get the random seed of the current HEaaN instance. More...
 
HEAAN_API void setSeed (const SeedType &new_global_seed)
 Set the random seed. More...
 
constexpr HEAAN_API Device getDefaultDevice ()
 
HEAAN_API Device getCurrentCudaDevice ()
 
HEAAN_API void setCurrentCudaDevice (int device_id)
 

Variables

constexpr u64 U64ZERO = UINT64_C(0)
 
constexpr u64 U64ONE = UINT64_C(1)
 
enum HEAAN_API ParameterPreset
 Class of Parameter presets. More...
 
enum HEAAN_API FVb
 
enum HEAAN_API FGa
 
enum HEAAN_API FGb
 
enum HEAAN_API FTa
 
enum HEAAN_API FTb
 
enum HEAAN_API ST19
 
enum HEAAN_API ST14
 
enum HEAAN_API ST11
 
enum HEAAN_API ST8
 
enum HEAAN_API ST7
 
enum HEAAN_API SS7
 
enum HEAAN_API SD3
 
enum HEAAN_API CUSTOM
 
enum HEAAN_API FVc
 
enum HEAAN_API FX
 
enum HEAAN_API FGd
 
enum HEAAN_API SGd0
 
template class HEAAN_API Pointer< PlaintextImpl >
 
template class HEAAN_API Pointer< CiphertextImpl >
 
template class HEAAN_API Pointer< MessageImpl >
 
template class HEAAN_API Pointer< SecretKeyImpl >
 
template class HEAAN_API Pointer< CollectiveKeyGenDataImpl >
 
constexpr const u64 SEED_SIZE_IN_BYTES {32}
 
constexpr Real REAL_ZERO = 0.0
 Real number 0. More...
 
constexpr Real REAL_ONE = 1.0
 Real number 1. More...
 
constexpr Real REAL_PI = 3.14159265358979323846
 Real number pi. More...
 
constexpr Complex COMPLEX_ZERO = Complex(REAL_ZERO, REAL_ZERO)
 Complex number 0. More...
 
constexpr Complex COMPLEX_IMAG_UNIT = Complex(REAL_ZERO, REAL_ONE)
 Complex number i. More...
 
enum HEAAN_API SecurityLevel
 Enum class for security levels. More...
 
enum HEAAN_API Classical128 = 128
 at least 128-bit security level classically. More...
 
enum HEAAN_API Classical192 = 192
 at least 192-bit security level classically. More...
 
enum HEAAN_API Classical256 = 256
 at least 256-bit security level classically. More...
 

Typedef Documentation

◆ Complex

using HEaaN::Complex = typedef std::complex<Real>

Default type for representing a complex number.

◆ Context

using HEaaN::Context = typedef std::shared_ptr<ContextContent>

◆ CudaDeviceIds

using HEaaN::CudaDeviceIds = typedef std::set<int>

◆ DeviceSet

using HEaaN::DeviceSet = typedef std::set<Device>

◆ i32

using HEaaN::i32 = typedef std::int32_t

◆ i64

using HEaaN::i64 = typedef std::int64_t

◆ Real

using HEaaN::Real = typedef double

Default type for representing a real number.

◆ SeedType

using HEaaN::SeedType = typedef std::array<u64, SEED_SIZE_IN_BYTES / 8>

◆ u32

using HEaaN::u32 = typedef std::uint32_t

◆ u64

using HEaaN::u64 = typedef std::uint64_t

Enumeration Type Documentation

◆ DeviceType

enum HEaaN::DeviceType
strong
Enumerator
CPU 
GPU 
UNDEFINED 
CPU_PINNED 

Function Documentation

◆ getCurrentCudaDevice()

HEAAN_API Device HEaaN::getCurrentCudaDevice ( )

◆ getDefaultDevice()

constexpr HEAAN_API Device HEaaN::getDefaultDevice ( )
constexpr

◆ getDefaultScaleFactorList()

HEAAN_API std::vector<Real> HEaaN::getDefaultScaleFactorList ( const Context context)

Get the default list of scale factors.

Parameters
[in]context

The i-th element corresponds to level i. HEaaN uses fixed scale factor system, which fixes the scale factor with respect to each level. It helps managing scale factor properly, and saves some level.

◆ getEncryptionLevel()

HEAAN_API u64 HEaaN::getEncryptionLevel ( const Context context)

Get the level of a fresh ciphertext, which is the maximum level that users can encrypt a ciphertext to.

Parameters
[in]context

For somewhat homomorphic encryption parameters, it is equal to the maximum level of Q part. For some full homomorphic encryption parameters, however, some levels are reserved for bootstrapping and encrypting a ciphertext over this level is not allowed.

◆ getLogFullSlots()

HEAAN_API u64 HEaaN::getLogFullSlots ( const Context context)

Get the maximal logarithmic (base of 2) number of slots for the given context object.

Parameters
[in]context

The maximal number of slots is equal to N / 2 if N is the dimension of the context. The basic intention is to use this function with the constructor of the Message class, which takes the logarithmic number of slots in order to allocate sufficient memory.

◆ getPrimeList()

HEAAN_API std::vector<u64> HEaaN::getPrimeList ( const Context context)

Get the list of primes.

Parameters
[in]context

The i-th element corresponds to level i

◆ getRotIndicesForBootstrap()

HEAAN_API std::set<i64> HEaaN::getRotIndicesForBootstrap ( const Context context,
u64  log_slots 
)

Get the list of rotation key index for the bootstrapping process.

Parameters
[in]context
[in]log_slots

◆ getSecurityLevel()

HEAAN_API SecurityLevel HEaaN::getSecurityLevel ( const Context context)

Get the security level of the given context.

Parameters
[in]contextContext object

The security level is chosen according to the homomorphic encryption standard documentation, Table 1, distribution (-1,1) (ternary uniform with elements -1, 0 and 1) and CryptoLab's own experimental results.

Returns
The security level as described in HEaaN::SecurityLevel

◆ getSeed()

HEAAN_API SeedType HEaaN::getSeed ( )

Get the random seed of the current HEaaN instance.

Returns
The internal random seed

◆ getSparseParameterPresetFor()

HEAAN_API ParameterPreset HEaaN::getSparseParameterPresetFor ( ParameterPreset  preset)

Returns the parameter preset which is required to perform sparse secret encapsulation on bootstrapping for certain parameters.

The context of the sparse parameter should be constructed and provided to construct modules for the parameters. Sparse Secret Encapsulation is a technique to ease bootstrapping complexity while maintaing homomorphic capacity. For more details, please refer to the paper : Bootstrapping for Approximate Homomorphic Encryption with Negligible Failure-Probability by Using Sparse-Secret Encapsulation

◆ isBootstrappableParameter()

HEAAN_API bool HEaaN::isBootstrappableParameter ( const Context context)

Get whether the bootstrapping is supported.

Parameters
[in]context

◆ isExtendedBootstrapSupported()

HEAAN_API bool HEaaN::isExtendedBootstrapSupported ( const Context context)

Get whether the bootstrapping for extended range supported.

Parameters
[in]context

◆ isSparseSecretEncapsulationSupported()

HEAAN_API bool HEaaN::isSparseSecretEncapsulationSupported ( const Context context)

Get whether the given context supports sparse secret encapsulation or not.

Parameters
[in]context

Returns true for the context using a parameter with dense hamming weight on secret key, which can be key-switched to a corresponding parameter with a sparse secret key during bootstrapping.

◆ load() [1/3]

HEAAN_API void HEaaN::load ( EncryptionKey &  key,
std::istream &  stream 
)

◆ load() [2/3]

HEAAN_API void HEaaN::load ( EvaluationKey &  key,
std::istream &  stream 
)

Load key from a given stream.

◆ load() [3/3]

HEAAN_API void HEaaN::load ( SparseSecretEncapsulationKey &  key,
std::istream &  stream 
)

◆ makeContext() [1/2]

HEAAN_API Context HEaaN::makeContext ( const ParameterPreset preset,
const CudaDeviceIds cuda_device_ids = {} 
)

Make a context object based on a given parameter preset.

Parameters
[in]presetParameter preset
[in]cuda_device_idsOptional CUDA device IDs to be used. You can use only the specified cuda devices with this Context.
Returns
The context object generated from the predetermined parameters in the given ParameterPreset.
Exceptions
RuntimeExceptionif one calls this function with preset == ParameterPreset::CUSTOM. In order to make sense, one must use the other overloaded makeContext() function to specify custom parameters explicitly.

◆ makeContext() [2/2]

HEAAN_API Context HEaaN::makeContext ( const u64  log_dimension,
const u64  chain_length,
const u64  bpsize,
const u64  qpsize,
const u64  tpsize,
const u64  gadget_rank,
const CudaDeviceIds cuda_device_ids = {} 
)

Make a context based on custom parameters.

Parameters
[in]log_dimensionLogarithmic (with base 2) dimension of the ciphertexts and the keys. This means that in this homomorphic encryption context, the polynomials constituting the ciphertexts and the public/secret keys must be elements of the ring R[X] / (X^N + 1), where N is called the dimension of the polynomial (or of the ciphertexts). The value must be >= 10 and <= 20.
[in]chain_lengthThis is the number of primes in the RNS decomposition of each polynomial constituting the ciphertexts or the keys in the current homomorphic encryption context. There are the base prime (the prime at level 0) and the quantization primes at the higher levels, so chain_length is equal to the sum of the number of base primes (usually this number is 1) and the number of quantization primes. The value must be <= 50.
[in]bpsizeThe size of the base prime in bits. The value must be greater than or equal to qpsize, less than or equal to 61.
[in]qpsizeThe size of the quantization primes in bits. The value must be greater than or equal to 36, less than or equal to bpsize.
[in]tpsizeThe size of the temporary primes in bits. The value must be greater than qpsize + (bpsize - qpsize) / numTP, less than or equal to
  1. Note that numTP = chain_length / gadget_rank.
[in]gadget_rankThis is the number of decomposed polynomials when one does the "modup" process in the middle of keyswitching process. More precisely, in the modup process, the maximal ciphertext modulus Q which is also a product of word-sized primes, is divided into gadget_rank number of pieces and the modup process is to be applied to each of these pieces. This also means that the size of the evaluation keys is roughly gadget_rank times of the fresh ciphertexts. Using smaller or bigger number of gadget_rank has its advantages and disadvantages: using bigger number means that the polynomial is divided more finely, and this causes bigger total size for the evaluation keys, meanwhile smaller gadget_rank makes the size of the evaluation keys smaller. However, since the security level of the parameter is determined by the size of each modup polynomial, so in order to retain the same security level, using smaller gadget_rank causes smaller ciphertext modulus size, i.e., less multiplication depth is allowed. Microsoft SEAL uses the maximum gadget_rank, i.e. equal to chain_length, while HEaaN allows smaller gadget_rank in order to accelerate homomorphic operations and reduce switching key size.
[in]cuda_device_idsOptional CUDA device IDs to be used. You can use only the specified cuda devices with this Context.
Returns
The context object generated from the input parameters.

One must use this function to create a custom "somewhat" parameters, meaning ones with a fixed multiplication depth and without bootstrapping.

◆ makeContextFromFile()

HEAAN_API Context HEaaN::makeContextFromFile ( const std::string &  filename,
const CudaDeviceIds cuda_device_ids = {} 
)

Make a context object from a "context file".

Parameters
[in]filenameIt designates the path of the file to be read inside this function.
[in]cuda_device_idsOptional CUDA device IDs to be used. You can use only the specified cuda devices with this Context.
Returns
The generated context object.

A context file is one created by saveContextToFile.

Exceptions
RuntimeExceptionif it fails to open filename in read mode.

◆ save() [1/3]

HEAAN_API void HEaaN::save ( const EncryptionKey &  key,
std::ostream &  stream 
)

◆ save() [2/3]

HEAAN_API void HEaaN::save ( const EvaluationKey &  key,
std::ostream &  stream 
)

Save key to a given stream.

◆ save() [3/3]

HEAAN_API void HEaaN::save ( const SparseSecretEncapsulationKey &  key,
std::ostream &  stream 
)

◆ saveContextToFile()

HEAAN_API void HEaaN::saveContextToFile ( const Context context,
const std::string &  filename 
)

Save a context object into a file.

Parameters
[in]contextA context object to be saved.
[in]filenameFile path to be written.
Exceptions
RuntimeExceptionif it fails to open filename in write mode.

◆ setCurrentCudaDevice()

HEAAN_API void HEaaN::setCurrentCudaDevice ( int  device_id)

◆ setSeed()

HEAAN_API void HEaaN::setSeed ( const SeedType new_global_seed)

Set the random seed.

Parameters
[in]new_global_seedThe internal random seed is to be set with this parameter.

Variable Documentation

◆ Classical128

enum HEAAN_API HEaaN::Classical128 = 128

at least 128-bit security level classically.

◆ Classical192

enum HEAAN_API HEaaN::Classical192 = 192

at least 192-bit security level classically.

◆ Classical256

enum HEAAN_API HEaaN::Classical256 = 256

at least 256-bit security level classically.

◆ COMPLEX_IMAG_UNIT

constexpr Complex HEaaN::COMPLEX_IMAG_UNIT = Complex(REAL_ZERO, REAL_ONE)
constexpr

Complex number i.

◆ COMPLEX_ZERO

constexpr Complex HEaaN::COMPLEX_ZERO = Complex(REAL_ZERO, REAL_ZERO)
constexpr

Complex number 0.

◆ CUSTOM

enum HEAAN_API HEaaN::CUSTOM

◆ FGa

enum HEAAN_API HEaaN::FGa

◆ FGb

enum HEAAN_API HEaaN::FGb

◆ FGd

enum HEAAN_API HEaaN::FGd

◆ FTa

enum HEAAN_API HEaaN::FTa

◆ FTb

enum HEAAN_API HEaaN::FTb

◆ FVb

enum HEAAN_API HEaaN::FVb

◆ FVc

enum HEAAN_API HEaaN::FVc

◆ FX

enum HEAAN_API HEaaN::FX

◆ ParameterPreset

enum HEAAN_API HEaaN::ParameterPreset
strong

Class of Parameter presets.

The first alphabet denotes whether a parameter is full or somewhat homomorphic encryption. Somewhat homomorphic encryption parameters can use only a finite number of multiplications while full homomorphic encryption parameters can use infinitely many multiplications via bootstrapping. The second alphabet denotes the size of log2(N), where N denotes the dimension of the base ring. V(Venti), G(Grande), T(Tall), S(Short), D(Demi) represent log2(N) = 17, 16, 15, 14, 13, respectively. For somewhat parameters, a number that comes after these alphabets indicates total available multiplication number.

◆ Pointer< CiphertextImpl >

template class HEAAN_API HEaaN::Pointer< CiphertextImpl >

◆ Pointer< CollectiveKeyGenDataImpl >

template class HEAAN_API HEaaN::Pointer< CollectiveKeyGenDataImpl >

◆ Pointer< MessageImpl >

template class HEAAN_API HEaaN::Pointer< MessageImpl >

◆ Pointer< PlaintextImpl >

template class HEAAN_API HEaaN::Pointer< PlaintextImpl >

◆ Pointer< SecretKeyImpl >

template class HEAAN_API HEaaN::Pointer< SecretKeyImpl >

◆ REAL_ONE

constexpr Real HEaaN::REAL_ONE = 1.0
constexpr

Real number 1.

◆ REAL_PI

constexpr Real HEaaN::REAL_PI = 3.14159265358979323846
constexpr

Real number pi.

◆ REAL_ZERO

constexpr Real HEaaN::REAL_ZERO = 0.0
constexpr

Real number 0.

◆ SD3

enum HEAAN_API HEaaN::SD3

◆ SecurityLevel

enum HEAAN_API HEaaN::SecurityLevel
strong

Enum class for security levels.

This enum class represents the security level of the homomorphic encryption parameters. The prefix Classical in the enum value names denotes that the security level in question is measured assuming classical computers, not quantum ones. signifies that no security level assumptions are imposed, suitable for parameters for experimental purposes.

◆ SEED_SIZE_IN_BYTES

constexpr const u64 HEaaN::SEED_SIZE_IN_BYTES {32}
constexpr

◆ SGd0

enum HEAAN_API HEaaN::SGd0

◆ SS7

enum HEAAN_API HEaaN::SS7

◆ ST11

enum HEAAN_API HEaaN::ST11

◆ ST14

enum HEAAN_API HEaaN::ST14

◆ ST19

enum HEAAN_API HEaaN::ST19

◆ ST7

enum HEAAN_API HEaaN::ST7

◆ ST8

enum HEAAN_API HEaaN::ST8

◆ U64ONE

constexpr u64 HEaaN::U64ONE = UINT64_C(1)
constexpr

◆ U64ZERO

constexpr u64 HEaaN::U64ZERO = UINT64_C(0)
constexpr