|
@@ -15,6 +15,7 @@
|
|
#include "cryptocontext_docs.h"
|
|
#include "cryptocontext_docs.h"
|
|
#include "plaintext_docs.h"
|
|
#include "plaintext_docs.h"
|
|
#include "ciphertext_docs.h"
|
|
#include "ciphertext_docs.h"
|
|
|
|
+#include "serialization.h"
|
|
|
|
|
|
using namespace lbcrypto;
|
|
using namespace lbcrypto;
|
|
namespace py = pybind11;
|
|
namespace py = pybind11;
|
|
@@ -101,13 +102,14 @@ void bind_crypto_context(py::module &m)
|
|
.def("GetKeyGenLevel", &CryptoContextImpl<DCRTPoly>::GetKeyGenLevel, cc_GetKeyGenLevel_docs)
|
|
.def("GetKeyGenLevel", &CryptoContextImpl<DCRTPoly>::GetKeyGenLevel, cc_GetKeyGenLevel_docs)
|
|
.def("SetKeyGenLevel", &CryptoContextImpl<DCRTPoly>::SetKeyGenLevel, cc_SetKeyGenLevel_docs,
|
|
.def("SetKeyGenLevel", &CryptoContextImpl<DCRTPoly>::SetKeyGenLevel, cc_SetKeyGenLevel_docs,
|
|
py::arg("level"))
|
|
py::arg("level"))
|
|
|
|
+ .def("get_ptr", [](const CryptoContext<DCRTPoly> &self)
|
|
|
|
+ { std::cout << "CC shared ptr (python cc)" << self << std::endl; })
|
|
//.def("GetScheme",&CryptoContextImpl<DCRTPoly>::GetScheme)
|
|
//.def("GetScheme",&CryptoContextImpl<DCRTPoly>::GetScheme)
|
|
//.def("GetCryptoParameters", &CryptoContextImpl<DCRTPoly>::GetCryptoParameters)
|
|
//.def("GetCryptoParameters", &CryptoContextImpl<DCRTPoly>::GetCryptoParameters)
|
|
.def("GetRingDimension", &CryptoContextImpl<DCRTPoly>::GetRingDimension, cc_GetRingDimension_docs)
|
|
.def("GetRingDimension", &CryptoContextImpl<DCRTPoly>::GetRingDimension, cc_GetRingDimension_docs)
|
|
.def("GetPlaintextModulus", &GetPlaintextModulusWrapper, cc_GetPlaintextModulus_docs)
|
|
.def("GetPlaintextModulus", &GetPlaintextModulusWrapper, cc_GetPlaintextModulus_docs)
|
|
.def("GetModulus", &GetModulusWrapper, cc_GetModulus_docs)
|
|
.def("GetModulus", &GetModulusWrapper, cc_GetModulus_docs)
|
|
.def("GetCyclotomicOrder", &CryptoContextImpl<DCRTPoly>::GetCyclotomicOrder, cc_GetCyclotomicOrder_docs)
|
|
.def("GetCyclotomicOrder", &CryptoContextImpl<DCRTPoly>::GetCyclotomicOrder, cc_GetCyclotomicOrder_docs)
|
|
- // .def("GetModulus", &CryptoContextImpl<DCRTPoly>::GetModulus, cc_GetModulus_docs)
|
|
|
|
.def("Enable", static_cast<void (CryptoContextImpl<DCRTPoly>::*)(PKESchemeFeature)>(&CryptoContextImpl<DCRTPoly>::Enable), cc_Enable_docs,
|
|
.def("Enable", static_cast<void (CryptoContextImpl<DCRTPoly>::*)(PKESchemeFeature)>(&CryptoContextImpl<DCRTPoly>::Enable), cc_Enable_docs,
|
|
py::arg("feature"))
|
|
py::arg("feature"))
|
|
.def("KeyGen", &CryptoContextImpl<DCRTPoly>::KeyGen, cc_KeyGen_docs)
|
|
.def("KeyGen", &CryptoContextImpl<DCRTPoly>::KeyGen, cc_KeyGen_docs)
|
|
@@ -546,6 +548,7 @@ void bind_crypto_context(py::module &m)
|
|
py::arg("ciphertext"),
|
|
py::arg("ciphertext"),
|
|
py::arg("numIterations") = 1,
|
|
py::arg("numIterations") = 1,
|
|
py::arg("precision") = 0)
|
|
py::arg("precision") = 0)
|
|
|
|
+ //TODO (Oliveira, R.): Solve pointer handling bug when returning EvalKeyMap objects for the next functions
|
|
.def("EvalAutomorphismKeyGen", &EvalAutomorphismKeyGenWrapper,
|
|
.def("EvalAutomorphismKeyGen", &EvalAutomorphismKeyGenWrapper,
|
|
cc_EvalAutomorphismKeyGen_docs,
|
|
cc_EvalAutomorphismKeyGen_docs,
|
|
py::arg("privateKey"),
|
|
py::arg("privateKey"),
|
|
@@ -592,7 +595,17 @@ void bind_crypto_context(py::module &m)
|
|
return res; },
|
|
return res; },
|
|
cc_SerializeEvalMultKey_docs,
|
|
cc_SerializeEvalMultKey_docs,
|
|
py::arg("filename"), py::arg("sertype"), py::arg("id") = "")
|
|
py::arg("filename"), py::arg("sertype"), py::arg("id") = "")
|
|
- .def_static(
|
|
|
|
|
|
+ .def_static( // SerializeEvalMultKey - JSON
|
|
|
|
+ "SerializeEvalMultKey", [](const std::string &filename, const SerType::SERJSON &sertype, std::string id = "")
|
|
|
|
+ {
|
|
|
|
+ std::ofstream outfile(filename,std::ios::out | std::ios::binary);
|
|
|
|
+ bool res;
|
|
|
|
+ res = CryptoContextImpl<DCRTPoly>::SerializeEvalMultKey<SerType::SERJSON>(outfile, sertype, id);
|
|
|
|
+ outfile.close();
|
|
|
|
+ return res; },
|
|
|
|
+ cc_SerializeEvalMultKey_docs,
|
|
|
|
+ py::arg("filename"), py::arg("sertype"), py::arg("id") = "")
|
|
|
|
+ .def_static( // SerializeEvalAutomorphismKey - Binary
|
|
"SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string id = "")
|
|
"SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string id = "")
|
|
{
|
|
{
|
|
std::ofstream outfile(filename,std::ios::out | std::ios::binary);
|
|
std::ofstream outfile(filename,std::ios::out | std::ios::binary);
|
|
@@ -602,29 +615,65 @@ void bind_crypto_context(py::module &m)
|
|
return res; },
|
|
return res; },
|
|
cc_SerializeEvalAutomorphismKey_docs,
|
|
cc_SerializeEvalAutomorphismKey_docs,
|
|
py::arg("filename"), py::arg("sertype"), py::arg("id") = "")
|
|
py::arg("filename"), py::arg("sertype"), py::arg("id") = "")
|
|
- .def_static("DeserializeEvalMultKey", [](std::shared_ptr<CryptoContextImpl<DCRTPoly>> &self, const std::string &filename, const SerType::SERBINARY &sertype)
|
|
|
|
|
|
+ .def_static( // SerializeEvalAutomorphismKey - JSON
|
|
|
|
+ "SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERJSON &sertype, std::string id = "")
|
|
|
|
+ {
|
|
|
|
+ std::ofstream outfile(filename,std::ios::out | std::ios::binary);
|
|
|
|
+ bool res;
|
|
|
|
+ res = CryptoContextImpl<DCRTPoly>::SerializeEvalAutomorphismKey<SerType::SERJSON>(outfile, sertype, id);
|
|
|
|
+ outfile.close();
|
|
|
|
+ return res; },
|
|
|
|
+ cc_SerializeEvalAutomorphismKey_docs,
|
|
|
|
+ py::arg("filename"), py::arg("sertype"), py::arg("id") = "")
|
|
|
|
+ .def_static("DeserializeEvalMultKey", // DeserializeEvalMultKey - Binary
|
|
|
|
+ [](const std::string &filename, const SerType::SERBINARY &sertype)
|
|
{
|
|
{
|
|
std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
|
|
std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
|
|
if (!emkeys.is_open()) {
|
|
if (!emkeys.is_open()) {
|
|
std::cerr << "I cannot read serialization from " << filename << std::endl;
|
|
std::cerr << "I cannot read serialization from " << filename << std::endl;
|
|
}
|
|
}
|
|
bool res;
|
|
bool res;
|
|
- res = self->DeserializeEvalMultKey<SerType::SERBINARY>(emkeys, sertype);
|
|
|
|
|
|
+ res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<SerType::SERBINARY>(emkeys, sertype);
|
|
|
|
+ return res;
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ cc_DeserializeEvalMultKey_docs,
|
|
|
|
+ py::arg("filename"), py::arg("sertype"))
|
|
|
|
+ .def_static("DeserializeEvalMultKey", // DeserializeEvalMultKey - JSON
|
|
|
|
+ [](const std::string &filename, const SerType::SERJSON &sertype)
|
|
|
|
+ {
|
|
|
|
+ std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
|
|
|
|
+ if (!emkeys.is_open()) {
|
|
|
|
+ std::cerr << "I cannot read serialization from " << filename << std::endl;
|
|
|
|
+ }
|
|
|
|
+ bool res;
|
|
|
|
+ res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<SerType::SERJSON>(emkeys, sertype);
|
|
return res; },
|
|
return res; },
|
|
cc_DeserializeEvalMultKey_docs,
|
|
cc_DeserializeEvalMultKey_docs,
|
|
- py::arg("self"),
|
|
|
|
py::arg("filename"), py::arg("sertype"))
|
|
py::arg("filename"), py::arg("sertype"))
|
|
- .def_static("DeserializeEvalAutomorphismKey", [](std::shared_ptr<CryptoContextImpl<DCRTPoly>> &self, const std::string &filename, const SerType::SERBINARY &sertype)
|
|
|
|
|
|
+ .def_static("DeserializeEvalAutomorphismKey", // DeserializeEvalAutomorphismKey - Binary
|
|
|
|
+ [](const std::string &filename, const SerType::SERBINARY &sertype)
|
|
{
|
|
{
|
|
std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
|
|
std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
|
|
if (!erkeys.is_open()) {
|
|
if (!erkeys.is_open()) {
|
|
std::cerr << "I cannot read serialization from " << filename << std::endl;
|
|
std::cerr << "I cannot read serialization from " << filename << std::endl;
|
|
}
|
|
}
|
|
bool res;
|
|
bool res;
|
|
- res = self->DeserializeEvalAutomorphismKey<SerType::SERBINARY>(erkeys, sertype);
|
|
|
|
|
|
+ res = CryptoContextImpl<DCRTPoly>::DeserializeEvalAutomorphismKey<SerType::SERBINARY>(erkeys, sertype);
|
|
|
|
+ return res; },
|
|
|
|
+ cc_DeserializeEvalAutomorphismKey_docs,
|
|
|
|
+ py::arg("filename"), py::arg("sertype"))
|
|
|
|
+ .def_static("DeserializeEvalAutomorphismKey", // DeserializeEvalAutomorphismKey - JSON
|
|
|
|
+ [](const std::string &filename, const SerType::SERJSON &sertype)
|
|
|
|
+ {
|
|
|
|
+ std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
|
|
|
|
+ if (!erkeys.is_open()) {
|
|
|
|
+ std::cerr << "I cannot read serialization from " << filename << std::endl;
|
|
|
|
+ }
|
|
|
|
+ bool res;
|
|
|
|
+ res = CryptoContextImpl<DCRTPoly>::DeserializeEvalAutomorphismKey<SerType::SERJSON>(erkeys, sertype);
|
|
return res; },
|
|
return res; },
|
|
cc_DeserializeEvalAutomorphismKey_docs,
|
|
cc_DeserializeEvalAutomorphismKey_docs,
|
|
- py::arg("self"),
|
|
|
|
py::arg("filename"), py::arg("sertype"));
|
|
py::arg("filename"), py::arg("sertype"));
|
|
|
|
|
|
// Generator Functions
|
|
// Generator Functions
|
|
@@ -635,6 +684,7 @@ void bind_crypto_context(py::module &m)
|
|
m.def("GenCryptoContext", &GenCryptoContext<CryptoContextCKKSRNS>,
|
|
m.def("GenCryptoContext", &GenCryptoContext<CryptoContextCKKSRNS>,
|
|
py::arg("params"));
|
|
py::arg("params"));
|
|
m.def("ReleaseAllContexts", &CryptoContextFactory<DCRTPoly>::ReleaseAllContexts);
|
|
m.def("ReleaseAllContexts", &CryptoContextFactory<DCRTPoly>::ReleaseAllContexts);
|
|
|
|
+ m.def("GetAllContexts", &CryptoContextFactory<DCRTPoly>::GetAllContexts);
|
|
}
|
|
}
|
|
|
|
|
|
int get_native_int(){
|
|
int get_native_int(){
|
|
@@ -789,6 +839,7 @@ void bind_enums_and_constants(py::module &m)
|
|
//NATIVEINT function
|
|
//NATIVEINT function
|
|
m.def("get_native_int", &get_native_int);
|
|
m.def("get_native_int", &get_native_int);
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
void bind_keys(py::module &m)
|
|
void bind_keys(py::module &m)
|
|
@@ -806,7 +857,7 @@ void bind_keys(py::module &m)
|
|
.def_readwrite("secretKey", &KeyPair<DCRTPoly>::secretKey)
|
|
.def_readwrite("secretKey", &KeyPair<DCRTPoly>::secretKey)
|
|
.def("good", &KeyPair<DCRTPoly>::good,kp_good_docs);
|
|
.def("good", &KeyPair<DCRTPoly>::good,kp_good_docs);
|
|
py::class_<EvalKeyImpl<DCRTPoly>, std::shared_ptr<EvalKeyImpl<DCRTPoly>>>(m, "EvalKey")
|
|
py::class_<EvalKeyImpl<DCRTPoly>, std::shared_ptr<EvalKeyImpl<DCRTPoly>>>(m, "EvalKey")
|
|
- .def(py::init<>())
|
|
|
|
|
|
+ .def(py::init<>())
|
|
.def("GetKeyTag", &EvalKeyImpl<DCRTPoly>::GetKeyTag)
|
|
.def("GetKeyTag", &EvalKeyImpl<DCRTPoly>::GetKeyTag)
|
|
.def("SetKeyTag", &EvalKeyImpl<DCRTPoly>::SetKeyTag);
|
|
.def("SetKeyTag", &EvalKeyImpl<DCRTPoly>::SetKeyTag);
|
|
py::class_<std::map<usint, EvalKey<DCRTPoly>>, std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>>>(m, "EvalKeyMap")
|
|
py::class_<std::map<usint, EvalKey<DCRTPoly>>, std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>>>(m, "EvalKeyMap")
|
|
@@ -865,7 +916,9 @@ void bind_ciphertext(py::module &m)
|
|
ctx_GetLevel_docs)
|
|
ctx_GetLevel_docs)
|
|
.def("SetLevel", &CiphertextImpl<DCRTPoly>::SetLevel,
|
|
.def("SetLevel", &CiphertextImpl<DCRTPoly>::SetLevel,
|
|
ctx_SetLevel_docs,
|
|
ctx_SetLevel_docs,
|
|
- py::arg("level"));
|
|
|
|
|
|
+ py::arg("level"))
|
|
|
|
+ .def("get_ptr",[](const Ciphertext<DCRTPoly> &self){
|
|
|
|
+ std::cout<< "cryptoparameters shared ptr (python)" << self->GetCryptoContext().get() << std::endl;});
|
|
// .def("GetHopLevel", &CiphertextImpl<DCRTPoly>::GetHopLevel)
|
|
// .def("GetHopLevel", &CiphertextImpl<DCRTPoly>::GetHopLevel)
|
|
// .def("SetHopLevel", &CiphertextImpl<DCRTPoly>::SetHopLevel)
|
|
// .def("SetHopLevel", &CiphertextImpl<DCRTPoly>::SetHopLevel)
|
|
// .def("GetScalingFactor", &CiphertextImpl<DCRTPoly>::GetScalingFactor)
|
|
// .def("GetScalingFactor", &CiphertextImpl<DCRTPoly>::GetScalingFactor)
|
|
@@ -903,4 +956,4 @@ PYBIND11_MODULE(openfhe, m)
|
|
bind_binfhe_context(m);
|
|
bind_binfhe_context(m);
|
|
bind_binfhe_keys(m);
|
|
bind_binfhe_keys(m);
|
|
bind_binfhe_ciphertext(m);
|
|
bind_binfhe_ciphertext(m);
|
|
-}
|
|
|
|
|
|
+}
|