Browse Source

binding enums for PScheme Features

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

+ 24 - 2
src/bindings.cpp

@@ -27,15 +27,37 @@ void bind_parameters(py::module &m){
 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);
-
+            .def("SetKeyGenLevel",&CryptoContextImpl<DCRTPoly>::SetKeyGenLevel)
+            .def("Enable",static_cast<void (CryptoContextImpl<DCRTPoly>::*)(PKESchemeFeature)>(&CryptoContextImpl<DCRTPoly>::Enable), "Enable a feature for the CryptoContext");
+    // Generator Functions    
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>);
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBGVRNS>);
+    
+
+}
+
+void bind_enums(py::module &m){
+    // Scheme Types
+    py::enum_<SCHEME>(m, "SCHEME")
+            .value("INVALID_SCHEME", SCHEME::INVALID_SCHEME)
+            .value("CKKSRNS_SCHEME", SCHEME::CKKSRNS_SCHEME)
+            .value("BFVRNS_SCHEME", SCHEME::BFVRNS_SCHEME)
+            .value("BGVRNS_SCHEME", SCHEME::BGVRNS_SCHEME);
+    // PKE Features
+    py::enum_<PKESchemeFeature>(m, "PKESchemeFeature")
+            .value("PKE", PKESchemeFeature::PKE)
+            .value("KEYSWITCH", PKESchemeFeature::KEYSWITCH)
+            .value("PRE", PKESchemeFeature::PRE)
+            .value("LEVELEDSHE", PKESchemeFeature::LEVELEDSHE)
+            .value("ADVANCEDSHE", PKESchemeFeature::ADVANCEDSHE)
+            .value("MULTIPARTY", PKESchemeFeature::MULTIPARTY)
+            .value("FHE", PKESchemeFeature::FHE);
 }
 
 PYBIND11_MODULE(openfhe, m) {
     m.doc() = "Open-Source Fully Homomorphic Encryption Library";
     bind_parameters(m);
     bind_crypto_context(m);
+    bind_enums(m);
 
 }

+ 1 - 0
src/bindings.h

@@ -5,5 +5,6 @@
 
 void bind_parameters(pybind11::module &m);
 void bind_crypto_context(pybind11::module &m);
+void bind_enums(pybind11::module &m);
 
 #endif // OPENFHE_BINDINGS_H

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

@@ -1,6 +1,6 @@
 # Initial Setting
 from openfhe import *
-
+import openfhe.PKESchemeFeature as Feature
 # Creating the parameters object
 parameters = CCParamsBFVRNS()
 
@@ -19,4 +19,9 @@ print("New BFV Multiplicative Depth = " + str(parameters.GetMultiplicativeDepth(
 cryptoContext = GenCryptoContext(parameters)
 
 cryptoContext.SetKeyGenLevel(2)
-print(cryptoContext.GetKeyGenLevel())
+print(cryptoContext.GetKeyGenLevel())
+print(Feature.__members__)
+cryptoContext.Enable(Feature.PKE)
+cryptoContext.Enable(Feature.KEYSWITCH)
+cryptoContext.Enable(Feature.LEVELEDSHE)
+