|
42 | 42 | #include "key/key-ser.h" |
43 | 43 | #include "binfhe_bindings.h" |
44 | 44 |
|
45 | | -#include "cryptocontext_wrapper.h" |
46 | 45 | #include "cryptocontext_docs.h" |
47 | 46 | #include "cryptoparameters_docs.h" |
48 | 47 | #include "plaintext_docs.h" |
@@ -142,9 +141,6 @@ void bind_parameters(py::module &m, const std::string name) |
142 | 141 | stream << params; |
143 | 142 | return stream.str(); |
144 | 143 | }); |
145 | | - |
146 | | - // |
147 | | - |
148 | 144 | } |
149 | 145 |
|
150 | 146 | template <typename T> |
@@ -263,9 +259,29 @@ void bind_crypto_context(py::module &m) |
263 | 259 | .ConvertToDouble(); |
264 | 260 | }, |
265 | 261 | py::doc(cc_GetModulus_docs)) |
266 | | - .def("GetModulusCKKS", &GetModulusCKKSWrapper) |
267 | | - .def("GetScalingFactorReal", &GetScalingFactorRealWrapper, cc_GetScalingFactorReal_docs) |
268 | | - .def("GetScalingTechnique",&GetScalingTechniqueWrapper) |
| 262 | + .def("GetModulusCKKS", |
| 263 | + [](CryptoContext<DCRTPoly>& self) { |
| 264 | + auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersCKKSRNS>(self->GetCryptoParameters()); |
| 265 | + if (!cryptoParams) |
| 266 | + OPENFHE_THROW("std::dynamic_pointer_cast<CryptoParametersCKKSRNS>() failed"); |
| 267 | + return cryptoParams->GetElementParams()->GetParams()[0]->GetModulus().ConvertToInt<uint64_t>(); |
| 268 | + }) |
| 269 | + .def("GetScalingFactorReal", |
| 270 | + [](CryptoContext<DCRTPoly>& self, uint32_t level) { |
| 271 | + auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersRNS>(self->GetCryptoParameters()); |
| 272 | + if (!cryptoParams) |
| 273 | + OPENFHE_THROW("std::dynamic_pointer_cast<CryptoParametersRNS>() failed"); |
| 274 | + return cryptoParams->GetScalingFactorReal(level); |
| 275 | + }, |
| 276 | + py::arg("level"), |
| 277 | + py::doc(cc_GetScalingFactorReal_docs)) |
| 278 | + .def("GetScalingTechnique", |
| 279 | + [](CryptoContext<DCRTPoly>& self) { |
| 280 | + const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersRNS>(self->GetCryptoParameters()); |
| 281 | + if (!cryptoParams) |
| 282 | + OPENFHE_THROW("std::dynamic_pointer_cast<CryptoParametersRNS>() failed"); |
| 283 | + return cryptoParams->GetScalingTechnique(); |
| 284 | + }) |
269 | 285 | .def("GetDigitSize", |
270 | 286 | [](CryptoContext<DCRTPoly>& self) { |
271 | 287 | return self->GetCryptoParameters()->GetDigitSize(); |
@@ -368,7 +384,13 @@ void bind_crypto_context(py::module &m) |
368 | 384 | py::arg("ciphertext"), |
369 | 385 | py::arg("index"), |
370 | 386 | py::doc(cc_EvalRotate_docs)) |
371 | | - .def("EvalFastRotationPrecompute", &EvalFastRotationPrecomputeWrapper, |
| 387 | + .def("EvalFastRotationPrecompute", |
| 388 | + [](CryptoContext<DCRTPoly>& self, ConstCiphertext<DCRTPoly> ciphertext) { |
| 389 | + auto precomp = self->EvalFastRotationPrecompute(ciphertext); |
| 390 | + auto cipherdigits = std::make_shared<CiphertextImpl<DCRTPoly>>(self); |
| 391 | + cipherdigits->SetElements(*precomp); |
| 392 | + return cipherdigits; |
| 393 | + }, |
372 | 394 | py::arg("ciphertext"), |
373 | 395 | py::doc(cc_EvalFastRotationPreCompute_docs)) |
374 | 396 | .def("EvalFastRotation", |
@@ -704,8 +726,13 @@ void bind_crypto_context(py::module &m) |
704 | 726 | py::arg("ciphertextVec"), |
705 | 727 | py::arg("privateKey"), |
706 | 728 | py::doc(cc_MultipartyDecryptMain_docs)) |
707 | | - .def("MultipartyDecryptFusion", &MultipartyDecryptFusionWrapper, |
708 | | - py::arg("ciphertextVec"), |
| 729 | + .def("MultipartyDecryptFusion", |
| 730 | + [](CryptoContext<DCRTPoly>& self, const std::vector<Ciphertext<DCRTPoly>>& partialCiphertextVec) { |
| 731 | + Plaintext result; |
| 732 | + self->MultipartyDecryptFusion(partialCiphertextVec, &result); |
| 733 | + return result; |
| 734 | + }, |
| 735 | + py::arg("partialCiphertextVec"), |
709 | 736 | py::doc(cc_MultipartyDecryptFusion_docs)) |
710 | 737 | .def("MultiKeySwitchGen", &CryptoContextImpl<DCRTPoly>::MultiKeySwitchGen, |
711 | 738 | py::arg("originalPrivateKey"), |
@@ -962,7 +989,12 @@ void bind_crypto_context(py::module &m) |
962 | 989 | .def("FindAutomorphismIndices", &CryptoContextImpl<DCRTPoly>::FindAutomorphismIndices, |
963 | 990 | py::arg("idxList"), |
964 | 991 | py::doc(cc_FindAutomorphismIndices_docs)) |
965 | | - .def("GetEvalSumKeyMap", &GetEvalSumKeyMapWrapper, cc_GetEvalSumKeyMap_docs) |
| 992 | + .def("GetEvalSumKeyMap", |
| 993 | + [](CryptoContext<DCRTPoly>& self, const std::string& keyTag) { |
| 994 | + return std::make_shared<std::map<uint32_t, EvalKey<DCRTPoly>>>(CryptoContextImpl<DCRTPoly>::GetEvalSumKeyMap(keyTag)); |
| 995 | + }, |
| 996 | + py::arg("keyTag"), |
| 997 | + py::doc(cc_GetEvalSumKeyMap_docs)) |
966 | 998 | .def("GetBinCCForSchemeSwitch", &CryptoContextImpl<DCRTPoly>::GetBinCCForSchemeSwitch) |
967 | 999 | .def_static("InsertEvalSumKey", &CryptoContextImpl<DCRTPoly>::InsertEvalSumKey, |
968 | 1000 | py::arg("evalKeyMap"), |
@@ -1465,46 +1497,8 @@ void bind_ciphertext(py::module &m) { |
1465 | 1497 | }); |
1466 | 1498 | } |
1467 | 1499 |
|
1468 | | -// void bind_ciphertext(py::module &m) { |
1469 | | -// using CiphertextImplDCRT = CiphertextImpl<DCRTPoly>; |
1470 | | -// using CiphertextDCRT = Ciphertext<DCRTPoly>; // shared_ptr<CiphertextImpl<DCRTPoly>> |
1471 | | - |
1472 | | -// // Bind CiphertextImpl<DCRTPoly> and expose it to Python as "Ciphertext" |
1473 | | -// py::class_<CiphertextImplDCRT, std::shared_ptr<CiphertextImplDCRT>>(m, "Ciphertext") |
1474 | | -// .def(py::init<>()) |
1475 | | -// .def("__add__", [](const CiphertextDCRT &a, const CiphertextDCRT &b) { |
1476 | | -// return a + b; |
1477 | | -// }, |
1478 | | -// py::is_operator(), pybind11::keep_alive<0, 1>()) |
1479 | | -// .def("GetLevel", &CiphertextImplDCRT::GetLevel, ctx_GetLevel_docs) |
1480 | | -// .def("SetLevel", &CiphertextImplDCRT::SetLevel, py::doc(ctx_SetLevel_docs)) py::arg("level")) |
1481 | | -// .def("Clone", &CiphertextImplDCRT::Clone) |
1482 | | -// .def("RemoveElement", &RemoveElementWrapper, cc_RemoveElement_docs) |
1483 | | -// .def("GetSlots", &CiphertextImplDCRT::GetSlots) |
1484 | | -// .def("SetSlots", &CiphertextImplDCRT::SetSlots) |
1485 | | -// .def("GetNoiseScaleDeg", &CiphertextImplDCRT::GetNoiseScaleDeg) |
1486 | | -// .def("SetNoiseScaleDeg", &CiphertextImplDCRT::SetNoiseScaleDeg) |
1487 | | -// .def("GetCryptoContext", &CiphertextImplDCRT::GetCryptoContext) |
1488 | | -// .def("GetEncodingType", &CiphertextImplDCRT::GetEncodingType) |
1489 | | -// .def("GetElements", [](const CiphertextImplDCRT& self) -> const std::vector<DCRTPoly>& { |
1490 | | -// return self.GetElements(); |
1491 | | -// }, py::return_value_policy::reference_internal) |
1492 | | -// .def("GetElementsMutable", [](CiphertextImplDCRT& self) -> std::vector<DCRTPoly>& { |
1493 | | -// return self.GetElements(); |
1494 | | -// }, py::return_value_policy::reference_internal) |
1495 | | -// .def("SetElements", [](CiphertextImplDCRT& self, const std::vector<DCRTPoly>& elems) { |
1496 | | -// self.SetElements(elems); |
1497 | | -// }) |
1498 | | -// .def("SetElementsMove", [](CiphertextImplDCRT& self, std::vector<DCRTPoly>&& elems) { |
1499 | | -// self.SetElements(std::move(elems)); |
1500 | | -// }); |
1501 | | - |
1502 | | -// // Bind the shared_ptr alias (Ciphertext<DCRTPoly>) so it picks up the methods above |
1503 | | -// py::class_<CiphertextDCRT>(m, "_CiphertextAlias"); // hidden helper; not necessary for users |
1504 | | -// } |
1505 | | - |
1506 | 1500 | void bind_schemes(py::module &m){ |
1507 | | - /*Bind schemes specific functionalities like bootstrapping functions and multiparty*/ |
| 1501 | + // Bind schemes specific functionalities like bootstrapping functions and multiparty |
1508 | 1502 | py::class_<FHECKKSRNS>(m, "FHECKKSRNS") |
1509 | 1503 | .def(py::init<>()) |
1510 | 1504 | .def_static("GetBootstrapDepth", |
@@ -1568,15 +1562,15 @@ void bind_sch_swch_params(py::module &m) |
1568 | 1562 | }); |
1569 | 1563 | } |
1570 | 1564 |
|
1571 | | -PYBIND11_MODULE(openfhe, m) |
1572 | | -{ |
| 1565 | +PYBIND11_MODULE(openfhe, m) { |
| 1566 | + // sequence of function calls matters |
1573 | 1567 | m.doc() = "Open-Source Fully Homomorphic Encryption Library"; |
1574 | | - // binfhe library |
1575 | 1568 | bind_DCRTPoly(m); |
| 1569 | + // binfhe library |
1576 | 1570 | bind_binfhe_enums(m); |
1577 | | - bind_binfhe_context(m); |
1578 | | - bind_binfhe_keys(m); |
1579 | 1571 | bind_binfhe_ciphertext(m); |
| 1572 | + bind_binfhe_keys(m); |
| 1573 | + bind_binfhe_context(m); |
1580 | 1574 | // pke library |
1581 | 1575 | bind_enums_and_constants(m); |
1582 | 1576 | bind_parameters<CryptoContextBFVRNS>(m,"CCParamsBFVRNS"); |
|
0 commit comments