Template Class Secretkey< Scheme::CKKS >

Class Documentation

template<>
class Secretkey<Scheme::CKKS>

Secretkey represents a secret key used for decrypting data and generating other keys in homomorphic encryption schemes.

The Secretkey class is initialized with encryption parameters and provides a method to access the underlying secret key data. This key is essential for decryption operations as well as for generating other keys like public keys, relinearization keys, and Galois keys.

Public Functions

Secretkey(HEContext<Scheme::CKKS> context)

Constructs a new Secretkey object with specified parameters.

Parameters:

context – Reference to the Parameters object that sets the encryption parameters.

Secretkey(HEContext<Scheme::CKKS> context, const int hamming_weight)

Constructs a new Secretkey object with specified parameters.

Parameters:
  • context – Reference to the Parameters object that sets the encryption parameters.

  • hamming_weight – Parameter defining hamming weight of secret key, try to use it as (ring size / 2) for maximum security.

Secretkey(const std::vector<int> &secret_key, HEContext<Scheme::CKKS> context, cudaStream_t stream = cudaStreamDefault)

Constructs a new Secretkey object with specified parameters.

Parameters:
  • secret_key – Vector where the device data will be copied to.

  • stream – The CUDA stream to be used for asynchronous operations. Defaults to cudaStreamDefault.

Secretkey(const HostVector<int> &secret_key, HEContext<Scheme::CKKS> context, cudaStream_t stream = cudaStreamDefault)

Constructs a new Secretkey object with specified parameters.

Parameters:
  • secret_key – Vector where the device data will be copied to.

  • stream – The CUDA stream to be used for asynchronous operations. Defaults to cudaStreamDefault.

Data64 *data()

Returns a pointer to the underlying secret key data.

Returns:

Data64* Pointer to the secret key data.

inline void switch_stream(cudaStream_t stream)

Switches the secretkey CUDA stream.

Parameters:

stream – The new CUDA stream to be used.

inline cudaStream_t stream() const

Retrieves the CUDA stream associated with the secretkey.

This function returns the CUDA stream that was used to create or last modify the secretkey.

Returns:

The CUDA stream associated with the secretkey.

inline int ring_size() const noexcept

Returns the size of the polynomial ring used in the homomorphic encryption scheme.

Returns:

int Size of the polynomial ring.

inline int coeff_modulus_count() const noexcept

Returns the number of coefficient modulus primes used in the encryption parameters.

Returns:

int Number of coefficient modulus primes.

void store_in_device(cudaStream_t stream = cudaStreamDefault)

Stores the ciphertext in the device (GPU) memory.

void store_in_host(cudaStream_t stream = cudaStreamDefault)

Stores the ciphertext in the host (CPU) memory.

inline bool is_on_device() const noexcept

Checks whether the data is stored on the device (GPU) memory.

inline Secretkey(const Secretkey &copy)

Copy constructor for creating a new Secretkey object by copying an existing one.

This constructor performs a deep copy of the secret key data, ensuring that the new object has its own independent copy of the data. GPU memory operations are handled using cudaMemcpyAsync for asynchronous data transfer.

Parameters:

copy – The source Secretkey object to copy from.

inline Secretkey(Secretkey &&assign) noexcept

Move constructor for transferring ownership of a Secretkey object.

Transfers all resources, including GPU memory, from the source object to the newly constructed object. The source object is left in a valid but undefined state.

Parameters:

assign – The source Secretkey object to move from.

inline Secretkey &operator=(const Secretkey &copy)

Copy assignment operator for assigning one Secretkey object to another.

Performs a deep copy of the secret key data, ensuring that the target object has its own independent copy. GPU memory is copied using cudaMemcpyAsync.

Parameters:

copy – The source Secretkey object to copy from.

Returns:

Reference to the assigned object.

inline Secretkey &operator=(Secretkey &&assign) noexcept

Move assignment operator for transferring ownership of a Secretkey object.

Transfers all resources, including GPU memory, from the source object to the target object. The source object is left in a valid but undefined state.

Parameters:

assign – The source Secretkey object to move from.

Returns:

Reference to the assigned object.

Secretkey() = default

Default constructor for Secretkey.

Initializes an empty Secretkey object. All members will have their default values.

void save(std::ostream &os) const
void load(std::istream &is)
inline void set_context(HEContext<Scheme::CKKS> context)