Skip to content

Commit 611395a

Browse files
Added more CryptoContext member functions
1 parent 526dc2d commit 611395a

File tree

4 files changed

+86
-16
lines changed

4 files changed

+86
-16
lines changed

src/include/docstrings/cryptocontext_docs.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,15 @@ const char* cc_MultiKeySwitchGen_docs = R"pbdoc(
932932
:rtype: EvalKey
933933
)pbdoc";
934934

935+
const char* cc_GetEvalAutomorphismKeyMap_docs = R"pbdoc(
936+
Get automorphism keys for a specific secret key tag
937+
938+
:param keyId: key identifier used for private key
939+
:type keyId: str
940+
:return: EvalKeyMap: map with all automorphism keys.
941+
:rtype: EvalKeyMap
942+
)pbdoc";
943+
935944
// TODO (Oliveira, R.) - Complete the following documentation
936945
const char* cc_GetEvalSumKeyMap_docs = R"pbdoc(
937946
Get a map of summation keys (each is composed of several automorphism keys) for a specific secret key tag
@@ -944,6 +953,22 @@ const char* cc_InsertEvalSumKey_docs = R"pbdoc(
944953
:param evalKeyMap: key map
945954
:type evalKeyMap: EvalKeyMap
946955
)pbdoc";
956+
957+
const char* cc_MultiEvalAtIndexKeyGen_docs = R"pbdoc(
958+
Threshold FHE: Generates joined rotation keys from the current secret key and prior joined rotation keys
959+
960+
:param privateKey: secret key share
961+
:type privateKey: PrivateKey
962+
:param evalKeyMap: a map with prior joined rotation keys
963+
:type evalKeyMap: EvalKeyMap
964+
:param indexList: a vector of rotation indices
965+
:type indexList: List[int32]
966+
:param keyId: new key identifier used for resulting evaluation key
967+
:type keyId: str
968+
:return: EvalKeyMap: new joined rotation keys
969+
:rtype: EvalKeyMap
970+
)pbdoc";
971+
947972
const char* cc_MultiEvalSumKeyGen_docs = R"pbdoc(
948973
Threshold FHE: Generates joined summation evaluation keys from the current secret share and prior joined summation keys
949974
@@ -957,6 +982,32 @@ const char* cc_MultiEvalSumKeyGen_docs = R"pbdoc(
957982
:rtype: EvalKeyMap
958983
)pbdoc";
959984

985+
const char* cc_MultiAddEvalAutomorphismKeys_docs = R"pbdoc(
986+
Threshold FHE: Adds two prior evaluation key sets for automorphisms
987+
988+
:param evalKeyMap1: first automorphism key set
989+
:type evalKeyMap1: EvalKeyMap
990+
:param evalKeyMap2: second automorphism key set
991+
:type evalKeyMap2: EvalKeyMap
992+
:param keyId: new key identifier used for resulting evaluation key
993+
:type keyId: str
994+
:return: the new joined key set for summation
995+
:rtype: evalKeyMap
996+
)pbdoc";
997+
998+
const char* cc_MultiAddPubKeys_docs = R"pbdoc(
999+
Threshold FHE: Adds two prior public keys
1000+
1001+
:param publicKey1: first public key
1002+
:type publicKey1: PublicKey
1003+
:param publicKey2: second public key
1004+
:type publicKey2: PublicKey
1005+
:param keyId: new key identifier used for the resulting key
1006+
:type keyId: str
1007+
:return: the new combined key
1008+
:rtype: PublicKey
1009+
)pbdoc";
1010+
9601011
const char* cc_MultiAddEvalKeys_docs = R"pbdoc(
9611012
Threshold FHE: Adds two prior evaluation keys
9621013
@@ -1279,7 +1330,7 @@ const char* cc_ClearEvalMultKeys_docs = R"pbdoc(
12791330
)pbdoc";
12801331

12811332
const char* cc_ClearEvalAutomorphismKeys_docs = R"pbdoc(
1282-
ClearEvalAutomorphismKeys - flush EvalAutomorphismKey cache
1333+
Flush EvalAutomorphismKey cache
12831334
)pbdoc";
12841335

12851336
const char* cc_SerializeEvalAutomorphismKey_docs = R"pbdoc(

src/include/pke/cryptocontext_wrapper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Plaintext DecryptWrapper(CryptoContext<DCRTPoly> &self,
5858
const PrivateKey<DCRTPoly> privateKey, ConstCiphertext<DCRTPoly> ciphertext);
5959
Plaintext MultipartyDecryptFusionWrapper(CryptoContext<DCRTPoly>& self,const std::vector<Ciphertext<DCRTPoly>>& partialCiphertextVec);
6060

61-
const std::map<usint, EvalKey<DCRTPoly>> EvalAutomorphismKeyGenWrapper(CryptoContext<DCRTPoly>& self,const PrivateKey<DCRTPoly> privateKey,const std::vector<usint> &indexList);
6261
const std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>> GetEvalSumKeyMapWrapper(CryptoContext<DCRTPoly>& self, const std::string &id);
6362
const PlaintextModulus GetPlaintextModulusWrapper(CryptoContext<DCRTPoly>& self);
6463
const double GetModulusWrapper(CryptoContext<DCRTPoly>& self);

src/lib/bindings.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,34 @@ void bind_crypto_context(py::module &m)
497497
py::arg("originalPrivateKey"),
498498
py::arg("newPrivateKey"),
499499
py::arg("evalKey"))
500+
.def("MultiEvalAtIndexKeyGen",
501+
[](CryptoContextImpl<DCRTPoly>* self,
502+
const PrivateKey<DCRTPoly>& privateKey,
503+
std::shared_ptr<std::map<unsigned int, EvalKey<DCRTPoly>>> evalKeyMap,
504+
const std::vector<int32_t>& indexList,
505+
const std::string& keyId) {
506+
return self->MultiEvalAtIndexKeyGen(privateKey, evalKeyMap, indexList, keyId);
507+
},
508+
cc_MultiEvalAtIndexKeyGen_docs,
509+
py::arg("privateKey"),
510+
py::arg("evalKeyMap"),
511+
py::arg("indexList"),
512+
py::arg("keyId") = "")
500513
.def("MultiEvalSumKeyGen", &CryptoContextImpl<DCRTPoly>::MultiEvalSumKeyGen,
501514
cc_MultiEvalSumKeyGen_docs,
502515
py::arg("privateKey"),
503516
py::arg("evalKeyMap"),
504517
py::arg("keyId") = "")
518+
.def("MultiAddEvalAutomorphismKeys", &CryptoContextImpl<DCRTPoly>::MultiAddEvalAutomorphismKeys,
519+
cc_MultiAddEvalAutomorphismKeys_docs,
520+
py::arg("evalKeyMap1"),
521+
py::arg("evalKeyMap1"),
522+
py::arg("keyId") = "")
523+
.def("MultiAddPubKeys", &CryptoContextImpl<DCRTPoly>::MultiAddPubKeys,
524+
cc_MultiAddPubKeys_docs,
525+
py::arg("publicKey1"),
526+
py::arg("publicKey2"),
527+
py::arg("keyId") = "")
505528
.def("MultiAddEvalKeys", &CryptoContextImpl<DCRTPoly>::MultiAddEvalKeys,
506529
cc_MultiAddEvalKeys_docs,
507530
py::arg("evalKey1"),
@@ -686,11 +709,12 @@ void bind_crypto_context(py::module &m)
686709
py::arg("pLWE") = 0,
687710
py::arg("scaleSign") = 1.0)
688711
//TODO (Oliveira, R.): Solve pointer handling bug when returning EvalKeyMap objects for the next functions
689-
.def("EvalAutomorphismKeyGen", &EvalAutomorphismKeyGenWrapper,
712+
.def("EvalAutomorphismKeyGen",
713+
static_cast<std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>> (CryptoContextImpl<DCRTPoly>::*)(const PrivateKey<DCRTPoly>, const std::vector<usint>&) const>
714+
(&CryptoContextImpl<DCRTPoly>::EvalAutomorphismKeyGen),
690715
cc_EvalAutomorphismKeyGen_docs,
691716
py::arg("privateKey"),
692-
py::arg("indexList"),
693-
py::return_value_policy::reference_internal)
717+
py::arg("indexList"))
694718
.def("EvalLinearWSumMutable",
695719
static_cast<lbcrypto::Ciphertext<DCRTPoly> (lbcrypto::CryptoContextImpl<DCRTPoly>::*)(
696720
const std::vector<double>&,
@@ -729,11 +753,13 @@ void bind_crypto_context(py::module &m)
729753
"ClearEvalAutomorphismKeys", []()
730754
{ CryptoContextImpl<DCRTPoly>::ClearEvalAutomorphismKeys(); },
731755
cc_ClearEvalAutomorphismKeys_docs)
732-
.def("GetEvalSumKeyMap", &GetEvalSumKeyMapWrapper,
733-
cc_GetEvalSumKeyMap_docs,
756+
.def_static("GetEvalAutomorphismKeyMap", &CryptoContextImpl<DCRTPoly>::GetEvalAutomorphismKeyMap,
757+
cc_GetEvalAutomorphismKeyMap_docs,
758+
py::arg("keyId") = "",
734759
py::return_value_policy::reference)
735-
.def("GetBinCCForSchemeSwitch", &CryptoContextImpl<DCRTPoly>::GetBinCCForSchemeSwitch,
736-
py::return_value_policy::reference_internal)
760+
.def("GetEvalSumKeyMap", &GetEvalSumKeyMapWrapper,
761+
cc_GetEvalSumKeyMap_docs)
762+
.def("GetBinCCForSchemeSwitch", &CryptoContextImpl<DCRTPoly>::GetBinCCForSchemeSwitch)
737763
.def_static(
738764
"SerializeEvalMultKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string id = "")
739765
{

src/lib/pke/cryptocontext_wrapper.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,8 @@ Plaintext MultipartyDecryptFusionWrapper(CryptoContext<DCRTPoly>& self,const std
7777
return plaintextDecResult;
7878
}
7979

80-
const std::map<usint, EvalKey<DCRTPoly>> EvalAutomorphismKeyGenWrapper(CryptoContext<DCRTPoly>& self,const PrivateKey<DCRTPoly> privateKey,const std::vector<usint> &indexList){
81-
return *(self->EvalAutomorphismKeyGen(privateKey, indexList));
82-
}
83-
8480
const std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>> GetEvalSumKeyMapWrapper(CryptoContext<DCRTPoly>& self,const std::string &id){
85-
auto evalSumKeyMap =
86-
std::make_shared<std::map<usint, EvalKey<DCRTPoly>>>(self->GetEvalSumKeyMap(id));
87-
return evalSumKeyMap;
81+
return std::make_shared<std::map<usint, EvalKey<DCRTPoly>>>(CryptoContextImpl<DCRTPoly>::GetEvalSumKeyMap(id));;
8882
}
8983

9084
const PlaintextModulus GetPlaintextModulusWrapper(CryptoContext<DCRTPoly>& self){

0 commit comments

Comments
 (0)