Browse Source

minimal CC + GenCryptoContext

Rener Oliveira (Ubuntu WSL) 2 years ago
parent
commit
6fd424c8ff
4 changed files with 21 additions and 6 deletions
  1. 2 1
      .gitignore
  2. 11 3
      src/bindings.cpp
  3. 1 0
      src/bindings.h
  4. 7 2
      src/pke/examples/simple-integers.py

+ 2 - 1
.gitignore

@@ -1 +1,2 @@
-build/
+build/
+.vscode/

+ 11 - 3
src/bindings.cpp

@@ -1,7 +1,5 @@
 #include <pybind11/pybind11.h>
-#include <scheme/bfvrns/cryptocontextparams-bfvrns.h>
-#include <scheme/cryptocontextparams-base.h>
-#include <core/utils/inttypes.h>
+#include <openfhe/pke/openfhe.h>
 #include "bindings.h"
 
 using namespace lbcrypto;
@@ -26,8 +24,18 @@ void bind_parameters(py::module &m){
             // &CCParams<CryptoContextBFVRNS>::SetPlaintextModulus);
 }
 
+void bind_crypto_context(py::module &m){
+    py::class_<CryptoContextImpl<DCRTPoly>,std::shared_ptr<CryptoContextImpl<DCRTPoly>>>(m,"CryptoContextDCRTPoly")
+            .def("GetKeyGenLevel",&CryptoContextImpl<DCRTPoly>::GetKeyGenLevel)
+            .def("SetKeyGenLevel",&CryptoContextImpl<DCRTPoly>::SetKeyGenLevel);
+
+    m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>);
+    m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBGVRNS>);
+}
+
 PYBIND11_MODULE(openfhe, m) {
     m.doc() = "Open-Source Fully Homomorphic Encryption Library";
     bind_parameters(m);
+    bind_crypto_context(m);
 
 }

+ 1 - 0
src/bindings.h

@@ -4,5 +4,6 @@
 #include <pybind11/pybind11.h>
 
 void bind_parameters(pybind11::module &m);
+void bind_crypto_context(pybind11::module &m);
 
 #endif // OPENFHE_BINDINGS_H

+ 7 - 2
src/pke/examples/simple-integers.py

@@ -1,5 +1,5 @@
 # Initial Setting
-from openfhe import CCParamsBFVRNS
+from openfhe import *
 
 # Creating the parameters object
 parameters = CCParamsBFVRNS()
@@ -14,4 +14,9 @@ parameters.SetMultiplicativeDepth(2)
 
 # Getting new values
 print("New BFV Plaintext Modulus = " + str(parameters.GetPlaintextModulus()))
-print("New BFV Multiplicative Depth = " + str(parameters.GetMultiplicativeDepth()))
+print("New BFV Multiplicative Depth = " + str(parameters.GetMultiplicativeDepth()))
+
+cryptoContext = GenCryptoContext(parameters)
+
+cryptoContext.SetKeyGenLevel(2)
+print(cryptoContext.GetKeyGenLevel())