Compute on encrypted data. Reveal only the result.
A research-oriented Python library of functional encryption (FE) schemes for AI security and privacy โ from single-input inner products to multi-client, threshold, decentralized, and quadratic constructions.
One consistent Python API โ setup / keygen / encrypt / decrypt โ
across the functional-encryption zoo, built for ML workloads.
SIFE, MIFE, MCFE, decentralized MCFE, threshold MIFE/MCFE, function-hiding IPE / Multi-IPE, and quadratic FE (SGP & Quad) โ 39 (family, variant) combinations under one roof.
DDH, Damgรฅrd-DDH, Paillier/DCR, LWE & Ring-LWE (post-quantum lines), and pairing-based constructions โ pick the assumption that fits your deployment.
ml_adapter wraps any scheme for federated-learning gradient
aggregation and encrypted linear inference; a quantization toolkit handles
float โ integer precision.
NTT polynomial multiplication for Ring-LWE, O(โn) baby-step giant-step discrete log with caching, CSPRNG batch sampling, and ndarray batch helpers throughout.
150+ core tests in CI, typed public API (py.typed), TypedDict
config schemas, and a structured FEError exception
hierarchy.
Every scheme cites its source construction (PKC'15, CRYPTO'16/'18, ASIACRYPT'18, PKC'19, IEEE TDSC TAPFed, โฆ) in the module docstring โ built for reproducible research.
Encrypt a vector, hand out a functional key, learn only the inner product.
# install git clone https://github.com/spire-studio/pyfe4ai.git cd pyfe4ai conda env create -f environment.yml conda activate pyfe4ai pip install -e ".[test]" # run the test suite python -m pytest -m core -q
from pyfe4ai import SIFE, SIFEKeyGenerator x, y = [2, 1, 3], [4, 5, 6] kg = SIFEKeyGenerator({"sec_param": 128, "eta": 3}) kg.setup() pp, sk = kg.get_public_parameters(), kg.get_private_keys() dk = kg.get_decryption_keys("sid_0", credentials={"fusion_weight": y}) ct = SIFE({"precision": 3, "keys": {"pp": pp, "sk": sk}}).encrypt(x) result = SIFE({"precision": 3, "keys": {"pp": pp}}).decrypt(ct, dk, y) print(result) # โจx, yโฉ = 31 โ and nothing else is revealed
Families ร backends at a glance โ see the documentation for per-scheme papers and parameters.
| Family | DDH | Damgรฅrd | Paillier | LWE | Ring-LWE | Pairing (FH) |
|---|---|---|---|---|---|---|
| SIFE single-input | โ | โ | โ | โ | โ | โ |
| MIFE multi-input | โ | โ | โ | โ | โ | โ |
| MCFE multi-client, labeled | โ | โ | โ | โ | โ | โ |
| dMCFE decentralized | โ | โ | โ | โ | โ | โ |
| tMIFE threshold | โ | โ | โ | โ | โ | โ |
| tMCFE threshold | โ | โ | โ | โ | โ | โ |
| Quadratic SGP ยท Quad | โ | โ | โ | โ | โ | โ |
Functional encryption reveals a chosen function of the data โ not the data itself.
Clients encrypt local gradients with MCFE; the aggregator decrypts only the weighted sum โ individual updates stay private. Threshold variants (TAPFed-style) tolerate partial participation and curb single-aggregator power.
Run linear scoring or bilinear-form classification (quadratic FE) directly over ciphertexts โ the model owner learns the prediction, never the raw features.
A technical report is in preparationcoming soon
@software{pyfe4ai2026,
author = {{Spire Studio}},
title = {{PyFE4AI}: Python-based Functional Encryption
for {AI} Security and Privacy},
year = {2026},
version = {0.1.0},
license = {Apache-2.0},
url = {https://github.com/spire-studio/pyfe4ai}
}