fhelium.backend.ckks.crypto
CKKS key material and registered encryption/decryption implementations.
RANDOM_STREAM_RESOURCE_KIND
constant View source
RANDOM_STREAM_RESOURCE_KIND = 'ckks-random-stream'RANDOM_STREAM_RESOURCE_SYMBOL
constant View source
RANDOM_STREAM_RESOURCE_SYMBOL = 'ckks-random-stream'NativeDecryptImplementation
class View source
NativeDecryptImplementation(name: str = 'native-ckks-decrypt', supports_in_place: bool = False, operation_types: tuple[type[Operation], ...] = (ckks.DecryptOp,))Execute decryption with Tensor key, transform, and reconstruction operands.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'native-ckks-decrypt' |
supports_in_place | bool | False |
operation_types | tuple[type[Operation], ...] | (ckks.DecryptOp,) |
resource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...execute
method
def execute(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], *, in_place: bool) -> tuple[torch.Tensor, ...]: ...DecryptReconstructionTables
class View source
DecryptReconstructionTables(source_prime_ids_by_depth: tuple[tuple[int, ...], ...], normalizers_by_depth: tuple[torch.Tensor, ...], propagation_by_depth: tuple[torch.Tensor, ...], device: torch.device, half_digits_by_depth: tuple[torch.Tensor, ...])Hold device tables for centered reconstruction of the complete active Q basis.
Attributes
| Name | Type | Default/value |
|---|---|---|
source_prime_ids_by_depth | tuple[tuple[int, ...], ...] | |
normalizers_by_depth | tuple[torch.Tensor, ...] | |
propagation_by_depth | tuple[torch.Tensor, ...] | |
device | torch.device | |
half_digits_by_depth | tuple[torch.Tensor, ...] |
tensor_operands
method
def tensor_operands(context: RnsContext, depth: int) -> tuple[torch.Tensor, ...]: ...Return the Q parameters and mixed-radix reconstruction tables.
create
method
def create(context: RnsContext) -> DecryptReconstructionTables: ...Build reconstruction tables for one context-local RNS context.
NativeEncryptImplementation
class View source
NativeEncryptImplementation(name: str = 'native-ckks-encrypt', supports_in_place: bool = False, operation_types: tuple[type[Operation], ...] = (ckks.EncryptOp,))Execute encryption with data operands and a bound random stream.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'native-ckks-encrypt' |
supports_in_place | bool | False |
operation_types | tuple[type[Operation], ...] | (ckks.EncryptOp,) |
resource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...execute
method
def execute(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], *, in_place: bool) -> tuple[torch.Tensor, ...]: ...CkksKeyGenerator
class View source
CkksKeyGenerator()Construct dense CKKS keys from caller-supplied device resources.
Key payloads use configured integral dtype and prime-row order. Secret-key data is [limb, ntt_index]; public keys are [key_component, limb, ntt_index]; key-switch keys are [key_digit, key_component, limb, ntt_index]. Returned keys are always NTT/Montgomery/lazy at depth zero in the stated Q or QP basis and own their payload storage. Local digit_index is resolved to stable key_digit_index before key tensor indexing.
create_secret_key
method
def create_secret_key(resources: KeyGenerationResource, *, modulus_basis: ModulusBasis='QP') -> SecretKey: ...Sample ternary
Output shape is [limb, ntt_index] with Q or QP prime_ids selected by modulus_basis. Sampling and all temporary transitions are functional from the caller's perspective.
create_public_key
method
def create_public_key(resources: KeyGenerationResource, secret_key: SecretKey, *, modulus_basis: ModulusBasis='Q', uniform_component: torch.Tensor | None=None, error_coefficients: torch.Tensor | None=None) -> PublicKey: ...Generate (k_0,k_1) satisfying
Output is integral [key_component=2, limb, ntt_index] in depth-zero NTT/Montgomery form with Q or QP rows. secret_key and optional sampled uniform/error coefficients are read-only and never alias the returned stacked tensor. When error coefficients are omitted, the generator samples its configured discrete Gaussian.
create_key_switch_key
method
def create_key_switch_key(resources: KeyGenerationResource, source_secret_key: SecretKey, destination_secret_key: SecretKey, *, uniform_component_by_key_digit: torch.Tensor | None=None, error_coefficients_by_key_digit: torch.Tensor | None=None) -> KeySwitchKey: ...Create a hybrid-RNS key from source to destination secret relation.
Each hybrid digit is constructed through a public-key encryption.
Stable key digit [key_digit, key_component=2, QP_limb, ntt_index] in NTT/Montgomery lazy form and depth-zero QP order. Input keys and optional sampled uniform/error coefficients are not mutated or aliased.
create_relinearization_key
method
def create_relinearization_key(resources: KeyGenerationResource, secret_key: SecretKey) -> RelinearizationKey: ...Return QP key material that switches the
The returned state and layout equal create_key_switch_key; the input secret key remains NTT/Montgomery QP and is not mutated.
create_rotation_key
method
def create_rotation_key(resources: KeyGenerationResource, rotation_step: int, *, uniform_component_by_key_digit: torch.Tensor | None=None, secret_key: SecretKey) -> RotationKey: ...Construct QP key material from
rotation_step follows signed slot displacement and is stored as metadata. The distinct galois_element
create_conjugation_key
method
def create_conjugation_key(resources: KeyGenerationResource, secret_key: SecretKey) -> ConjugationKey: ...Construct QP key material from
Output uses key-switch-key axes and NTT/Montgomery QP state; the input secret key remains unchanged.
KeyGenerationResource
class View source
KeyGenerationResource(config: CkksConfig, rng: Csprng, rns_context: RnsContext, ntt_context: NttContext, p_product_montgomery_q: torch.Tensor)Bind context, arithmetic, and random resources for one key device.
Attributes
| Name | Type | Default/value |
|---|---|---|
config | CkksConfig | |
rng | Csprng | |
rns_context | RnsContext | |
ntt_context | NttContext | |
p_product_montgomery_q | torch.Tensor |
create
method
def create(*, config: CkksConfig, rng: Csprng, rns_context: RnsContext, ntt_context: NttContext) -> KeyGenerationResource: ...Build key-generation scalars on one concrete context device.
device
property
device: torch.deviceReturn the concrete device shared by all key-generation resources.
decrypt_tensor
function View source
def decrypt_tensor(ciphertext: torch.Tensor, secret_key: torch.Tensor, tensors: dict[str, torch.Tensor], attributes: dict[str, object]) -> torch.Tensor: ...Decrypt Tensor payloads and reconstruct their centered Q coefficients.
encrypt_tensor
function View source
def encrypt_tensor(coefficients: torch.Tensor, public_key: torch.Tensor, tensors: dict[str, torch.Tensor], attributes: dict[str, object], rng: Csprng) -> torch.Tensor: ...Sample encryption randomness and evaluate the two ciphertext components.
reconstruct_q_coefficients_tensor
function View source
def reconstruct_q_coefficients_tensor(plaintext_rns: torch.Tensor, source_params: torch.Tensor, normalizers: torch.Tensor, propagation: torch.Tensor, half_digits: torch.Tensor) -> torch.Tensor: ...Reconstruct the centered class modulo the complete supplied Q product.