Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Automatic build-and-test. It reuses the same pipeline as the Manual workflow,
# pinned to the supported OpenFHE version.
#
# The triggers below stay commented out until after the next release. Before
# enabling them, note:
# - push: safe to enable as-is (the downstream builder checks out
# ${{ github.ref_name }}, which exists in this repository for pushes).
# - pull_request: NOT functional yet. For PR events github.ref_name is
# "<number>/merge", which the builder's fresh clone cannot check out, and fork
# branches do not exist in this repository. The reusable workflow must first be
# taught to fetch the PR merge/head SHA explicitly (or build the caller's
# checked-out workspace).
# - runner policy: the pipeline runs on ${{ vars.RUNNER }}. If that is a
# self-hosted runner, do not run fork-PR code on it; also consider pinning the
# reusable workflow/action/packager references to commit SHAs instead of the
# mutable github-ci/main branches.
name: CI

permissions:
contents: read

on:
workflow_dispatch:
# push:
# branches:
# - main
# - dev
# pull_request: # see the notes above before enabling

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-test:
uses: ./.github/workflows/manual.yml
with:
compiler: 'CLANG-18'
native_backend: '64'
openfhe_development_branch: 'v1.6.1'
54 changes: 26 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ cmake_minimum_required (VERSION 3.16.3)
project (OpenFHE-Python)

set(OPENFHE_PYTHON_VERSION_MAJOR 1)
set(OPENFHE_PYTHON_VERSION_MINOR 5)
set(OPENFHE_PYTHON_VERSION_MINOR 6)
set(OPENFHE_PYTHON_VERSION_PATCH 1)
set(OPENFHE_PYTHON_VERSION_TWEAK 0)
set(OPENFHE_PYTHON_VERSION ${OPENFHE_PYTHON_VERSION_MAJOR}.${OPENFHE_PYTHON_VERSION_MINOR}.${OPENFHE_PYTHON_VERSION_PATCH}.${OPENFHE_PYTHON_VERSION_TWEAK})

# OpenFHE version can be specified externally (-DOPENFHE_REQUIRED_VERSION=1.5.1)
# OpenFHE version can be specified externally (-DOPENFHE_REQUIRED_VERSION=1.6.1)
if(NOT DEFINED OPENFHE_REQUIRED_VERSION)
set(OPENFHE_REQUIRED_VERSION "1.5.1" CACHE STRING "Required OpenFHE version")
set(OPENFHE_REQUIRED_VERSION "1.6.1" CACHE STRING "Required OpenFHE version")
else()
# User provided OPENFHE_REQUIRED_VERSION via -D
message(STATUS "Using user-specified OpenFHE version: ${OPENFHE_REQUIRED_VERSION}")
Expand All @@ -26,6 +26,15 @@ endif()
find_package(OpenFHE ${OPENFHE_REQUIRED_VERSION} REQUIRED)
message(STATUS "Building with OpenFHE version: ${OPENFHE_REQUIRED_VERSION}")

# Allow the user to specify the path to the Python executable (if not provided, find it).
# Python must be selected before pybind11 is found: pybind11 locks in the first Python
# that CMake discovers, and a later find_package(Python) with a different interpreter fails.
set(PYTHON_EXECUTABLE_PATH "" CACHE FILEPATH "Path to Python executable")
if(PYTHON_EXECUTABLE_PATH)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE_PATH}")
endif()
find_package(Python REQUIRED COMPONENTS Interpreter Development)

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 REQUIRED)

Expand Down Expand Up @@ -66,11 +75,14 @@ endif()
### add_executable( test demo-simple-example.cpp )

### Pybind Modules
pybind11_add_module(openfhe
src/lib/bindings.cpp
add_compile_definitions(OPENFHE_PYTHON_VERSION_STR="${OPENFHE_PYTHON_VERSION}")
pybind11_add_module(openfhe
src/lib/bindings.cpp
src/lib/binfhe_bindings.cpp
src/lib/binfhe/binfhecontext_wrapper.cpp
src/lib/pke/serialization.cpp
src/lib/pke/serialization.cpp
src/lib/pke/fbt.cpp
src/lib/pke/schemeswitching_data_serializer.cpp
)
# The next line ensures that the installed openfhe module can find its shared library dependencies
# in the 'lib/' subdirectory relative to itself without requiring LD_LIBRARY_PATH.
Expand All @@ -97,28 +109,14 @@ elseif(APPLE)
endif()


### Python installation
# Allow the user to specify the path to Python executable (if not provided, find it)
option(PYTHON_EXECUTABLE_PATH "Path to Python executable" "")
if(PYTHON_EXECUTABLE_PATH)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE_PATH}")
endif()
find_package(Python REQUIRED COMPONENTS Interpreter Development)

# Check Python version
if(${Python_VERSION_MAJOR} EQUAL 3 AND ${Python_VERSION_MINOR} GREATER_EQUAL 10)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "from sys import exec_prefix; print(exec_prefix)"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
### Python installation
# sysconfig's platlib is the platform-specific site-packages directory (also inside venvs);
# sys.exec_prefix used here previously is the installation root, not site-packages.
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import sysconfig; print(sysconfig.get_path('platlib'))"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(STATUS "Python site packages directory: ${PYTHON_SITE_PACKAGES}")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand Down
65 changes: 53 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![License](https://img.shields.io/badge/License-BSD%202--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause)
[![Python Versions](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
[![OpenFHE Version](https://img.shields.io/badge/OpenFHE-1.5.1%2B-green)](https://github.com/openfheorg/openfhe-development)
[![OpenFHE Version](https://img.shields.io/badge/OpenFHE-1.6.1%2B-green)](https://github.com/openfheorg/openfhe-development)

Python wrapper for the main cryptographic capabilities of the OpenFHE C++ library. `OpenFHE-Python` provides a more user-friendly interface for Python developers, while keeping the efficiency of C++ FHE operations.

Expand Down Expand Up @@ -42,7 +42,7 @@ The legacy build instructions below are for other operating systems where [openf

Before building, make sure you have the following dependencies installed:

- [OpenFHE 1.5.1+](https://github.com/openfheorg/openfhe-development) by following the instructions in [OpenFHE Documentation](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/installation/installation.html)
- [OpenFHE 1.6.1+](https://github.com/openfheorg/openfhe-development) by following the instructions in [OpenFHE Documentation](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/installation/installation.html)
- [Python 3.10+](https://www.python.org/)
- [pybind11](https://pybind11.readthedocs.io/en/stable/installing.html)

Expand Down Expand Up @@ -127,33 +127,74 @@ To get familiar with the OpenFHE Python API, check out the examples:

- FHE for arithmetic over integers (BFV):
- [Simple Code Example](examples/pke/simple-integers.py)
<!-- - [Simple Code Example with Serialization](examples/pke/simple-integers-serial.py) -->
- [Simple Code Example with Serialization](examples/pke/simple-integers-serial.py)
- [Computation Circuit of Depth 3](examples/pke/depth-bfvrns.py)
- [Computation Circuit of Depth 3 with the BEHZ Multiplication Technique](examples/pke/depth-bfvrns-behz.py)
- FHE for arithmetic over integers (BGV):
- [Simple Code Example](examples/pke/simple-integers-bgvrns.py)
<!-- - [Simple Code Example with Serialization](examples/pke/simple-integers-serial-bgvrns.py) -->
- [Simple Code Example with Serialization](examples/pke/simple-integers-serial-bgvrns.py)
- [Computation Circuit of Depth 3](examples/pke/depth-bgvrns.py)
- FHE for arithmetic over real numbers (CKKS):
- [Simple Code Example](examples/pke/simple-real-numbers.py)
- [Simple Code Example with Serialization](examples/pke/simple-real-numbers-serial.py)
- [Simple Code Example for Complex Numbers](examples/pke/simple-complex-numbers.py)
- [Advanced Code Example](examples/pke/advanced-real-numbers.py)
- [Advanced Code Example for High-Precision CKKS](examples/pke/advanced-real-numbers-128.py)
- [Arbitrary Smooth Function Evaluation](examples/pke/function-evaluation.py)
- [Polynomial Evaluation](examples/pke/polynomial-evaluation.py)
- [Linear Weighted Sum Evaluation](examples/pke/linearwsum-evaluation.py)
- [Decryption with Noise Flooding](examples/pke/ckks-noise-flooding.py)
- [Releasing Memory Used by Precomputations](examples/pke/ckks-release-memory.py)
- CKKS with Composite Scaling:
- [Simple Code Example](examples/pke/simple-real-numbers-composite-scaling.py)
- [Simple Code Example with Manual Rescaling](examples/pke/simple-composite-scaling-manual.py)
- [High-Precision Polynomial Evaluation](examples/pke/polynomial-evaluation-high-precision-composite-scaling.py)
- CKKS Bootstrapping:
- [Simple CKKS Bootstrapping Example](examples/pke/simple-ckks-bootstrapping.py)
- [Advanced CKKS Bootstrapping Example](examples/pke/advanced-ckks-bootstrapping.cpp)
- [Advanced CKKS Bootstrapping Example](examples/pke/advanced-ckks-bootstrapping.py)
- [Double-Precision (Iterative) Bootstrapping Example](examples/pke/iterative-ckks-bootstrapping.py)
- [Simple Bootstrapping Example with Composite Scaling](examples/pke/simple-ckks-bootstrapping-composite-scaling.py)
- [Double-Precision (Iterative) Bootstrapping Example with Composite Scaling](examples/pke/iterative-ckks-bootstrapping-composite-scaling.py)
- [Serialization of Bootstrapping Keys](examples/pke/ckks-bootstrap-keys-serial.py)
- [Functional Bootstrapping for RLWE Ciphertexts](examples/pke/functional-bootstrapping-ckks.py)
- [Fourier-Extension (FE) Functional Bootstrapping](examples/pke/FE-functional-bootstrapping-ckks.py)
- Operations over Encrypted Vectors (BFV and CKKS):
- [Vector Rotation Example](examples/pke/rotation.py)
- [Inner Product Example](examples/pke/inner-product.py)
- Proxy Re-Encryption (PRE):
- [Simple Code Example with Buffers (BFV)](examples/pke/pre-buffer.py)
- [HRA-Secure PRE with 13 Hops (BGV)](examples/pke/pre-hra-secure.py)
- FHE for Boolean circuits and larger plaintext spaces (FHEW/TFHE):
- [Simple Code Example with Symmetric Encryption](examples/binfhe/boolean.py)
- [Truth Table Example](examples/binfhe/boolean-truth-table.py)
- [Simple Code Example with the AP Bootstrapping Method](examples/binfhe/boolean-ap.py)
- [Simple Code Example with the LMKCDEY Bootstrapping Method](examples/binfhe/boolean-lmkcdey.py)
- [Multi-Input Gates Example](examples/binfhe/boolean-multi-input.py)
- [Truth Table Example](examples/binfhe/boolean-truth-tables.py)
- [Code with JSON Serialization](examples/binfhe/boolean-serial-json.py)
- [Code with Binary Serialization](examples/binfhe/boolean-serial-binary.py)
- [Large-Precision Comparison](examples/binfhe/eval-sign.py)
- [Small-Precision Arbitrary Function Evaluation](examples/binfhe/eval-function.py)
- [Homomorphic Digit Decomposition](examples/binfhe/eval-decomp.py)
- [Homomorphic Flooring](examples/binfhe/eval-flooring.py)
- [JSON Serialization for Large-Precision Sign Evaluation with Dynamic Bootstrapping Keys](examples/binfhe/boolean-serial-json-dynamic-large-precision.py)
- [Binary Serialization for Large-Precision Sign Evaluation with Dynamic Bootstrapping Keys](examples/binfhe/boolean-serial-binary-dynamic-large-precision.py)
- FHEW/TFHE with Public-Key Encryption:
- [Simple Code Example](examples/binfhe/pke/boolean-pke.py)
- [Simple Code Example with the AP Bootstrapping Method](examples/binfhe/pke/boolean-ap-pke.py)
- [Truth Table Example](examples/binfhe/pke/boolean-truth-tables-pke.py)
- [Code with JSON Serialization](examples/binfhe/pke/boolean-serial-json-pke.py)
- [Code with Binary Serialization](examples/binfhe/pke/boolean-serial-binary-pke.py)
- [Small-Precision Arbitrary Function Evaluation](examples/binfhe/pke/eval-function-pke.py)
- [Homomorphic Flooring](examples/binfhe/pke/eval-flooring-pke.py)
- Scheme Switching:
- [Examples with Scheme Switching between CKKS and FHEW/TFHE](examples/pke/scheme-switching.py)
<!-- - [Code with JSON serialization](examples/binfhe/boolean-serial-json.py) -->
<!-- - [Code with Binary Serialization](examples/binfhe/boolean-serial-binary.py) -->
<!-- - [Large-Precision Comparison](examples/binfhe/eval-sign.py) -->
<!-- - [Small-Precison Arbitrary Function Evaluation](examples/binfhe/eval-function.py) -->
- [Scheme Switching with Serialization](examples/pke/scheme-switching-serial.py)
- Threshold FHE:
- [Code Example for BGV, BFV, and CKKS](examples/pke/threshold-fhe.py)
- [Code Example for BFV with 5 parties](examples/pke/threshold-fhe-5p.py)
- [2-party Interactive Bootstrapping Examples](examples/pke/interactive-bootstrapping.py)
- [Simple n-party Interactive Bootstrapping Example](examples/pke/tckks-interactive-mp-bootstrapping.py)
- [n-party Interactive Bootstrapping after Chebyshev Approximation](examples/pke/tckks-interactive-mp-bootstrapping-Chebyschev.py)
- [Code Example for BFV with 5 parties](examples/pke/threshold-fhe-5p.py)
- [n-party Interactive Bootstrapping after Chebyshev Approximation](examples/pke/tckks-interactive-mp-bootstrapping-Chebyshev.py)

## OpenFHE Python Wrapper Documentation

Expand Down
46 changes: 45 additions & 1 deletion docs/binfhe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,48 @@ LWEPrivateKey
.. autoclass:: openfhe.LWEPrivateKey
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:

LWEPublicKey
----------------
.. autoclass:: openfhe.LWEPublicKey
:members:
:undoc-members:
:show-inheritance:

LWESwitchingKey
----------------
.. autoclass:: openfhe.LWESwitchingKey
:members:
:undoc-members:
:show-inheritance:

LWEKeyPair
----------------
.. autoclass:: openfhe.LWEKeyPair
:members:
:undoc-members:
:show-inheritance:

RingGSWBTKey
----------------
.. autoclass:: openfhe.RingGSWBTKey
:members:
:undoc-members:
:show-inheritance:

Serialization
----------------
BinFHE objects are serialized with the overloads of ``SerializeToFile`` and
deserialized with the functions below, each returning an ``(object, success)``
tuple.

.. autofunction:: openfhe.DeserializeBinFHECryptoContext

.. autofunction:: openfhe.DeserializeLWECiphertext

.. autofunction:: openfhe.DeserializeLWEPrivateKey

.. autofunction:: openfhe.DeserializeLWEPublicKey

.. autofunction:: openfhe.DeserializeBinFHEBTKey
18 changes: 12 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
# -- Project information -----------------------------------------------------

project = 'openfhe-python'
copyright = '2023, Yuriy Polyakov, Ian Quah, Rener Oliveira, and Matthew Triplett.'
author = 'Yuriy Polyakov, Ian Quah, Rener Oliveira, and Matthew Triplett.'

copyright = '2023-2026, Yuriy Polyakov, Ian Quah, Rener Oliveira, Matthew Triplett, and Dmitriy Suponitskiy.'
author = 'Yuriy Polyakov, Ian Quah, Rener Oliveira, Matthew Triplett, and Dmitriy Suponitskiy.'

# The full version, including alpha/beta/rc tags. Taken from the built module
# when it is importable; the fallback must match OPENFHE_PYTHON_VERSION in
# CMakeLists.txt.
try:
import openfhe
release = openfhe.__version__
except Exception:
release = '1.6.1.0'
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = 'v1.5.1.0'
version = '.'.join(release.split('.')[:2])


# -- General configuration ---------------------------------------------------
Expand Down
Loading