fhelium/ckks_keys.h
#include <fhelium/ckks_keys.h> · namespace fhelium::ckks
CKKS key generation: secret, public, key-switching, relinearization, and Galois keys, and the conversion of a secret key to another RNS basis.
Every key is returned in the NTT domain with Montgomery residues over the rows of RingTables::forward.parameters and the forward and inverse NTT schedules of RingTables (fhelium/operation_tables.h). A secret key has shape [limb, N], a public key [2, limb, N], and a key-switching key (KeySwitchKey) [key_digit, 2, key_row, N]. Random functions read the stream seed of fhelium/random.h at its current nonce cdt_table.
SeedSpec
struct View source
Generator of the uniform component
Digit [w_0, w_1, w_2, w_3, id, d] (int64): the 256-bit ChaCha key as four little-endian 64-bit words, a 64-bit key identifier and the stored digit index; KeySwitchKey::seed_rows stacks them as [key_digit, 6]. Stored row fhelium::random::expand_seeded_key of that row with prime moduli[r] and ChaCharounds: Lemire rejection sampling of ChaCha output at block counter
| Member | Description |
|---|---|
std::string prf = "chacha" | Stream cipher name; chacha is the supported generator. |
int64_t rounds = 12 | ChaCha round count; 12 is the supported count. |
std::vector<int64_t> moduli | Prime of every stored key row, in key-row order. |
KeySwitchKey
struct View source
Hybrid key-switching key.
data is [key_digit, 2, key_row, N] (expanded) or [key_digit, 1, key_row, N] (compact, seed_rows and spec; an expanded and a compact form of one key give bitwise equal key-switch results. Key products read seed_rows.
| Member | Description |
|---|---|
bool expanded() const | Whether data holds |
KeySwitchKeyLayout
struct View source
Rows of a hybrid key-switching key.
| Member | Description |
|---|---|
std::string ntt_backend | NTT policy name (fhelium/ntt_operations.h). |
std::vector<int64_t> q_rows | Active Q rows in key-row order; consecutive digits cover consecutive entries. |
std::vector<int64_t> digit_sizes | Row counts of the consecutive digits (key_digit_sizes). |
std::vector<int64_t> p_rows | Auxiliary rows of the key, in key-row order. |
| Function | Devices | Summary |
|---|---|---|
expand_key_switch_key | Any device | Returns key with seed_rows and holds both components in new storage. An expanded key is returned as is. |
compact_key_switch_key | Any device | Returns key holding seed_rows is shared, so the memory of seed_rows; a compact key is returned as is. |
create_secret_key | Any device | Samples a ternary secret ring_dimension. |
prepare_secret_key | Any device | Returns the secret key of the integer coefficients [N] (int32 or int64). |
create_public_key | Any device | Returns the public key secret_key that match parameters. |
create_key_switch_key | Any device | Returns the hybrid key that switches source_secret_key to destination_secret_key. |
create_relinearization_key | Any device | Returns the key that switches create_key_switch_key). |
create_galois_key | Any device | Returns the key that switches galois_element (create_key_switch_key). Rotation keys use rotation_galois_element; the conjugation key uses |
convert_secret_key | Any device | Re-expresses secret_key in another RNS basis. |
expand_key_switch_key
function View source
KeySwitchKey fhelium::ckks::expand_key_switch_key(
const KeySwitchKey& key);2
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.expand_key_switch_key
fhelium_ckks_ops::expand_key_switch_key(Tensor data, Tensor seed_rows, int[] moduli, str prf, int rounds) -> TensorReturns key with seed_rows and holds both components in new storage. An expanded key is returned as is.
compact_key_switch_key
function View source
KeySwitchKey fhelium::ckks::compact_key_switch_key(
const KeySwitchKey& key);2
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.compact_key_switch_key
fhelium_ckks_ops::compact_key_switch_key(Tensor data, Tensor seed_rows, int[] moduli, str prf, int rounds) -> TensorReturns key holding seed_rows is shared, so the memory of seed_rows; a compact key is returned as is.
create_secret_key
function View source
at::Tensor fhelium::ckks::create_secret_key(
int64_t ring_dimension,
const RingTables& tables,
const at::Tensor& seed,
std::string_view ntt_backend,
std::optional<int64_t> hamming_weight);2
3
4
5
6
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.create_secret_key
fhelium_ckks_ops::create_secret_key(int ring_dimension, Tensor?[] tables, Tensor seed, str ntt_backend, int? hamming_weight) -> TensorSamples a ternary secret ring_dimension.
Without hamming_weight, every coefficient is
prepare_secret_key
function View source
at::Tensor fhelium::ckks::prepare_secret_key(
const at::Tensor& coefficients,
const RingTables& tables,
std::string_view ntt_backend);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.prepare_secret_key
fhelium_ckks_ops::prepare_secret_key(Tensor coefficients, Tensor?[] tables, str ntt_backend) -> TensorReturns the secret key of the integer coefficients [N] (int32 or int64).
create_public_key
function View source
at::Tensor fhelium::ckks::create_public_key(
const at::Tensor& secret_key,
const RingTables& tables,
const at::Tensor& seed,
const at::Tensor& cdt_table,
std::string_view ntt_backend,
const std::optional<at::Tensor>& uniform,
const std::optional<at::Tensor>& error_coefficients);2
3
4
5
6
7
8
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.create_public_key
fhelium_ckks_ops::create_public_key(Tensor secret_key, Tensor?[] tables, Tensor seed, Tensor cdt_table, str ntt_backend, Tensor? uniform, Tensor? error_coefficients) -> TensorReturns the public key secret_key that match parameters.
The error error_coefficients [N] or a discrete-Gaussian sample, and uniform (NTT Montgomery [limb, N]) or a uniform sample. Sampled components use one nonce each, in the order
create_key_switch_key
function View source
KeySwitchKey fhelium::ckks::create_key_switch_key(
const at::Tensor& source_secret_key,
const at::Tensor& destination_secret_key,
const RingTables& tables,
const at::Tensor& seed,
const at::Tensor& cdt_table,
const KeySwitchKeyLayout& layout,
const std::optional<at::Tensor>& uniform_by_digit,
const std::optional<at::Tensor>& error_by_digit);2
3
4
5
6
7
8
9
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.create_key_switch_key
fhelium_ckks_ops::create_key_switch_key(Tensor source_secret_key, Tensor destination_secret_key, Tensor?[] tables, ) -> (Tensor, Tensor?, int[], int)Returns the hybrid key that switches source_secret_key to destination_secret_key.
Both secrets cover the rows of parameters. Table source_product holds layout.p_rows.
Without uniform_by_digit, the key is seeded: its seed rows (SeedSpec) take the first ten words of the stream block at the current nonce, and uniform_by_digit [key_digit, limb, N] supplies parameters instead, for a uniform component shared with other parties, and gives a key without seed rows. error_by_digit [key_digit, N] replaces the error samples. Uses one nonce for the seed rows and one per sampled error.
create_relinearization_key
function View source
KeySwitchKey fhelium::ckks::create_relinearization_key(
const at::Tensor& secret_key,
const RingTables& tables,
const at::Tensor& seed,
const at::Tensor& cdt_table,
const KeySwitchKeyLayout& layout,
const std::optional<at::Tensor>& uniform_by_digit,
const std::optional<at::Tensor>& error_by_digit);2
3
4
5
6
7
8
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.create_relinearization_key
fhelium_ckks_ops::create_relinearization_key(Tensor secret_key, Tensor?[] tables, ) -> (Tensor, Tensor?, int[], int)Returns the key that switches create_key_switch_key).
create_galois_key
function View source
KeySwitchKey fhelium::ckks::create_galois_key(
const at::Tensor& secret_key,
int64_t galois_element,
const RingTables& tables,
const at::Tensor& seed,
const at::Tensor& cdt_table,
const KeySwitchKeyLayout& layout,
const std::optional<at::Tensor>& uniform_by_digit,
const std::optional<at::Tensor>& error_by_digit);2
3
4
5
6
7
8
9
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.create_galois_key
fhelium_ckks_ops::create_galois_key(Tensor secret_key, int galois_element, Tensor?[] tables, ) -> (Tensor, Tensor?, int[], int)Returns the key that switches galois_element (create_key_switch_key). Rotation keys use rotation_galois_element; the conjugation key uses
convert_secret_key
function View source
at::Tensor fhelium::ckks::convert_secret_key(
const at::Tensor& secret_key,
const SecretConversionTables& tables,
std::string_view ntt_backend);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.convert_secret_key
fhelium_ckks_ops::convert_secret_key(Tensor secret_key, Tensor?[] tables, str ntt_backend) -> TensorRe-expresses secret_key in another RNS basis.
The source_inverse NTT schedule returns the secret to coefficients, whose centered representative modulo the source product is extended to the target rows with the extension tables of fhelium::rns::centered_basis_extend, and the target_forward NTT schedule transforms the result. The extension tables fix the working dtype; the result takes the dtype of the target schedule.