Quadratic FE

Quadratic functional encryption schemes.

class pyfe4ai.schemes.quadratic.QuadraticQuad(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Crypto operations for public-key quadratic FE (Quad construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

encrypt(payload)[source]
Parameters:

payload (dict)

Return type:

dict

decrypt(ct, dk)[source]

Decrypt ciphertexts and recover the inner product.

Parameters:
  • ct (dict) – Ciphertext dict.

  • dk (dict) – Functional decryption key.

Return type:

int

encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Perform the encrypt_lst_ndarray operation.

Parameters:

lst_ndarray (list) – List of numpy arrays to encrypt element-wise.

Return type:

list | None

compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Compute inner products on encrypted ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt encrypted ndarray ciphertexts element-wise.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

class pyfe4ai.schemes.quadratic.QuadraticQuadKeyGenerator(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Key generator for public-key quadratic FE (Quad construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

dict | None

Returns:

A dict of public parameters, or None on error.

get_private_keys(nid='nid_default', **kwargs)[source]

Perform the get_private_keys operation.

Parameters:

nid (str, default: 'nid_default') – Node identifier.

Return type:

dict | None

get_decryption_keys(sid, **kwargs)[source]

Perform the get_decryption_keys operation.

Parameters:

sid (str) – Session / decryption-key identifier.

Return type:

dict | None

class pyfe4ai.schemes.quadratic.QuadraticSGP(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Crypto operations for secret-key quadratic FE (SGP construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

encrypt(payload)[source]
Parameters:

payload (dict)

Return type:

dict

decrypt(ct, dk)[source]

Decrypt ciphertexts and recover the inner product.

Parameters:
  • ct (dict) – Ciphertext dict.

  • dk (dict) – Functional decryption key.

Return type:

int

encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Perform the encrypt_lst_ndarray operation.

Parameters:

lst_ndarray (list) – List of numpy arrays to encrypt element-wise.

Return type:

list | None

compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Compute inner products on encrypted ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt encrypted ndarray ciphertexts element-wise.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

class pyfe4ai.schemes.quadratic.QuadraticSGPKeyGenerator(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Key generator for secret-key quadratic FE (SGP construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

dict | None

Returns:

A dict of public parameters, or None on error.

get_private_keys(nid='nid_default', **kwargs)[source]

Perform the get_private_keys operation.

Parameters:

nid (str, default: 'nid_default') – Node identifier.

Return type:

dict | None

get_decryption_keys(sid, **kwargs)[source]

Perform the get_decryption_keys operation.

Parameters:

sid (str) – Session / decryption-key identifier.

Return type:

dict | None

class pyfe4ai.schemes.quadratic.MultiInputQuadraticSGP(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Multi-input secret-key quadratic FE.

Each client independently encrypts (x_i, y_i). The decryptor combines ciphertexts from all clients and recovers sum_i x_i^T F_i y_i.

Parameters:

config (dict)

scheme_type = 'MI_QUADRATIC_SGP'
__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

encrypt(payload)[source]

Encrypt a single client’s (x, y) pair.

payload: dict with keys x and y (list[int] of length d).

Parameters:

payload (dict)

Return type:

dict

decrypt(dct_ct, dk)[source]

Decrypt aggregated quadratic form from multiple clients.

Parameters:
  • dct_ct (dict) – Ciphertext dict (or dict of per-client ciphertexts).

  • dk (dict) – Functional decryption key.

Return type:

int

encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Perform the encrypt_lst_ndarray operation.

Parameters:

lst_ndarray (list) – List of numpy arrays to encrypt element-wise.

Return type:

list | None

compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Compute inner products on encrypted ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt encrypted ndarray ciphertexts element-wise.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

class pyfe4ai.schemes.quadratic.MultiInputQuadraticSGPKeyGenerator(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Key generator for multi-input secret-key quadratic FE (MI-SGP).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

dict | None

Returns:

A dict of public parameters, or None on error.

get_private_keys(nid=None, **kwargs)[source]

Perform the get_private_keys operation.

Parameters:

nid (str, default: None) – Node identifier.

Return type:

dict | None

get_decryption_keys(sid, **kwargs)[source]

Generate functional decryption key for per-client function matrices.

Parameters:

sid (str) – Session / decryption-key identifier.

Return type:

dict | None

SGP (Single-Input)

Secret-Key Quadratic Functional Encryption (SGP) | Based on | “Reading in the Dark: Classifying Encrypted Digits with Functional Encryption” | By Dufour Sans, Gay, Pointcheval | See ePrint 2018/206 | | This prototype follows the GoFE quadratic/sgp.go structure and adapts it | to the repository’s key-generator / crypto split.

  • type: secret-key encryption

  • setting: Pairing based

  • note: research prototype aligned with the existing crypto-ipfe API

class pyfe4ai.schemes.quadratic.sgp.QuadraticSGPKeyGenerator(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Key generator for secret-key quadratic FE (SGP construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

dict | None

Returns:

A dict of public parameters, or None on error.

get_private_keys(nid='nid_default', **kwargs)[source]

Perform the get_private_keys operation.

Parameters:

nid (str, default: 'nid_default') – Node identifier.

Return type:

dict | None

get_decryption_keys(sid, **kwargs)[source]

Perform the get_decryption_keys operation.

Parameters:

sid (str) – Session / decryption-key identifier.

Return type:

dict | None

class pyfe4ai.schemes.quadratic.sgp.QuadraticSGP(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Crypto operations for secret-key quadratic FE (SGP construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

encrypt(payload)[source]
Parameters:

payload (dict)

Return type:

dict

decrypt(ct, dk)[source]

Decrypt ciphertexts and recover the inner product.

Parameters:
  • ct (dict) – Ciphertext dict.

  • dk (dict) – Functional decryption key.

Return type:

int

encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Perform the encrypt_lst_ndarray operation.

Parameters:

lst_ndarray (list) – List of numpy arrays to encrypt element-wise.

Return type:

list | None

compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Compute inner products on encrypted ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt encrypted ndarray ciphertexts element-wise.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

Multi-Input SGP

Multi-Input Secret-Key Quadratic Functional Encryption (MI-SGP) | Based on the single-input SGP construction from | “Reading in the Dark: Classifying Encrypted Digits with Functional Encryption” | By Dufour Sans, Gay, Pointcheval (ePrint 2018/206) | | Extended to multi-input: each client i independently encrypts its own | pair (x_i, y_i), and decryption recovers the aggregated quadratic form | sum_i x_i^T F_i y_i where F_i is the per-client function matrix. | | The multi-input composition follows the per-client secret key approach: | each client holds independent (s_i, t_i) secrets and encrypts using | independent randomness (gamma_i, W_i). Decryption combines pairing | results across all clients.

  • type: secret-key encryption

  • setting: Pairing based

  • note: research prototype aligned with the existing crypto-ipfe API

class pyfe4ai.schemes.quadratic.multi_input_sgp.MultiInputQuadraticSGPKeyGenerator(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Key generator for multi-input secret-key quadratic FE (MI-SGP).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

dict | None

Returns:

A dict of public parameters, or None on error.

get_private_keys(nid=None, **kwargs)[source]

Perform the get_private_keys operation.

Parameters:

nid (str, default: None) – Node identifier.

Return type:

dict | None

get_decryption_keys(sid, **kwargs)[source]

Generate functional decryption key for per-client function matrices.

Parameters:

sid (str) – Session / decryption-key identifier.

Return type:

dict | None

class pyfe4ai.schemes.quadratic.multi_input_sgp.MultiInputQuadraticSGP(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Multi-input secret-key quadratic FE.

Each client independently encrypts (x_i, y_i). The decryptor combines ciphertexts from all clients and recovers sum_i x_i^T F_i y_i.

Parameters:

config (dict)

scheme_type = 'MI_QUADRATIC_SGP'
__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

encrypt(payload)[source]

Encrypt a single client’s (x, y) pair.

payload: dict with keys x and y (list[int] of length d).

Parameters:

payload (dict)

Return type:

dict

decrypt(dct_ct, dk)[source]

Decrypt aggregated quadratic form from multiple clients.

Parameters:
  • dct_ct (dict) – Ciphertext dict (or dict of per-client ciphertexts).

  • dk (dict) – Functional decryption key.

Return type:

int

encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Perform the encrypt_lst_ndarray operation.

Parameters:

lst_ndarray (list) – List of numpy arrays to encrypt element-wise.

Return type:

list | None

compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Compute inner products on encrypted ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt encrypted ndarray ciphertexts element-wise.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

Quad

Public-Key Quadratic Functional Encryption (Quad) | Based on | “A New Paradigm for Public-Key Functional Encryption for Degree-2 Polynomials” | By Romain Gay | | This repository prototype realizes quadratic FE through tensor encoding over | the repository’s partially function-hiding IPE building block. The overall | organization is aligned with GoFE’s quadratic/quad.go, while the Python | implementation favors a simpler composition over a line-by-line port.

  • type: public-key encryption

  • setting: Pairing based

  • note: research prototype aligned with the existing crypto-ipfe API

class pyfe4ai.schemes.quadratic.quad.QuadraticQuadKeyGenerator(config, **kwargs)[source]

Bases: IPFEAbsKeyGenerator, ParameterCacheMixin

Key generator for public-key quadratic FE (Quad construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

setup()[source]

Generate master public and secret keys for the scheme.

Return type:

None

get_public_parameters(**kwargs)[source]

Return serialisable public parameters.

Return type:

dict | None

Returns:

A dict of public parameters, or None on error.

get_private_keys(nid='nid_default', **kwargs)[source]

Perform the get_private_keys operation.

Parameters:

nid (str, default: 'nid_default') – Node identifier.

Return type:

dict | None

get_decryption_keys(sid, **kwargs)[source]

Perform the get_decryption_keys operation.

Parameters:

sid (str) – Session / decryption-key identifier.

Return type:

dict | None

class pyfe4ai.schemes.quadratic.quad.QuadraticQuad(config, **kwargs)[source]

Bases: IPFEAbsCrypto

Crypto operations for public-key quadratic FE (Quad construction).

Parameters:

config (dict)

__init__(config, **kwargs)[source]

Perform the __init__ operation.

Parameters:

config (dict) – Scheme configuration dict.

Return type:

None

encrypt(payload)[source]
Parameters:

payload (dict)

Return type:

dict

decrypt(ct, dk)[source]

Decrypt ciphertexts and recover the inner product.

Parameters:
  • ct (dict) – Ciphertext dict.

  • dk (dict) – Functional decryption key.

Return type:

int

encrypt_lst_ndarray(lst_ndarray, **kwargs)[source]

Perform the encrypt_lst_ndarray operation.

Parameters:

lst_ndarray (list) – List of numpy arrays to encrypt element-wise.

Return type:

list | None

compute_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Compute inner products on encrypted ndarray ciphertexts.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None

decrypt_lst_ndarray_ct(dict_ndarray_ct, **kwargs)[source]

Decrypt encrypted ndarray ciphertexts element-wise.

Parameters:

dict_ndarray_ct (dict) – Encrypted ndarray ciphertexts (list or dict).

Return type:

list | None