PyFE4AI โ€” Python Functional Encryption for Trustworthy AI

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.

39scheme variants
8FE families
5crypto backends
Apache-2.0license

Why PyFE4AI

One consistent Python API โ€” setup / keygen / encrypt / decrypt โ€” across the functional-encryption zoo, built for ML workloads.

๐Ÿงฉ

Complete FE family coverage

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.

๐Ÿ”

Five cryptographic backends

DDH, Damgรฅrd-DDH, Paillier/DCR, LWE & Ring-LWE (post-quantum lines), and pairing-based constructions โ€” pick the assumption that fits your deployment.

๐Ÿค–

ML-native adapter

ml_adapter wraps any scheme for federated-learning gradient aggregation and encrypted linear inference; a quantization toolkit handles float โ†” integer precision.

โšก

Engineered for speed

NTT polynomial multiplication for Ring-LWE, O(โˆšn) baby-step giant-step discrete log with caching, CSPRNG batch sampling, and ndarray batch helpers throughout.

๐Ÿงช

Tested & typed

150+ core tests in CI, typed public API (py.typed), TypedDict config schemas, and a structured FEError exception hierarchy.

๐Ÿ“š

Paper-faithful

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.

Quickstart

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

Scheme Matrix

Families ร— backends at a glance โ€” see the documentation for per-scheme papers and parameters.

Family DDHDamgรฅrdPaillier LWERing-LWEPairing (FH)
SIFE single-input โœ“โœ“โœ“โœ“โœ“โœ“
MIFE multi-input โœ“โœ“โœ“โœ“โœ“โœ“
MCFE multi-client, labeled โœ“โœ“โœ“โœ“โœ“โœ“
dMCFE decentralized โœ“โ€”โœ“โœ“โœ“โœ“
tMIFE threshold โœ“โ€”โ€”โœ“โ€”โ€”
tMCFE threshold โœ“โ€”โ€”โœ“โœ“โœ“
Quadratic SGP ยท Quad โ€”โ€”โ€”โ€”โ€”โœ“

Built for Privacy-Preserving ML

Functional encryption reveals a chosen function of the data โ€” not the data itself.

๐ŸŒ Federated-learning secure aggregation

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.

examples/ml_fl_aggregation.py โ†’

๐Ÿ”Ž Encrypted inference

Run linear scoring or bilinear-form classification (quadratic FE) directly over ciphertexts โ€” the model owner learns the prediction, never the raw features.

examples/ml_encrypted_inference.py โ†’

Citing PyFE4AI

A technical report is in preparationcoming soon

BibTeX
@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}
}