🌐 Project Page · 📖 Documentation · 🐛 Issues
PyFE4AI is a research-oriented Python library for functional encryption in trustworthy AI systems. It currently focuses on inner-product and quadratic functional encryption, with implementations spanning single-input, multi-input, multi-client, threshold, decentralized, and function-hiding settings.
conda env create -f environment.yml
conda activate pyfe4ai
pip install -e ".[test]" # editable with test extras
python -m pytest -m core -q # run the core test suiteFor pairing-based FE families (and the full test suite, python -m pytest -q),
additionally install:
pip install -e ".[test,pairing]"from pyfe4ai import SIFE, SIFEKeyGenerator
x = [2, 1, 3]
y = [4, 5, 6]
# Key generation
kg = SIFEKeyGenerator({"sec_param": 128, "eta": len(x)})
kg.setup()
pp = kg.get_public_parameters()
sk = kg.get_private_keys()
dk = kg.get_decryption_keys("sid_0", credentials={"fusion_weight": y})
# Encrypt (needs pp + sk)
encryptor = SIFE({"precision": 3, "keys": {"pp": pp, "sk": sk}})
ct = encryptor.encrypt(x)
# Decrypt (needs pp + dk)
decryptor = SIFE({"precision": 3, "keys": {"pp": pp}})
result = decryptor.decrypt(ct, dk, y)
print("<x, y> =", result) # → 31See examples/sife_minimal.py for the full runnable version.
- Multiple FE families — DDH, LWE, Ring-LWE, FullySec-LWE, Paillier, and Damgård instantiations across SIFE, MIFE, and MCFE
- Threshold & decentralized —
tMIFE,tMCFE,dMCFEfor distributed trust settings - Function-hiding — pairing-based FH-IPE and FH-Multi-IPE with full inner-product privacy
- Quadratic FE — SGP (secret-key) and Quad (public-key) quadratic functional encryption
- ML adapter —
utils/ml_adapter.pyfor encrypted linear inference and federated gradient aggregation - Precision toolkit —
utils/quantization.pyfor float ↔ integer quantization with configurable bit-width - Discrete-log solvers — cached dlog table (default) with on-the-fly BSGS as optional backup in
utils/dlog_solver.py - NTT acceleration — number-theoretic transform for Ring-LWE polynomial multiplication in
utils/ring_lwe_utils.py - Structured exceptions —
FEErrorhierarchy inutils/exceptions.py
| Family | Instantiations | Paper(s) |
|---|---|---|
| SIFE (single-input) | DDH, DDH-Dynamic, LWE | ABDP15 (PKC '15) |
| Damgård-DDH, FullySec-LWE, Paillier | ALS16 (CRYPTO '16) | |
| Ring-LWE | BMMS21 (ePrint) | |
| FH-IPE (pairing) | KLMMRW (SCN '18) | |
| Partial-FH-IPE (pairing) | Gay20 (EUROCRYPT '20) | |
| MIFE (multi-input) | DDH, DDH-Hybrid-α, Damgård-DDH, LWE, FullySec-LWE, Ring-LWE, Paillier, FH-IPE | ACFGU18 (CRYPTO '18) ¹ |
| FH-Multi-IPE (pairing) | DOT18 (ePrint) | |
| MCFE (multi-client) | DDH, Damgård-DDH, LWE, FullySec-LWE, Ring-LWE, Paillier | CDGPP18 (ASIACRYPT '18) ¹ |
| FH-Multi-IPE (pairing) | CDGPP18 + DOT18 | |
| Decentralized | dMCFE-DDH | ABKW19 (PKC '19) |
| dMCFE-LWE, dMCFE-Ring-LWE, dMCFE-Paillier, dMCFE-FH-Multi-IPE | ABKW19 ¹ | |
| Threshold | tMIFE (DDH, LWE), tMCFE (DDH, LWE, Ring-LWE, FH-Multi-IPE) | Xu+24 (IEEE TDSC '24) ² |
| Quadratic | SGP (secret-key), Multi-Input SGP | DSGPP18 (ePrint) |
| Quad (public-key) | Gay20 (EUROCRYPT '20) |
¹ Multi-input, multi-client, and decentralized schemes compose a framework paper (ACFGU18 / CDGPP18 / ABKW19) with a per-slot single-input primitive — the concrete SIFE instantiation (ABDP15, ALS16, BMMS21, etc.) varies by row. See each module's docstring for the exact combination.
² Threshold variants add a Shamir secret-sharing layer on top of the corresponding MIFE or MCFE scheme; there is no separate standalone paper for each combination.
pyfe4ai/: installable Python packageschemes/: core cryptographic scheme implementationssife/: single-input familiesmife/: multi-input familiesmcfe/: multi-client familiesquadratic/: quadratic functional encryption families
utils/: utility modulescrypto_constants.py,crypto_utils.py: group generation and constantslwe_utils.py,ring_lwe_utils.py: LWE / Ring-LWE helpers with NTTdlog_solver.py: dlog table cache + BSGS discrete-log recoveryml_adapter.py: ML integration (encrypted inference, FL aggregation)quantization.py: float ↔ integer quantization toolkitexceptions.py:FEErrorexception hierarchysampling_utils.py,matrix_utils.py,modular_utils.py: math helperspairing_backend.py,pairing_utils.py: charm-crypto pairing layer
logger.py,config.yaml: logging configuration
docs/: Sphinx API documentation (see API Documentation)tests/: end-to-end and regression tests (sife/,mife/,mcfe/,quadratic/)examples/: minimal runnable usage examplesbenchmarks/: lightweight benchmark scriptsenvironment.yml: reproducible Conda environmentDockerfile.pairing: Docker-based pairing-enabled test environment
Scheme modules are organized by family and then named by instantiation:
<family>/<instantiation>.py<family>/<instantiation>_<variant>.py
Examples:
pyfe4ai/schemes/sife/ddh.pypyfe4ai/schemes/sife/damgard_ddh.pypyfe4ai/schemes/mife/ddh_threshold.pypyfe4ai/schemes/mcfe/ring_lwe_threshold.py
The instantiation segment may describe a security assumption, a concrete
cryptosystem, or a named construction lineage, depending on what is most
accurate for the scheme:
ddh: DDH-based discrete-log style constructionlwe: LWE-based instantiationpaillier: Paillier-based instantiationdamgard_ddh: Damgard-style DDH instantiation
python -m pytest -q # all tests
python -m pytest -m core -q # core FE/IPFE smoke lane only
python -m pytest -m extended -q # pairing-heavy & quadratic families onlyThe core lane is the main public release lane. The extended lane covers
pairing-heavy and quadratic families that remain publicly available but are kept
outside the minimal smoke path.
Minimal runnable examples are grouped as follows:
- Core FE/IPFE
examples/sife_minimal.pyexamples/mife_minimal.pyexamples/mcfe_threshold_demo.py
- LWE and threshold/decentralized variants
examples/lwe_minimal.pyexamples/mife_lwe_minimal.pyexamples/mcfe_lwe_minimal.pyexamples/mcfe_lwe_decentralized_demo.pyexamples/mcfe_lwe_threshold_demo.pyexamples/mife_lwe_threshold_demo.py
- ML / privacy-preserving AI
examples/ml_encrypted_inference.pyexamples/ml_fl_aggregation.py
- Pairing-based extended families
examples/mife_fh_multi_ipe_minimal.pyexamples/mcfe_fh_multi_ipe_minimal.pyexamples/mcfe_fh_multi_ipe_decentralized_demo.pyexamples/mcfe_fh_multi_ipe_threshold_demo.py
- Quadratic FE
examples/quadratic_sgp_minimal.pyexamples/quadratic_quad_minimal.py
For a short walkthrough of the example set, see examples/README.md.
Lightweight benchmark scripts are available under benchmarks/.
For benchmark entry points, see benchmarks/README.md.
Browse the full API reference online at
https://spire-studio.github.io/pyfe4ai/docs/ (rebuilt automatically on
every merge to main).
To build the docs locally instead:
pip install -e ".[doc]" # install Sphinx + theme
cd docs && make html # build HTML docs
open _build/html/index.html # view locallyThe schemes in the following files depend on
charm-crypto-framework:
pyfe4ai/schemes/sife/fh_ipe_pairing.pypyfe4ai/schemes/sife/part_fh_ipe_pairing.pypyfe4ai/schemes/mife/fh_ipe_pairing.pypyfe4ai/schemes/mife/fh_multi_ipe_pairing.pypyfe4ai/schemes/mcfe/fh_multi_ipe_pairing.pypyfe4ai/schemes/quadratic/sgp.py
charm-crypto-framework supports macOS, Linux, and Windows, but pairing-based
setups may still require additional system libraries depending on the platform.
If you plan to work heavily with these schemes, a Linux or Docker environment is
still the most reproducible option.
To run the pairing-enabled environment in Docker:
docker build -f Dockerfile.pairing -t pyfe4ai-pairing .
docker run --rm pyfe4ai-pairing
⚠️ Research Prototype — Not for Production UsePyFE4AI is a research-oriented library and has not undergone a formal security audit. Code organization and APIs may change at any point.
The purpose of this project is to support research and proof-of-concept implementations. It should not be used in production or in any setting where real-world security guarantees are required.
In particular:
- Implementations have not been hardened against side-channel attacks (timing, cache, power analysis, etc.).
- Parameter choices in examples and tests are selected for fast execution, not for cryptographic strength.
- Several schemes write generated public parameters into local
config/subdirectories during setup.
If you use PyFE4AI in your research, please cite it (a technical report is in preparation and will be added here once published):
@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}
}Citation metadata is also available in CITATION.cff — use
GitHub's "Cite this repository" button in the sidebar for APA/BibTeX.
This project is licensed under the Apache License 2.0. See the
LICENSE file for details.
- Contribution guide:
CONTRIBUTING.md - Security reporting:
SECURITY.md - Citation metadata:
CITATION.cff - Code of conduct:
CODE_OF_CONDUCT.md
