Browse Source

Merge branch 'main' into dev

Rener Oliveira 1 year ago
parent
commit
b6e22c7723

+ 4 - 0
.gitignore

@@ -4,3 +4,7 @@ build/
 .png
 .json
 .txt
+.cproject
+.project
+.settings/
+demoData/

+ 7 - 7
CMakeLists.txt

@@ -8,8 +8,8 @@ find_package(OpenFHE)
 find_package(pybind11 REQUIRED)
 
 set( CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS} )
-set( OpenFHE_Py_SOURCES src)
-set( OpenFHE_Py_INCLUDES include)
+set( OpenFHE_Py_SOURCES src/lib)
+set( OpenFHE_Py_INCLUDES src/include)
 
 include_directories( ${OPENMP_INCLUDES} )
 include_directories( ${OpenFHE_INCLUDE} )
@@ -42,11 +42,11 @@ endif()
 
 ### Pybind Modules
 pybind11_add_module(openfhe 
-                    src/bindings.cpp 
-                    src/binfhe_bindings.cpp
-                    src/binfhe/binfhecontext_wrapper.cpp
-                    src/pke/serialization.cpp 
-                    src/pke/cryptocontext_wrapper.cpp
+                    src/lib/bindings.cpp 
+                    src/lib/binfhe_bindings.cpp
+                    src/lib/binfhe/binfhecontext_wrapper.cpp
+                    src/lib/pke/serialization.cpp 
+                    src/lib/pke/cryptocontext_wrapper.cpp
                     )
 ### Python installation 
 # Allow the user to specify the path to Python executable (if not provided, find it)

+ 27 - 26
README.md

@@ -8,6 +8,7 @@
     - [Installing the .so: Conda](#conda)
     - [Installing the .so: System](#system-install)
 - [Running Examples](#code-examples)
+- [OpenFHE Python Wrapper Documentation](#openfhe-python-wrapper-documentation)
 
 ## Building
 
@@ -38,6 +39,7 @@ mkdir build
 cd build
 cmake ..  # Alternatively, cmake .. -DOpenFHE_DIR=/path/to/installed/openfhe
 make
+make install  # You may have to run sudo make install
 ```
 
 At this point the `.so` file has been built. Your exact installation process will depend on your virtual environment.
@@ -58,8 +60,9 @@ To do this, run the following commands:
 ```bash
 mkdir build
 cd build
-cmake ..  # Or cmake .. -DPYTHON_EXECUTABLE_PATH=$CONDA_PREFIX/bin/python
+cmake .. -DPYTHON_EXECUTABLE_PATH=$CONDA_PREFIX/bin/python
 make
+make install  # You may have to run sudo make install
 ```
 
 The CONDA_PREFIX variable is set by conda, and points to the root of your active conda environment.
@@ -76,38 +79,36 @@ which creates a lib folder, moves the built `.so` file into that lib folder, and
 
 **Note** You may wish to copy the `.so` file to any projects of your own, or add it to your system path to source from.
 
-#### System install
-
-```
-make install  # You may have to run sudo make install
-```
-
 ## Code Examples
 
 To get familiar with the OpenFHE Python API, check out the examples:
 
 - FHE for arithmetic over integers (BFV):
-  - [Simple Code Example](src/pke/examples/simple-integers.py)
-  <!-- - [Simple Code Example with Serialization](src/pke/examples/simple-integers-serial.py) -->
+  - [Simple Code Example](examples/pke/simple-integers.py)
+  <!-- - [Simple Code Example with Serialization](examples/pke/simple-integers-serial.py) -->
 - FHE for arithmetic over integers (BGV):
-  - [Simple Code Example](src/pke/examples/simple-integers-bgvrns.py)
-  <!-- - [Simple Code Example with Serialization](src/pke/examples/simple-integers-serial-bgvrns.py) -->
+  - [Simple Code Example](examples/pke/simple-integers-bgvrns.py)
+  <!-- - [Simple Code Example with Serialization](examples/pke/simple-integers-serial-bgvrns.py) -->
 - FHE for arithmetic over real numbers (CKKS):
-  - [Simple Code Example](src/pke/examples/simple-real-numbers.py)
-  - [Advanced Code Example](src/pke/examples/advanced-real-numbers.py)
-  - [Advanced Code Example for High-Precision CKKS](src/pke/examples/advanced-real-numbers-128.py)
-  - [Arbitrary Smooth Function Evaluation](src/pke/examples/function-evaluation.py)
-  - [Simple CKKS Bootstrapping Example](src/pke/examples/simple-ckks-bootstrapping.py)
-  - [Advanced CKKS Bootstrapping Example](src/pke/examples/advanced-ckks-bootstrapping.cpp)
-  - [Double-Precision (Iterative) Bootstrapping Example](src/pke/examples/iterative-ckks-bootstrapping.py)
+  - [Simple Code Example](examples/pke/simple-real-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)
+  - [Simple CKKS Bootstrapping Example](examples/pke/simple-ckks-bootstrapping.py)
+  - [Advanced CKKS Bootstrapping Example](examples/pke/advanced-ckks-bootstrapping.cpp)
+  - [Double-Precision (Iterative) Bootstrapping Example](examples/pke/iterative-ckks-bootstrapping.py)
 - FHE for Boolean circuits and larger plaintext spaces (FHEW/TFHE):
-  - [Simple Code Example](src/binfhe/examples/boolean.py)
-  - [Truth Table Example](src/binfhe/examples/boolean-truth-table.py)
-  <!-- - [Code with JSON serialization](src/binfhe/examples/boolean-serial-json.py) -->
-  <!-- - [Code with Binary Serialization](src/binfhe/examples/boolean-serial-binary.py) -->
-  <!-- - [Large-Precision Comparison](src/binfhe/examples/eval-sign.py) -->
-  <!-- - [Small-Precison Arbitrary Function Evaluation](src/binfhe/examples/eval-function.py) -->
+  - [Simple Code Example](examples/binfhe/boolean.py)
+  - [Truth Table Example](examples/binfhe/boolean-truth-table.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) -->
   <!-- - Threshold FHE:  -->
-  <!-- - [Code Example for BGV, BFV, and CKKS](src/pke/examples/threshold-fhe.py) -->
-  <!-- - [Code Example for BFV with 5 parties](src/pke/examples/threshold-fhe-5p.py) -->
+  <!-- - [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) -->
+
+## OpenFHE Python Wrapper Documentation
+
+[OpenFHE Python Wrapper API Reference](https://openfheorg.github.io/openfhe-python/html/index.html)
 

+ 0 - 0
src/binfhe/examples/boolean-ap.py → examples/binfhe/boolean-ap.py


+ 0 - 0
src/binfhe/examples/boolean-truth-tables.py → examples/binfhe/boolean-truth-tables.py


+ 0 - 0
src/binfhe/examples/boolean.py → examples/binfhe/boolean.py


+ 0 - 0
src/pke/examples/advanced-real-numbers-128.py → examples/pke/advanced-real-numbers-128.py


+ 0 - 0
src/pke/examples/advanced-real-numbers.py → examples/pke/advanced-real-numbers.py


+ 0 - 0
src/pke/examples/function-evaluation.py → examples/pke/function-evaluation.py


+ 0 - 0
src/pke/examples/iterative-ckks-bootstrapping.py → examples/pke/iterative-ckks-bootstrapping.py


+ 0 - 0
src/pke/examples/polynomial-evaluation.py → examples/pke/polynomial-evaluation.py


+ 0 - 0
src/pke/examples/simple-ckks-bootstrapping.py → examples/pke/simple-ckks-bootstrapping.py


+ 0 - 0
src/pke/examples/simple-integers-bgvrns.py → examples/pke/simple-integers-bgvrns.py


+ 0 - 0
src/pke/examples/simple-integers-serial-bgvrns.py → examples/pke/simple-integers-serial-bgvrns.py


+ 0 - 0
src/pke/examples/simple-integers-serial.py → examples/pke/simple-integers-serial.py


+ 0 - 0
src/pke/examples/simple-integers.py → examples/pke/simple-integers.py


+ 0 - 0
src/pke/examples/simple-real-numbers.py → examples/pke/simple-real-numbers.py


+ 0 - 0
include/bindings.h → src/include/bindings.h


+ 0 - 0
include/binfhe/binfhecontext_wrapper.h → src/include/binfhe/binfhecontext_wrapper.h


+ 0 - 0
include/binfhe_bindings.h → src/include/binfhe_bindings.h


+ 0 - 0
include/docstrings/binfhecontext_docs.h → src/include/docstrings/binfhecontext_docs.h


+ 0 - 0
include/docstrings/ciphertext_docs.h → src/include/docstrings/ciphertext_docs.h


+ 0 - 0
include/docstrings/cryptocontext_docs.h → src/include/docstrings/cryptocontext_docs.h


+ 0 - 0
include/docstrings/cryptoparameters_docs.h → src/include/docstrings/cryptoparameters_docs.h


+ 0 - 0
include/docstrings/plaintext_docs.h → src/include/docstrings/plaintext_docs.h


+ 0 - 0
include/pke/cryptocontext_wrapper.h → src/include/pke/cryptocontext_wrapper.h


+ 0 - 0
include/pke/serialization.h → src/include/pke/serialization.h


+ 0 - 0
src/bindings.cpp → src/lib/bindings.cpp


+ 1 - 1
src/binfhe/binfhecontext_wrapper.cpp → src/lib/binfhe/binfhecontext_wrapper.cpp

@@ -49,4 +49,4 @@ LWEPlaintext binfhe_DecryptWrapper(BinFHEContext &self,
     LWEPlaintext result;
     self.Decrypt(sk, ct, &result, p);
     return result;
-}
+}

+ 44 - 22
src/binfhe_bindings.cpp → src/lib/binfhe_bindings.cpp

@@ -42,37 +42,51 @@ void bind_binfhe_enums(py::module &m)
     py::enum_<BINFHE_PARAMSET>(m, "BINFHE_PARAMSET")
         .value("TOY", BINFHE_PARAMSET::TOY)
         .value("MEDIUM", BINFHE_PARAMSET::MEDIUM)
+        .value("STD128_LMKCDEY", BINFHE_PARAMSET::STD128_LMKCDEY)
         .value("STD128_AP", BINFHE_PARAMSET::STD128_AP)
-        .value("STD128_APOPT", BINFHE_PARAMSET::STD128_APOPT)
         .value("STD128", BINFHE_PARAMSET::STD128)
-        .value("STD128_OPT", BINFHE_PARAMSET::STD128_OPT)
         .value("STD192", BINFHE_PARAMSET::STD192)
-        .value("STD192_OPT", BINFHE_PARAMSET::STD192_OPT)
         .value("STD256", BINFHE_PARAMSET::STD256)
-        .value("STD256_OPT", BINFHE_PARAMSET::STD256_OPT)
         .value("STD128Q", BINFHE_PARAMSET::STD128Q)
-        .value("STD128Q_OPT", BINFHE_PARAMSET::STD128Q_OPT)
+        .value("STD128Q_LMKCDEY", BINFHE_PARAMSET::STD128Q_LMKCDEY)
         .value("STD192Q", BINFHE_PARAMSET::STD192Q)
-        .value("STD192Q_OPT", BINFHE_PARAMSET::STD192Q_OPT)
         .value("STD256Q", BINFHE_PARAMSET::STD256Q)
-        .value("STD256Q_OPT", BINFHE_PARAMSET::STD256Q_OPT)
+        .value("STD128_3", BINFHE_PARAMSET::STD128_3)
+        .value("STD128_3_LMKCDEY", BINFHE_PARAMSET::STD128_3_LMKCDEY)
+        .value("STD128Q_3", BINFHE_PARAMSET::STD128Q_3)
+        .value("STD128Q_3_LMKCDEY", BINFHE_PARAMSET::STD128Q_3_LMKCDEY)
+        .value("STD192Q_3", BINFHE_PARAMSET::STD192Q_3)
+        .value("STD256Q_3", BINFHE_PARAMSET::STD256Q_3)
+        .value("STD128_4", BINFHE_PARAMSET::STD128_4)
+        .value("STD128_4_LMKCDEY", BINFHE_PARAMSET::STD128_4_LMKCDEY)
+        .value("STD128Q_4", BINFHE_PARAMSET::STD128Q_4)
+        .value("STD128Q_4_LMKCDEY", BINFHE_PARAMSET::STD128Q_4_LMKCDEY)
+        .value("STD192Q_4", BINFHE_PARAMSET::STD192Q_4)
+        .value("STD256Q_4", BINFHE_PARAMSET::STD256Q_4)
         .value("SIGNED_MOD_TEST", BINFHE_PARAMSET::SIGNED_MOD_TEST);
     m.attr("TOY") = py::cast(BINFHE_PARAMSET::TOY);
     m.attr("MEDIUM") = py::cast(BINFHE_PARAMSET::MEDIUM);
+    m.attr("STD128_LMKCDEY") = py::cast(BINFHE_PARAMSET::STD128_LMKCDEY);
     m.attr("STD128_AP") = py::cast(BINFHE_PARAMSET::STD128_AP);
-    m.attr("STD128_APOPT") = py::cast(BINFHE_PARAMSET::STD128_APOPT);
     m.attr("STD128") = py::cast(BINFHE_PARAMSET::STD128);
-    m.attr("STD128_OPT") = py::cast(BINFHE_PARAMSET::STD128_OPT);
     m.attr("STD192") = py::cast(BINFHE_PARAMSET::STD192);
-    m.attr("STD192_OPT") = py::cast(BINFHE_PARAMSET::STD192_OPT);
     m.attr("STD256") = py::cast(BINFHE_PARAMSET::STD256);
-    m.attr("STD256_OPT") = py::cast(BINFHE_PARAMSET::STD256_OPT);
     m.attr("STD128Q") = py::cast(BINFHE_PARAMSET::STD128Q);
-    m.attr("STD128Q_OPT") = py::cast(BINFHE_PARAMSET::STD128Q_OPT);
+    m.attr("STD128Q_LMKCDEY") = py::cast(BINFHE_PARAMSET::STD128Q_LMKCDEY);
     m.attr("STD192Q") = py::cast(BINFHE_PARAMSET::STD192Q);
-    m.attr("STD192Q_OPT") = py::cast(BINFHE_PARAMSET::STD192Q_OPT);
     m.attr("STD256Q") = py::cast(BINFHE_PARAMSET::STD256Q);
-    m.attr("STD256Q_OPT") = py::cast(BINFHE_PARAMSET::STD256Q_OPT);
+    m.attr("STD128_3") = py::cast(BINFHE_PARAMSET::STD128_3);
+    m.attr("STD128_3_LMKCDEY") = py::cast(BINFHE_PARAMSET::STD128_3_LMKCDEY);
+    m.attr("STD128Q_3") = py::cast(BINFHE_PARAMSET::STD128Q_3);
+    m.attr("STD128Q_3_LMKCDEY") = py::cast(BINFHE_PARAMSET::STD128Q_3_LMKCDEY);
+    m.attr("STD192Q_3") = py::cast(BINFHE_PARAMSET::STD192Q_3);
+    m.attr("STD256Q_3") = py::cast(BINFHE_PARAMSET::STD256Q_3);
+    m.attr("STD128_4") = py::cast(BINFHE_PARAMSET::STD128_4);
+    m.attr("STD128_4_LMKCDEY") = py::cast(BINFHE_PARAMSET::STD128_4_LMKCDEY);
+    m.attr("STD128Q_4") = py::cast(BINFHE_PARAMSET::STD128Q_4);
+    m.attr("STD128Q_4_LMKCDEY") = py::cast(BINFHE_PARAMSET::STD128Q_4_LMKCDEY);
+    m.attr("STD192Q_4") = py::cast(BINFHE_PARAMSET::STD192Q_4);
+    m.attr("STD256Q_4") = py::cast(BINFHE_PARAMSET::STD256Q_4);
     m.attr("SIGNED_MOD_TEST") = py::cast(BINFHE_PARAMSET::SIGNED_MOD_TEST);
 
     py::enum_<BINFHE_METHOD>(m, "BINFHE_METHOD")
@@ -83,6 +97,12 @@ void bind_binfhe_enums(py::module &m)
     m.attr("GINX") = py::cast(BINFHE_METHOD::GINX);
     m.attr("AP") = py::cast(BINFHE_METHOD::AP);
 
+    py::enum_<KEYGEN_MODE>(m, "KEYGEN_MODE")
+        .value("SYM_ENCRYPT", KEYGEN_MODE::SYM_ENCRYPT)
+        .value("PUB_ENCRYPT", KEYGEN_MODE::PUB_ENCRYPT);
+    m.attr("SYM_ENCRYPT") = py::cast(KEYGEN_MODE::SYM_ENCRYPT);
+    m.attr("PUB_ENCRYPT") = py::cast(KEYGEN_MODE::PUB_ENCRYPT);
+
     py::enum_<BINFHE_OUTPUT>(m, "BINFHE_OUTPUT")
         .value("INVALID_OUTPUT", BINFHE_OUTPUT::INVALID_OUTPUT)
         .value("FRESH", BINFHE_OUTPUT::FRESH)
@@ -134,31 +154,33 @@ void bind_binfhe_context(py::module &m)
         .def(py::init<>())
         .def("GenerateBinFHEContext", static_cast<void (BinFHEContext::*)(BINFHE_PARAMSET, BINFHE_METHOD)>(&BinFHEContext::GenerateBinFHEContext),
              binfhe_GenerateBinFHEContext_parset_docs,
-             py::arg("set"), 
+             py::arg("set"),
              py::arg("method") = GINX)
         .def("KeyGen", &BinFHEContext::KeyGen,
-            binfhe_KeyGen_docs)
+             binfhe_KeyGen_docs)
         .def("BTKeyGen", &BinFHEContext::BTKeyGen,
-            binfhe_BTKeyGen_docs)
+             binfhe_BTKeyGen_docs,
+             py::arg("sk"),
+             py::arg("keygenMode") = SYM_ENCRYPT)
         .def("Encrypt", &binfhe_EncryptWrapper,
              binfhe_Encrypt_docs,
              py::arg("sk"),
              py::arg("m"),
              py::arg("output") = BOOTSTRAPPED,
-             py::arg("p") = 4, 
+             py::arg("p") = 4,
              py::arg("mod") = 0)
-        .def("Decrypt",&binfhe_DecryptWrapper,
+        .def("Decrypt", &binfhe_DecryptWrapper,
              binfhe_Decrypt_docs,
              py::arg("sk"),
              py::arg("ct"),
              py::arg("p") = 4)
-        .def("EvalBinGate",&BinFHEContext::EvalBinGate,
+        .def("EvalBinGate", 
+        static_cast<LWECiphertext (BinFHEContext::*)(BINGATE, ConstLWECiphertext &, ConstLWECiphertext &) const>(&BinFHEContext::EvalBinGate),
              binfhe_EvalBinGate_docs,
              py::arg("gate"),
              py::arg("ct1"),
              py::arg("ct2"))
-        .def("EvalNOT",&BinFHEContext::EvalNOT,
+        .def("EvalNOT", &BinFHEContext::EvalNOT,
              binfhe_EvalNOT_docs,
              py::arg("ct"));
-            
 }

+ 0 - 0
src/pke/cryptocontext_wrapper.cpp → src/lib/pke/cryptocontext_wrapper.cpp


+ 0 - 0
src/pke/serialization.cpp → src/lib/pke/serialization.cpp