Browse Source

Merge pull request #4 from openfheorg/Oliveira_bind_keys

key bindings
Rener Oliveira 2 years ago
parent
commit
56d958a983
3 changed files with 27 additions and 8 deletions
  1. 16 2
      src/bindings.cpp
  2. 1 1
      src/bindings.h
  3. 10 5
      src/pke/examples/simple-integers.py

+ 16 - 2
src/bindings.cpp

@@ -5,7 +5,6 @@
 using namespace lbcrypto;
 using namespace lbcrypto;
 namespace py = pybind11;
 namespace py = pybind11;
 
 
-
 void bind_parameters(py::module &m){
 void bind_parameters(py::module &m){
     py::class_<Params>(m, "Params");
     py::class_<Params>(m, "Params");
     py::class_<CCParams<CryptoContextBFVRNS>, Params>(m, "CCParamsBFVRNS")
     py::class_<CCParams<CryptoContextBFVRNS>, Params>(m, "CCParamsBFVRNS")
@@ -28,7 +27,10 @@ void bind_crypto_context(py::module &m){
     py::class_<CryptoContextImpl<DCRTPoly>,std::shared_ptr<CryptoContextImpl<DCRTPoly>>>(m,"CryptoContextDCRTPoly")
     py::class_<CryptoContextImpl<DCRTPoly>,std::shared_ptr<CryptoContextImpl<DCRTPoly>>>(m,"CryptoContextDCRTPoly")
             .def("GetKeyGenLevel",&CryptoContextImpl<DCRTPoly>::GetKeyGenLevel)
             .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");
+            .def("Enable",static_cast<void (CryptoContextImpl<DCRTPoly>::*)(PKESchemeFeature)>(&CryptoContextImpl<DCRTPoly>::Enable), "Enable a feature for the CryptoContext")
+            .def("KeyGen",&CryptoContextImpl<DCRTPoly>::KeyGen)
+            .def("EvalMultKeyGen",&CryptoContextImpl<DCRTPoly>::EvalMultKeyGen);
+
     // Generator Functions    
     // Generator Functions    
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>);
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>);
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBGVRNS>);
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBGVRNS>);
@@ -36,6 +38,9 @@ void bind_crypto_context(py::module &m){
 
 
 }
 }
 
 
+
+
+
 void bind_enums(py::module &m){
 void bind_enums(py::module &m){
     // Scheme Types
     // Scheme Types
     py::enum_<SCHEME>(m, "SCHEME")
     py::enum_<SCHEME>(m, "SCHEME")
@@ -54,10 +59,19 @@ void bind_enums(py::module &m){
             .value("FHE", PKESchemeFeature::FHE);
             .value("FHE", PKESchemeFeature::FHE);
 }
 }
 
 
+void bind_keys(py::module &m){
+    py::class_<PublicKeyImpl<DCRTPoly>,std::shared_ptr<PublicKeyImpl<DCRTPoly>>>(m,"PublicKey");
+    py::class_<PrivateKeyImpl<DCRTPoly>,std::shared_ptr<PrivateKeyImpl<DCRTPoly>>>(m,"PrivateKey");
+    py::class_<KeyPair<DCRTPoly>>(m,"KeyPair")
+            .def_readwrite("publicKey", &KeyPair<DCRTPoly>::publicKey)
+            .def_readwrite("secretKey", &KeyPair<DCRTPoly>::secretKey);
+}
+
 PYBIND11_MODULE(openfhe, m) {
 PYBIND11_MODULE(openfhe, m) {
     m.doc() = "Open-Source Fully Homomorphic Encryption Library";
     m.doc() = "Open-Source Fully Homomorphic Encryption Library";
     bind_parameters(m);
     bind_parameters(m);
     bind_crypto_context(m);
     bind_crypto_context(m);
     bind_enums(m);
     bind_enums(m);
+    bind_keys(m);
 
 
 }
 }

+ 1 - 1
src/bindings.h

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

+ 10 - 5
src/pke/examples/simple-integers.py

@@ -1,6 +1,6 @@
 # Initial Setting
 # Initial Setting
 from openfhe import *
 from openfhe import *
-import openfhe.PKESchemeFeature as Feature
+# import openfhe.PKESchemeFeature as Feature
 # Creating the parameters object
 # Creating the parameters object
 parameters = CCParamsBFVRNS()
 parameters = CCParamsBFVRNS()
 
 
@@ -20,8 +20,13 @@ cryptoContext = GenCryptoContext(parameters)
 
 
 cryptoContext.SetKeyGenLevel(2)
 cryptoContext.SetKeyGenLevel(2)
 print(cryptoContext.GetKeyGenLevel())
 print(cryptoContext.GetKeyGenLevel())
-print(Feature.__members__)
-cryptoContext.Enable(Feature.PKE)
-cryptoContext.Enable(Feature.KEYSWITCH)
-cryptoContext.Enable(Feature.LEVELEDSHE)
+print(PKESchemeFeature.__members__)
+cryptoContext.Enable(PKESchemeFeature.PKE)
+cryptoContext.Enable(PKESchemeFeature.KEYSWITCH)
+cryptoContext.Enable(PKESchemeFeature.LEVELEDSHE)
+
+keypair = cryptoContext.KeyGen()
+print("Public Key: " + str(keypair.publicKey))
+
+cryptoContext.EvalMultKeyGen(keypair.secretKey)