Skip to content

Commit d70f780

Browse files
Removed cryptocontext_wrapper.cpp
1 parent e101db1 commit d70f780

File tree

4 files changed

+49
-209
lines changed

4 files changed

+49
-209
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ pybind11_add_module(openfhe
7171
src/lib/binfhe_bindings.cpp
7272
src/lib/binfhe/binfhecontext_wrapper.cpp
7373
src/lib/pke/serialization.cpp
74-
src/lib/pke/cryptocontext_wrapper.cpp
7574
)
7675
### Python installation
7776
# Allow the user to specify the path to Python executable (if not provided, find it)

src/include/pke/cryptocontext_wrapper.h

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/lib/bindings.cpp

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "key/key-ser.h"
4343
#include "binfhe_bindings.h"
4444

45-
#include "cryptocontext_wrapper.h"
4645
#include "cryptocontext_docs.h"
4746
#include "cryptoparameters_docs.h"
4847
#include "plaintext_docs.h"
@@ -142,9 +141,6 @@ void bind_parameters(py::module &m, const std::string name)
142141
stream << params;
143142
return stream.str();
144143
});
145-
146-
//
147-
148144
}
149145

150146
template <typename T>
@@ -263,9 +259,29 @@ void bind_crypto_context(py::module &m)
263259
.ConvertToDouble();
264260
},
265261
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+
})
269285
.def("GetDigitSize",
270286
[](CryptoContext<DCRTPoly>& self) {
271287
return self->GetCryptoParameters()->GetDigitSize();
@@ -368,7 +384,13 @@ void bind_crypto_context(py::module &m)
368384
py::arg("ciphertext"),
369385
py::arg("index"),
370386
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+
},
372394
py::arg("ciphertext"),
373395
py::doc(cc_EvalFastRotationPreCompute_docs))
374396
.def("EvalFastRotation",
@@ -704,8 +726,13 @@ void bind_crypto_context(py::module &m)
704726
py::arg("ciphertextVec"),
705727
py::arg("privateKey"),
706728
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"),
709736
py::doc(cc_MultipartyDecryptFusion_docs))
710737
.def("MultiKeySwitchGen", &CryptoContextImpl<DCRTPoly>::MultiKeySwitchGen,
711738
py::arg("originalPrivateKey"),
@@ -962,7 +989,12 @@ void bind_crypto_context(py::module &m)
962989
.def("FindAutomorphismIndices", &CryptoContextImpl<DCRTPoly>::FindAutomorphismIndices,
963990
py::arg("idxList"),
964991
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))
966998
.def("GetBinCCForSchemeSwitch", &CryptoContextImpl<DCRTPoly>::GetBinCCForSchemeSwitch)
967999
.def_static("InsertEvalSumKey", &CryptoContextImpl<DCRTPoly>::InsertEvalSumKey,
9681000
py::arg("evalKeyMap"),
@@ -1465,46 +1497,8 @@ void bind_ciphertext(py::module &m) {
14651497
});
14661498
}
14671499

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-
15061500
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
15081502
py::class_<FHECKKSRNS>(m, "FHECKKSRNS")
15091503
.def(py::init<>())
15101504
.def_static("GetBootstrapDepth",
@@ -1568,15 +1562,15 @@ void bind_sch_swch_params(py::module &m)
15681562
});
15691563
}
15701564

1571-
PYBIND11_MODULE(openfhe, m)
1572-
{
1565+
PYBIND11_MODULE(openfhe, m) {
1566+
// sequence of function calls matters
15731567
m.doc() = "Open-Source Fully Homomorphic Encryption Library";
1574-
// binfhe library
15751568
bind_DCRTPoly(m);
1569+
// binfhe library
15761570
bind_binfhe_enums(m);
1577-
bind_binfhe_context(m);
1578-
bind_binfhe_keys(m);
15791571
bind_binfhe_ciphertext(m);
1572+
bind_binfhe_keys(m);
1573+
bind_binfhe_context(m);
15801574
// pke library
15811575
bind_enums_and_constants(m);
15821576
bind_parameters<CryptoContextBFVRNS>(m,"CCParamsBFVRNS");

src/lib/pke/cryptocontext_wrapper.cpp

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)