Base Classes

Abstract base classes shared by all IPFE schemes.

class pyfe4ai.schemes.ipfe.ParameterCacheMixin[source]

Bases: object

Mixin that provides JSON-based parameter caching with validation.

Subclasses must set _scheme_type (a CryptoCONST string) and implement _param_verification(), _apply_parameters(), and _generate_and_save().

config_folder: str
class pyfe4ai.schemes.ipfe.IPFEAbsKeyGenerator(config, **kwargs)[source]

Bases: ABC

Abstract base for all inner-product FE key generators.

Subclasses implement setup() (generate keys), get_public_parameters(), get_private_keys(), and get_decryption_keys().

Parameters:

config (dict) – Scheme configuration dict. Expected keys vary by scheme; common keys include sec_param, eta, n, s, lst_nid.

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

abstractmethod setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

abstractmethod get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

None | dict

Returns:

A dict of public parameters, or None on error.

abstractmethod get_private_keys(nid, **kwargs)[source]

Return the private (encryption) keys for client nid.

Parameters:

nid (str) – A client/node identifier.

Return type:

None | dict

Returns:

A dict of private keys, or None if nid is invalid.

abstractmethod get_decryption_keys(sid, **kwargs)[source]

Derive a functional decryption key for session sid.

Parameters:
  • sid (str) – A session identifier.

  • **kwargs – Must include credentials with a fusion_weight entry.

Return type:

None | dict

Returns:

A dict containing the decryption key material.

Raises:
class pyfe4ai.schemes.ipfe.IPFEAbsCrypto(config, **kwargs)[source]

Bases: ABC

Abstract base for all inner-product FE crypto operations.

Subclasses implement encrypt_lst_ndarray(), compute_lst_ndarray_ct(), and decrypt_lst_ndarray_ct().

Parameters:

config (dict) – Runtime configuration dict containing at least keys (a dict with pp, sk, and/or dk sub-dicts) and optionally id, type, and precision.

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

abstractmethod encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Encrypt a list of ndarray-like plaintexts.

Parameters:

lst_ndarray (list) – List of plaintext arrays to encrypt.

Return type:

list | None

Returns:

List of ciphertext dicts, or None on error.

abstractmethod compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Aggregate ciphertexts from multiple clients.

Parameters:

dict_ndarray_ct (dict) – Mapping of client IDs to their ciphertext lists.

Return type:

list | None

Returns:

Aggregated ciphertext list, or None on error.

abstractmethod decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt aggregated ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Mapping of client IDs to their ciphertext lists.

Return type:

list | None

Returns:

List of decrypted inner-product results, or None on error.

DDH Base Classes

Base classes for DDH-family key generators.

Provides shared parameter caching logic (group generation, verification, serialisation) so that concrete SIFE / MIFE / MCFE DDH schemes only need to declare which configuration fields they use.

class pyfe4ai.schemes.ddh_base.DDHKeyGeneratorBase(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Base for standard DDH key generators sharing a (p, q, r, g) group.

Subclasses must set _scheme_type and _verify_keys, and may override _extra_param_fields to persist additional configuration.

Parameters:

config (dict)

class pyfe4ai.schemes.ddh_base.DamgardDDHKeyGeneratorBase(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Base for Damgard DDH key generators sharing a (p, q, g, h) group.

Subclasses must set _scheme_type and _verify_keys, implement _validate_bounds, and may override _extra_param_fields.

Parameters:

config (dict)

LWE Base Classes

Base classes for LWE-family key generators and crypto operations.

Provides shared parameter caching logic (LWE parameter derivation, matrix A sampling, serialisation) so that concrete SIFE / MIFE / MCFE LWE schemes only need to declare which configuration fields they use.

class pyfe4ai.schemes.lwe_base.LWEKeyGeneratorBase(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Base for LWE key generators sharing (p, q, m, sigma_q, l_sigma, A).

Subclasses must set _scheme_type and _verify_keys, and may override _extra_param_fields and _extra_verify to persist and verify additional configuration.

Parameters:

config (dict)

class pyfe4ai.schemes.lwe_base.LWECryptoBase(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Base for LWE crypto operations sharing encrypt/decrypt core logic.

Subclasses may override _pre_encrypt() to inject label masking.

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Initialise with scheme configuration.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

Paillier Base Classes

Base classes for Paillier-family key generators and crypto operations.

Provides shared Paillier group generation (p, q, n_mod, n_square, g), parameter caching, bound validation, and encrypt/decrypt core logic so that concrete SIFE / MIFE / MCFE Paillier schemes avoid code duplication.

class pyfe4ai.schemes.paillier_base.PaillierKeyGeneratorBase(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Base for Paillier key generators sharing (p, q, n_mod, n_square, g).

Subclasses must set _scheme_type and _verify_keys, and may override _extra_param_fields, _extra_verify, and _validate_bounds to persist/verify additional configuration.

Parameters:

config (dict)

class pyfe4ai.schemes.paillier_base.PaillierCryptoBase(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Base for Paillier crypto operations sharing encrypt/decrypt core logic.

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Initialise with scheme configuration.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

Ring-LWE Base Classes

Shared base classes for Ring-LWE-family inner-product FE schemes.

Extracts duplicated parameter handling and crypto initialisation that is identical across SIFE Ring-LWE, MIFE Ring-LWE and MCFE Ring-LWE.

class pyfe4ai.schemes.ring_lwe_base.RingLWEKeyGeneratorBase(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Common key-generator base for Ring-LWE schemes.

Subclasses MUST set:

  • _scheme_typeCryptoCONST.TYPE_*

  • _verify_keys – tuple of config attribute names checked by _param_verification (e.g. ("sec_param", "eta", "bound_x", "bound_y"))

Subclasses MAY override:

  • _extra_verify(param) – additional param-cache checks (default True)

  • _extra_param_fields() – extra fields for the param JSON (default {})

Parameters:

config (dict)

class pyfe4ai.schemes.ring_lwe_base.RingLWECryptoBase(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Common crypto base for Ring-LWE schemes.

Provides the shared __init__ that loads pp, A and sk.

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Initialise with scheme configuration.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

Threshold Utilities

Shared threshold secret-sharing utilities for threshold FE schemes.

Provides polynomial evaluation, Shamir secret sharing, Lagrange interpolation and modular centering used identically by both the LWE and Ring-LWE threshold variants.

pyfe4ai.schemes.threshold_utils.eval_poly(coeffs, x_value, modulus)[source]

Evaluate a polynomial at x_value modulo modulus.

Parameters:
  • coeffs (list[mpz]) – Polynomial coefficient list.

  • x_value (int) – Evaluation point.

  • modulus (mpz) – Modulus for the arithmetic operation.

Return type:

mpz

pyfe4ai.schemes.threshold_utils.share_secret(secret, threshold, share_points, modulus)[source]

Create Shamir secret shares of secret.

Parameters:
  • secret (mpz) – The secret to share.

  • threshold (int) – Minimum number of shares needed for reconstruction.

  • share_points (list[int]) – Evaluation points for the shares.

  • modulus (mpz) – Modulus for the arithmetic operation.

Return type:

dict[int, mpz]

pyfe4ai.schemes.threshold_utils.lagrange_at_zero(shares, modulus)[source]

Reconstruct the secret (polynomial value at 0) from shares.

Parameters:
  • shares (dict[int, mpz]) – List of (x, y) share pairs.

  • modulus (mpz) – Modulus for the arithmetic operation.

Return type:

mpz

pyfe4ai.schemes.threshold_utils.center_mod(value, modulus)[source]

Center value into the range (-modulus/2, modulus/2].

Parameters:
  • value (mpz) – Input value.

  • modulus (mpz) – Modulus for the arithmetic operation.

Return type:

mpz