28 #ifndef LBCRYPTO_CRYPTO_CKKS_H 29 #define LBCRYPTO_CRYPTO_CKKS_H 37 #include "math/dftransfrm.h" 39 #include "utils/caller_info.h" 52 template <
class Element>
54 using ParmType =
typename Element::Params;
55 using IntType =
typename Element::Integer;
56 using DugType =
typename Element::DugType;
57 using DggType =
typename Element::DggType;
58 using TugType =
typename Element::TugType;
67 m_rsTechnique(APPROXRESCALE),
80 m_rsTechnique(APPROXRESCALE),
110 const PlaintextModulus &plaintextModulus,
111 float distributionParameter,
float assuranceMeasure,
112 float securityLevel, usint relinWindow, MODE mode,
113 int depth = 1,
int maxDepth = 2,
114 KeySwitchTechnique ksTech = BV,
115 RescalingTechnique rsTech = APPROXRESCALE)
120 distributionParameter, assuranceMeasure, securityLevel, relinWindow,
121 depth, maxDepth, mode) {
122 m_ksTechnique = ksTech;
123 m_rsTechnique = rsTech;
146 EncodingParams encodingParams,
147 float distributionParameter,
float assuranceMeasure,
148 float securityLevel, usint relinWindow, MODE mode,
149 int depth = 1,
int maxDepth = 2,
150 KeySwitchTechnique ksTech = BV,
151 RescalingTechnique rsTech = APPROXRESCALE)
153 params, encodingParams, distributionParameter, assuranceMeasure,
154 securityLevel, relinWindow, depth, maxDepth, mode) {
155 m_ksTechnique = ksTech;
156 m_rsTechnique = rsTech;
167 template <
class Archive>
168 void save(Archive &ar, std::uint32_t
const version)
const {
170 ar(cereal::make_nvp(
"ks", m_ksTechnique));
171 ar(cereal::make_nvp(
"rs", m_rsTechnique));
172 ar(cereal::make_nvp(
"dnum", m_numPartQ));
175 template <
class Archive>
176 void load(Archive &ar, std::uint32_t
const version) {
177 if (version > SerializedVersion()) {
179 "serialized object version " + std::to_string(version) +
180 " is from a later version of the library");
183 ar(cereal::make_nvp(
"ks", m_ksTechnique));
184 ar(cereal::make_nvp(
"rs", m_rsTechnique));
185 ar(cereal::make_nvp(
"dnum", m_numPartQ));
192 std::string SerializedObjectName()
const {
return "CKKSSchemeParameters"; }
193 static uint32_t SerializedVersion() {
return 1; }
204 uint32_t numLargeDigits = 0);
215 if (el ==
nullptr)
return false;
218 m_rsTechnique == el->GetRescalingTechnique() &&
219 m_ksTechnique == el->GetKeySwitchTechnique() &&
220 m_numPartQ == el->GetNumPartQ();
223 void PrintParameters(std::ostream &os)
const {
234 return m_QlQlInvModqlDivqlModq[i];
245 return m_QlQlInvModqlDivqlModqPrecon[i];
254 return m_qInvModq[i];
263 return m_qInvModqPrecon[i];
272 const shared_ptr<ILDCRTParams<BigInteger>>
GetParamsP()
const {
304 const vector<NativeInteger> &
GetPInvModq()
const {
return m_PInvModq; }
313 return m_PInvModqPrecon;
333 return m_PHatInvModpPrecon;
346 return m_LvlQHatInvModq[l];
355 return m_LvlQHatInvModqPrecon[l];
381 return m_LvlQHatModp[l];
393 const vector<NativeInteger> &
GetPModq()
const {
return m_PModq; }
401 return m_modqBarrettMu;
410 return m_modpBarrettMu;
419 return m_ksTechnique;
428 return m_rsTechnique;
441 if (m_rsTechnique == EXACTRESCALE) {
442 if (l >= m_scalingFactors.size()) {
445 "LPCryptoParametersCKKS::GetScalingFactorOfLevel - Cannot " 446 "return scaling factor of level " +
447 std::to_string(l) +
". Current settings have up to " +
448 std::to_string(m_scalingFactors.size()) +
449 " levels, starting from 0.");
452 return m_scalingFactors[l];
468 if (m_rsTechnique == EXACTRESCALE) {
469 return m_dmoduliQ[l];
482 return m_PartQHatModq;
493 uint32_t part)
const {
494 return m_paramsPartQ[part];
509 const shared_ptr<ILDCRTParams<BigInteger>> &GetParamsComplPartQ(
510 uint32_t numTowers, uint32_t digit)
const {
511 return m_paramsComplPartQ[numTowers][digit];
519 uint32_t GetNumberOfQPartitions()
const {
return m_paramsPartQ.size(); }
528 return m_PartQHatInvModq[part];
554 uint32_t sublvl)
const {
555 if (part < m_LvlPartQHatInvModq.size() &&
556 sublvl < m_LvlPartQHatInvModq[part].size())
557 return m_LvlPartQHatInvModq[part][sublvl];
560 "LPCryptoParametersCKKS::GetPartitionQHatInvModQTable - " 561 "index out of bounds.");
571 uint32_t part, uint32_t sublvl)
const {
572 if (part < m_LvlPartQHatInvModqPrecon.size() &&
573 sublvl < m_LvlPartQHatInvModqPrecon[part].size())
574 return m_LvlPartQHatInvModqPrecon[part][sublvl];
577 "LPCryptoParametersCKKS::" 578 "GetPartitionQHatInvModQPreconTable - index " 589 uint32_t part)
const {
590 if (lvl < m_LvlPartQHatModp.size() && part < m_LvlPartQHatModp[lvl].size())
591 return m_LvlPartQHatModp[lvl][part];
594 "LPCryptoParametersCKKS::GetPartitionQHatModPTable - " 595 "index out of bounds.");
605 uint32_t lvl, uint32_t part)
const {
606 if (lvl < m_modComplPartqBarrettMu.size() &&
607 part < m_modComplPartqBarrettMu[lvl].size())
608 return m_modComplPartqBarrettMu[lvl][part];
611 "LPCryptoParametersCKKS::GetPartitionPrecon - index out " 617 enum KeySwitchTechnique m_ksTechnique;
620 enum RescalingTechnique m_rsTechnique;
627 uint32_t m_numPerPartQ;
630 vector<BigInteger> m_moduliPartQ;
633 vector<shared_ptr<ILDCRTParams<BigInteger>>> m_paramsPartQ;
637 vector<vector<shared_ptr<ILDCRTParams<BigInteger>>>> m_paramsComplPartQ;
640 vector<vector<vector<DoubleNativeInt>>> m_modComplPartqBarrettMu;
643 vector<BigInteger> m_PartQHat;
646 vector<vector<NativeInteger>> m_PartQHatModq;
649 vector<vector<NativeInteger>> m_PartQHatInvModq;
652 vector<vector<vector<NativeInteger>>> m_LvlPartQHatInvModq;
655 vector<vector<vector<NativeInteger>>> m_LvlPartQHatInvModqPrecon;
658 vector<vector<vector<vector<NativeInteger>>>> m_LvlPartQHatModp;
662 std::vector<std::vector<NativeInteger>> m_QlQlInvModqlDivqlModq;
666 std::vector<std::vector<NativeInteger>> m_QlQlInvModqlDivqlModqPrecon;
669 std::vector<std::vector<NativeInteger>> m_qInvModq;
672 std::vector<std::vector<NativeInteger>> m_qInvModqPrecon;
676 shared_ptr<ILDCRTParams<BigInteger>> m_paramsP;
680 shared_ptr<ILDCRTParams<BigInteger>> m_paramsQP;
687 vector<NativeInteger> m_PModq;
690 vector<NativeInteger> m_PInvModq;
693 vector<NativeInteger> m_PInvModqPrecon;
696 vector<NativeInteger> m_PHatInvModp;
699 vector<NativeInteger> m_PHatInvModpPrecon;
703 vector<vector<NativeInteger>> m_LvlQHatInvModq;
706 vector<vector<NativeInteger>> m_LvlQHatInvModqPrecon;
709 vector<vector<NativeInteger>> m_PHatModq;
712 vector<vector<vector<NativeInteger>>> m_LvlQHatModp;
715 vector<DoubleNativeInt> m_modpBarrettMu;
718 vector<DoubleNativeInt> m_modqBarrettMu;
722 vector<double> m_scalingFactors;
725 vector<double> m_dmoduliQ;
734 template <
class Element>
760 int32_t evalAddCount = 0, int32_t evalMultCount = 0,
761 int32_t keySwitchCount = 0,
size_t dcrtBits = 0,
762 uint32_t n = 0)
const {
763 std::string errMsg =
"This ParamsGen method is not implemented for CKKS.";
784 usint cyclOrder, usint numPrimes, usint scaleExp,
785 usint relinWindow, MODE mode, KeySwitchTechnique ksTech = BV,
786 usint firstModSize = 60, RescalingTechnique = APPROXRESCALE,
787 uint32_t numLargeDigits = 4)
const;
791 template <
class Archive>
792 void save(Archive &ar)
const {
796 template <
class Archive>
797 void load(Archive &ar) {
801 std::string SerializedObjectName()
const {
return "CKKSParamsGen"; }
808 template <
class Element>
810 using ParmType =
typename Element::Params;
811 using IntType =
typename Element::Integer;
812 using DugType =
typename Element::DugType;
813 using DggType =
typename Element::DggType;
814 using TugType =
typename Element::TugType;
831 Ciphertext<Element> Encrypt(
const LPPublicKey<Element> publicKey,
832 Element plaintext)
const;
843 Ciphertext<Element> Encrypt(
const LPPrivateKey<Element> privateKey,
844 Element plaintext)
const;
854 DecryptResult Decrypt(
const LPPrivateKey<Element> privateKey,
855 ConstCiphertext<Element> ciphertext,
866 DecryptResult Decrypt(
const LPPrivateKey<Element> privateKey,
867 ConstCiphertext<Element> ciphertext,
868 Poly *plaintext)
const;
880 template <
class Archive>
881 void save(Archive &ar)
const {
885 template <
class Archive>
886 void load(Archive &ar) {
890 std::string SerializedObjectName()
const {
return "CKKSEncryption"; }
898 template <
class Element>
900 using ParmType =
typename Element::Params;
901 using IntType =
typename Element::Integer;
902 using DugType =
typename Element::DugType;
903 using DggType =
typename Element::DggType;
904 using TugType =
typename Element::TugType;
925 void EvalAddInPlace(Ciphertext<Element> &ciphertext1,
926 ConstCiphertext<Element> ciphertext2)
const override;
937 Ciphertext<Element> &ciphertext1,
938 Ciphertext<Element> &ciphertext2)
const override {
940 "LPAlgorithmSHECKKS::EvalAddMutable is only supported for DCRTPoly.";
951 Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext,
952 ConstPlaintext plaintext)
const override;
963 Plaintext plaintext)
const override {
965 "LPAlgorithmSHECKKS::EvalAddMutable is only supported for DCRTPoly.";
976 Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext,
977 double constant)
const override;
988 double constant)
const {
990 "LPAlgorithmSHECKKS::EvalAddMutable is only supported for DCRTPoly.";
1004 vector<double> constants)
const override {
1005 std::string errMsg =
1006 "LPAlgorithmSHECKKS::EvalLinearWSum is only supported for DCRTPoly.";
1020 vector<Ciphertext<Element>> ciphertexts,
1021 vector<double> constants)
const override {
1022 std::string errMsg =
1023 "LPAlgorithmSHECKKS::EvalLinearWSumMutable is only supported for " 1035 Ciphertext<Element> EvalSub(
1036 ConstCiphertext<Element> ciphertext1,
1037 ConstCiphertext<Element> ciphertext2)
const override;
1048 Ciphertext<Element> &ciphertext1,
1049 Ciphertext<Element> &ciphertext2)
const override {
1050 std::string errMsg =
1051 "LPAlgorithmSHECKKS::EvalSubMutable is only supported for DCRTPoly.";
1062 Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext1,
1063 ConstPlaintext plaintext)
const override;
1074 Plaintext plaintext)
const override {
1075 std::string errMsg =
1076 "LPAlgorithmSHECKKS::EvalSubMutable is only supported for DCRTPoly.";
1087 Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext,
1088 double constant)
const override;
1099 double constant)
const {
1100 std::string errMsg =
1101 "LPAlgorithmSHECKKS::EvalSubMutable is only supported for DCRTPoly.";
1115 Ciphertext<Element> EvalMult(
1116 ConstCiphertext<Element> ciphertext1,
1117 ConstCiphertext<Element> ciphertext2)
const override;
1129 Ciphertext<Element> &ciphertext1,
1130 Ciphertext<Element> &ciphertext2)
const override {
1131 std::string errMsg =
1132 "LPAlgorithmSHECKKS::EvalMultMutable is only supported for DCRTPoly.";
1143 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext,
1144 ConstPlaintext plaintext)
const override;
1155 Plaintext plaintext)
const override {
1156 std::string errMsg =
1157 "LPAlgorithmSHECKKS::EvalMultMutable is only supported for DCRTPoly.";
1168 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext,
1169 double constant)
const override;
1180 double constant)
const override {
1181 std::string errMsg =
1182 "LPAlgorithmSHECKKS::EvalMultMutable is only supported for DCRTPoly.";
1198 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext1,
1199 ConstCiphertext<Element> ciphertext2,
1200 const LPEvalKey<Element> ek)
const override;
1213 Ciphertext<Element> EvalMultMutable(
1214 Ciphertext<Element> &ciphertext1, Ciphertext<Element> &ciphertext2,
1215 const LPEvalKey<Element> ek)
const override;
1228 ConstCiphertext<Element> ciphertext1,
1229 ConstCiphertext<Element> ciphertext2,
1230 const vector<LPEvalKey<Element>> &ek)
const override {
1231 std::string errMsg =
1232 "LPAlgorithmSHECKKS::EvalMultAndRelinearize is not implemented for " 1246 ConstCiphertext<Element> ciphertext,
1247 const vector<LPEvalKey<Element>> &ek)
const override {
1248 std::string errMsg =
1249 "LPAlgorithmSHECKKS::Relinearize is not implemented for the non " 1250 "Double-CRT variant of the CKKS Scheme.";
1262 Ciphertext<Element> &ciphertext,
1263 const vector<LPEvalKey<Element>> &ek)
const override {
1264 std::string errMsg =
1265 "LPAlgorithmSHECKKS::RelinearizeInPlace is not implemented for the non " 1266 "Double-CRT variant of the CKKS Scheme.";
1276 Ciphertext<Element> EvalNegate(ConstCiphertext<Element> ct)
const override;
1289 const LPPrivateKey<Element> oldKey,
const LPPrivateKey<Element> newKey,
1290 const LPEvalKey<DCRTPoly> ek =
nullptr)
const {
1291 std::string errMsg =
1292 "LPAlgorithmSHECKKS::KeySwitchHybridGen is not implemented for the " 1294 "Double-CRT variant of the CKKS Scheme.";
1306 Ciphertext<Element> &ciphertext)
const {
1307 std::string errMsg =
1308 "LPAlgorithmSHECKKS::KeySwitchHybridInPlace is not implemented for the " 1309 "non Double-CRT variant of the CKKS Scheme.";
1325 LPEvalKey<Element> KeySwitchGHSGen(
1326 const LPPrivateKey<DCRTPoly> oldKey,
const LPPrivateKey<DCRTPoly> newKey,
1327 const LPEvalKey<DCRTPoly> ek =
nullptr)
const;
1339 void KeySwitchGHSInPlace(
const LPEvalKey<Element> keySwitchHint,
1340 Ciphertext<Element> &ciphertext)
const;
1354 LPEvalKey<Element> KeySwitchBVGen(
1355 const LPPrivateKey<Element> oldKey,
const LPPrivateKey<Element> newKey,
1356 const LPEvalKey<DCRTPoly> ek =
nullptr)
const;
1367 void KeySwitchBVInPlace(
const LPEvalKey<Element> keySwitchHint,
1368 Ciphertext<Element> &ciphertext)
const;
1377 LPEvalKey<Element> KeySwitchGen(
1378 const LPPrivateKey<Element> oldKey,
1379 const LPPrivateKey<Element> newKey)
const override;
1388 void KeySwitchInPlace(
const LPEvalKey<Element> keySwitchHint,
1389 Ciphertext<Element> &ciphertext)
const override;
1398 LPEvalKey<Element> EvalMultKeyGen(
1399 const LPPrivateKey<Element> privateKey)
const override;
1409 vector<LPEvalKey<Element>> EvalMultKeysGen(
1410 const LPPrivateKey<Element> privateKey)
const override;
1421 Ciphertext<Element> EvalAutomorphism(
1422 ConstCiphertext<Element> ciphertext, usint i,
1423 const std::map<usint, LPEvalKey<Element>> &evalKeys,
1424 CALLER_INFO_ARGS_HDR)
const override;
1434 shared_ptr<std::map<usint, LPEvalKey<Element>>> EvalAutomorphismKeyGen(
1435 const LPPrivateKey<Element> privateKey,
1436 const std::vector<usint> &indexList)
const override;
1448 const LPPublicKey<Element> publicKey,
1449 const LPPrivateKey<Element> privateKey,
1450 const std::vector<usint> &indexList)
const override {
1451 std::string errMsg =
1452 "LPAlgorithmSHECKKS::EvalAutomorphismKeyGen is not implemented for " 1464 shared_ptr<vector<Element>> EvalFastRotationPrecompute(
1465 ConstCiphertext<Element> ciphertext)
const override;
1480 Ciphertext<Element> EvalFastRotation(
1481 ConstCiphertext<Element> ciphertext,
const usint index,
const usint m,
1482 const shared_ptr<vector<Element>> precomp)
const override;
1550 Ciphertext<Element> &ciphertext, uint32_t targetLevel)
const override {
1551 std::string errMsg =
1552 "LPAlgorithmSHECKKS::AdjustLevelWithoutRescale is not implemented " 1554 "the non Double-CRT variant of the CKKS Scheme.";
1576 uint32_t targetLevel)
const {
1577 std::string errMsg =
1578 "LPAlgorithmSHECKKS::AdjustLevelWithoutRescale is not implemented " 1580 "the non Double-CRT variant of the CKKS Scheme.";
1594 ConstCiphertext<DCRTPoly> ciphertext, ConstPlaintext plaintext)
const {
1595 std::string errMsg =
1596 "LPAlgorithmSHECKKS::EvalMultApprox with plaintext is only supported " 1611 Ciphertext<Element> EvalAddCorePlaintext(ConstCiphertext<Element> ciphertext,
1613 usint ptDepth)
const;
1625 Ciphertext<Element> EvalSubCorePlaintext(ConstCiphertext<Element> ciphertext,
1627 usint ptDepth)
const;
1637 std::pair<shared_ptr<ConstCiphertext<Element>>, Element> AutomaticLevelReduce(
1638 ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext)
const;
1668 shared_ptr<vector<Element>> EvalFastRotationPrecomputeBV(
1669 ConstCiphertext<Element> ciphertext)
const;
1710 Ciphertext<Element> EvalFastRotationBV(
1711 ConstCiphertext<Element> ciphertext,
const usint index,
const usint m,
1712 const shared_ptr<vector<Element>> digits,
1713 LPEvalKey<DCRTPoly> evalKey)
const;
1730 shared_ptr<vector<Element>> EvalFastRotationPrecomputeGHS(
1731 ConstCiphertext<Element> ciphertext)
const;
1752 Ciphertext<Element> EvalFastRotationGHS(
1753 ConstCiphertext<Element> ciphertext,
const usint index,
const usint m,
1754 const shared_ptr<vector<Element>> expandedCiphertext,
1755 LPEvalKey<DCRTPoly> evalKey)
const;
1770 shared_ptr<vector<Element>> EvalFastRotationPrecomputeHybrid(
1771 ConstCiphertext<Element> ciphertext)
const;
1790 Ciphertext<Element> EvalFastRotationHybrid(
1791 ConstCiphertext<Element> ciphertext,
const usint index,
const usint m,
1792 const shared_ptr<vector<Element>> expandedCiphertext,
1793 LPEvalKey<DCRTPoly> evalKey)
const;
1805 Ciphertext<Element> EvalAddCore(ConstCiphertext<Element> ciphertext1,
1806 ConstCiphertext<Element> ciphertext2)
const;
1818 void EvalAddCoreInPlace(Ciphertext<Element> &ciphertext1,
1819 ConstCiphertext<Element> ciphertext2)
const;
1829 virtual Ciphertext<Element> EvalAddApprox(
1830 ConstCiphertext<Element> ciphertext1,
1831 ConstCiphertext<Element> ciphertext2)
const {
1832 std::string errMsg =
1833 "LPAlgorithmSHECKKS::EvalAddApprox is only supported for DCRTPoly.";
1845 virtual void EvalAddApproxInPlace(
1846 Ciphertext<Element> &ciphertext1,
1847 ConstCiphertext<Element> ciphertext2)
const {
1848 std::string errMsg =
1849 "LPAlgorithmSHECKKS::EvalAddApproxInPlace is only supported for " 1863 Ciphertext<Element> EvalSubCore(ConstCiphertext<Element> ciphertext1,
1864 ConstCiphertext<Element> ciphertext2)
const;
1874 Ciphertext<Element> EvalSubApprox(ConstCiphertext<Element> ciphertext1,
1875 ConstCiphertext<Element> ciphertext2)
const;
1886 Ciphertext<Element> EvalMultCore(ConstCiphertext<Element> ciphertext1,
1887 ConstCiphertext<Element> ciphertext2)
const;
1897 virtual Ciphertext<Element> EvalMultApprox(
1898 ConstCiphertext<Element> ciphertext1,
1899 ConstCiphertext<Element> ciphertext2)
const {
1900 std::string errMsg =
1901 "LPAlgorithmSHECKKS::EvalMultApprox is only supported for DCRTPoly.";
1913 virtual Ciphertext<Element> EvalMultApprox(
1914 ConstCiphertext<Element> ciphertext,
double constant)
const;
1923 vector<shared_ptr<ConstCiphertext<Element>>> AutomaticLevelReduce(
1924 ConstCiphertext<Element> ciphertext1,
1925 ConstCiphertext<Element> ciphertext2)
const;
1935 void AutomaticLevelReduceInPlace(Ciphertext<Element> &ciphertext1,
1936 ConstCiphertext<Element> ciphertext2)
const;
1947 Ciphertext<DCRTPoly> EvalLinearWSumInternalMutable(
1948 vector<Ciphertext<DCRTPoly>> ciphertexts, vector<double> constants)
const;
1957 std::vector<DCRTPoly::Integer> GetElementForEvalAddOrSub(
1958 ConstCiphertext<DCRTPoly> ciphertext,
double constant)
const;
1961 template <
class Archive>
1962 void save(Archive &ar)
const {
1966 template <
class Archive>
1967 void load(Archive &ar) {
1971 std::string SerializedObjectName()
const {
return "CKKSSHE"; }
1977 Ciphertext<DCRTPoly>& ciphertext, uint32_t targetLevel)
const;
1980 Ciphertext<DCRTPoly>& ciphertext, uint32_t targetLevel)
const;
1983 ConstCiphertext<DCRTPoly> ciphertext1, ConstCiphertext<DCRTPoly> ciphertext2)
const;
1986 Ciphertext<DCRTPoly>& ciphertext1, ConstCiphertext<DCRTPoly> ciphertext2)
const;
1989 Ciphertext<DCRTPoly>& ciphertext1, Ciphertext<DCRTPoly>& ciphertext2)
const;
1992 Ciphertext<DCRTPoly>& ciphertext, Plaintext plaintext)
const;
1995 vector<Ciphertext<DCRTPoly>> ciphertexts, vector<double> constants)
const;
1998 vector<Ciphertext<DCRTPoly>> ciphertexts, vector<double> constants)
const;
2001 vector<Ciphertext<DCRTPoly>> ciphertexts, vector<double> constants)
const;
2004 vector<Ciphertext<DCRTPoly>> ciphertexts, vector<double> constants)
const;
2007 ConstCiphertext<DCRTPoly> ciphertext1, ConstCiphertext<DCRTPoly> ciphertext2,
const vector<LPEvalKey<DCRTPoly>>& ek)
const;
2010 ConstCiphertext<DCRTPoly> ciphertext1, ConstCiphertext<DCRTPoly> ciphertext2)
const;
2013 ConstCiphertext<DCRTPoly> ciphertext, ConstPlaintext plaintext)
const;
2016 ConstCiphertext<DCRTPoly> ciphertext,
double constant)
const;
2019 Ciphertext<DCRTPoly>& ciphertext,
double constant)
const;
2022 Ciphertext<DCRTPoly>& ciphertext1, Ciphertext<DCRTPoly>& ciphertext2)
const;
2025 Ciphertext<DCRTPoly>& ciphertext, Plaintext plaintext)
const;
2028 Ciphertext<DCRTPoly>& ciphertext1, Ciphertext<DCRTPoly>& ciphertext2)
const;
2031 Ciphertext<DCRTPoly>& ciphertext, Plaintext plaintext)
const;
2034 const LPPrivateKey<DCRTPoly> oldKey,
const LPPrivateKey<DCRTPoly> newKey,
const LPEvalKey<DCRTPoly> ekPrev)
const;
2037 const LPEvalKey<DCRTPoly> ek, Ciphertext<DCRTPoly>& ciphertext)
const;
2040 ConstCiphertext<DCRTPoly> ciphertext,
const vector<LPEvalKey<DCRTPoly>>& ek)
const;
2043 Ciphertext<DCRTPoly>& ciphertext,
const vector<LPEvalKey<DCRTPoly>>& ek)
const;
2070 template <
class Element>
2072 using ParmType =
typename Element::Params;
2073 using IntType =
typename Element::Integer;
2074 using DugType =
typename Element::DugType;
2075 using DggType =
typename Element::DggType;
2076 using TugType =
typename Element::TugType;
2094 LPEvalKey<Element> ReKeyGen(
const LPPrivateKey<Element> newKey,
2095 const LPPrivateKey<Element> oldKey)
const;
2123 LPEvalKey<Element> ReKeyGen(
const LPPublicKey<Element> newKey,
2124 const LPPrivateKey<Element> oldKey)
const;
2152 Ciphertext<Element> ReEncrypt(
2153 const LPEvalKey<Element> EK, ConstCiphertext<Element> ciphertext,
2154 const LPPublicKey<Element> publicKey =
nullptr)
const;
2170 LPEvalKey<Element> ReKeyGenBV(
const LPPublicKey<Element> newKey,
2171 const LPPrivateKey<Element> oldKey)
const;
2186 LPEvalKey<Element> ReKeyGenGHS(
const LPPublicKey<Element> newKey,
2187 const LPPrivateKey<Element> oldKey)
const;
2190 template <
class Archive>
2191 void save(Archive &ar)
const {
2195 template <
class Archive>
2196 void load(Archive &ar) {
2200 std::string SerializedObjectName()
const {
return "CKKSPRE"; }
2229 template <
class Element>
2231 using ParmType =
typename Element::Params;
2232 using IntType =
typename Element::Integer;
2233 using DugType =
typename Element::DugType;
2234 using DggType =
typename Element::DggType;
2235 using TugType =
typename Element::TugType;
2258 const LPPublicKey<Element> pk1,
2259 bool makeSparse =
false,
2260 bool fresh =
false);
2274 CryptoContext<Element> cc,
2275 const vector<LPPrivateKey<Element>> &secretKeys,
bool makeSparse =
false);
2284 Ciphertext<Element> MultipartyDecryptMain(
2285 const LPPrivateKey<Element> privateKey,
2286 ConstCiphertext<Element> ciphertext)
const;
2295 Ciphertext<Element> MultipartyDecryptLead(
2296 const LPPrivateKey<Element> privateKey,
2297 ConstCiphertext<Element> ciphertext)
const;
2308 const vector<Ciphertext<Element>> &ciphertextVec,
2320 const vector<Ciphertext<Element>> &ciphertextVec,
Poly *plaintext)
const;
2332 LPEvalKey<Element> MultiKeySwitchGen(
2333 const LPPrivateKey<Element> originalPrivateKey,
2334 const LPPrivateKey<Element> newPrivateKey,
2335 const LPEvalKey<Element> ek)
const;
2347 shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalAutomorphismKeyGen(
2348 const LPPrivateKey<Element> privateKey,
2349 const shared_ptr<std::map<usint, LPEvalKey<Element>>> eAuto,
2350 const std::vector<usint> &indexList)
const;
2361 shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalSumKeyGen(
2362 const LPPrivateKey<Element> privateKey,
2363 const shared_ptr<std::map<usint, LPEvalKey<Element>>> eSum)
const;
2374 LPEvalKey<Element> MultiMultEvalKey(LPEvalKey<Element> evalKey,
2375 LPPrivateKey<Element> sk)
const;
2377 template <
class Archive>
2378 void save(Archive &ar)
const {
2382 template <
class Archive>
2383 void load(Archive &ar) {
2387 std::string SerializedObjectName()
const {
return "CKKSMultiparty"; }
2403 template <
class Element>
2405 using ParmType =
typename Element::Params;
2406 using IntType =
typename Element::Integer;
2407 using DugType =
typename Element::DugType;
2408 using DggType =
typename Element::DggType;
2409 using TugType =
typename Element::TugType;
2432 void ModReduceInPlace(Ciphertext<Element> &ciphertext,
2433 size_t levels = 1)
const override;
2441 Ciphertext<Element> ModReduceInternal(ConstCiphertext<Element> ciphertext,
2442 size_t levels = 1)
const override;
2444 void ModReduceInternalInPlace(Ciphertext<Element> &ciphertext,
2445 size_t levels = 1)
const override;
2454 Ciphertext<Element> Compress(ConstCiphertext<Element> ciphertext,
2455 size_t towersLeft = 1)
const override;
2470 ConstCiphertext<Element> cipherText1,
2471 ConstCiphertext<Element> cipherText2,
2472 const LPEvalKey<Element> quadKeySwitchHint)
const override {
2473 std::string errMsg =
2474 "LPLeveledSHEAlgorithmCKKS::ComposedEvalMult is not currently " 2477 "the CKKS/CKKS Scheme.";
2492 Ciphertext<Element> LevelReduce(ConstCiphertext<Element> ciphertext,
2493 const LPEvalKey<Element> linearKeySwitchHint,
2494 size_t levels)
const override;
2506 Ciphertext<Element> LevelReduceInternal(
2507 ConstCiphertext<Element> ciphertext,
2508 const LPEvalKey<Element> linearKeySwitchHint,
2509 size_t levels)
const override;
2521 void LevelReduceInternalInPlace(Ciphertext<Element> &ciphertext,
2522 const LPEvalKey<Element> linearKeySwitchHint,
2523 size_t levels)
const override;
2535 ConstCiphertext<Element> cipherText,
2536 const std::vector<double> &coefficients)
const override {
2537 std::string errMsg =
2538 "LPLeveledSHEAlgorithmCKKS::EvalPoly is only supported for DCRTPoly.";
2542 template <
class Archive>
2543 void save(Archive &ar)
const {
2547 template <
class Archive>
2548 void load(Archive &ar) {
2552 std::string SerializedObjectName()
const {
return "CKKSLeveledSHE"; }
2559 template <
class Element>
2564 this->m_algorithmParamsGen =
2565 std::make_shared<LPAlgorithmParamsGenCKKS<Element>>();
2573 void Enable(PKESchemeFeature feature);
2575 template <
class Archive>
2576 void save(Archive &ar, std::uint32_t
const version)
const {
2580 template <
class Archive>
2581 void load(Archive &ar, std::uint32_t
const version) {
2585 std::string SerializedObjectName()
const {
return "CKKSScheme"; }
const vector< NativeInteger > & GetPInvModq() const
Definition: ckks.h:304
const vector< NativeInteger > & GetPartQlHatInvModqPrecon(uint32_t part, uint32_t sublvl) const
Definition: ckks.h:570
const vector< NativeInteger > & GetQlHatInvModqPrecon(uint32_t l) const
Definition: ckks.h:354
Ciphertext< Element > EvalMultMutable(Ciphertext< Element > &ciphertext, double constant) const override
Definition: ckks.h:1179
Ciphertext< Element > EvalMultMutable(Ciphertext< Element > &ciphertext1, Ciphertext< Element > &ciphertext2) const override
Definition: ckks.h:1128
const vector< DoubleNativeInt > & GetModqBarrettMu() const
Definition: ckks.h:400
Ciphertext< Element > EvalSubMutable(Ciphertext< Element > &ciphertext1, Plaintext plaintext) const override
Definition: ckks.h:1073
const vector< NativeInteger > & GetPModq() const
Definition: ckks.h:393
Abstract interface for parameter generation algorithm.
Definition: pubkeylp.h:899
PRE scheme based on CKKS. The basic scheme is described here:
Definition: ckks.h:2071
shared_ptr< std::map< usint, LPEvalKey< Element > > > EvalAutomorphismKeyGen(const LPPublicKey< Element > publicKey, const LPPrivateKey< Element > privateKey, const std::vector< usint > &indexList) const override
Definition: ckks.h:1447
The multiparty homomorphic encryption capability for the CKKS scheme. A version of this multiparty sc...
Definition: ckks.h:2230
Ciphertext< Element > EvalLinearWSumMutable(vector< Ciphertext< Element >> ciphertexts, vector< double > constants) const override
Definition: ckks.h:1019
double GetModReduceFactor(uint32_t l=0) const
Definition: ckks.h:467
uint32_t GetNumPartQ() const
Definition: ckks.h:536
Decryption result. This represents whether the decryption of a cipheretext was performed correctly...
Definition: pubkeylp.h:105
Ciphertext< Element > Relinearize(ConstCiphertext< Element > ciphertext, const vector< LPEvalKey< Element >> &ek) const override
Definition: ckks.h:1245
enum KeySwitchTechnique GetKeySwitchTechnique() const
Definition: ckks.h:418
const vector< vector< NativeInteger > > & GetPartQHatModq() const
Definition: ckks.h:481
Ciphertext< Element > AdjustLevelWithRescale(Ciphertext< Element > &ciphertext, uint32_t targetLevel) const override
Definition: ckks.h:1549
Ciphertext< Element > EvalLinearWSum(vector< Ciphertext< Element >> ciphertexts, vector< double > constants) const override
Definition: ckks.h:1003
const vector< NativeInteger > & GetQlHatInvModq(uint32_t l) const
Definition: ckks.h:345
Concrete feature class for Leveled SHECKKS operations. This class adds leveled (CKKS scheme) features...
Definition: ckks.h:2404
Ciphertext< Element > EvalPoly(ConstCiphertext< Element > cipherText, const std::vector< double > &coefficients) const override
Definition: ckks.h:2534
Template for crypto parameters.
Definition: rlwe.h:47
Definition: stl_allocator.h:124
All parameters for plaintext encodings into ciphertext space.
Definition: encodingparams.h:44
LPAlgorithmPRECKKS()
Definition: ckks.h:2082
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: rlwe.h:284
Abstract interface class for LBC Multiparty algorithms based on threshold FHE. A version of this mult...
Definition: pubkeylp.h:1299
LPEvalKey< Element > KeySwitchHybridGen(const LPPrivateKey< Element > oldKey, const LPPrivateKey< Element > newKey, const LPEvalKey< DCRTPoly > ek=nullptr) const
Definition: ckks.h:1288
Ciphertext< Element > EvalMultAndRelinearize(ConstCiphertext< Element > ciphertext1, ConstCiphertext< Element > ciphertext2, const vector< LPEvalKey< Element >> &ek) const override
Definition: ckks.h:1227
Definition: exception.h:119
LPAlgorithmMultipartyCKKS()
Definition: ckks.h:2241
const vector< NativeInteger > & GetPInvModqPrecon() const
Definition: ckks.h:312
const vector< vector< NativeInteger > > & GetQlHatModp(uint32_t l) const
Definition: ckks.h:380
LPAlgorithmParamsGenCKKS()
Definition: ckks.h:741
virtual Ciphertext< Element > EvalSubMutable(Ciphertext< Element > &ciphertext, double constant) const
Definition: ckks.h:1098
Definition: exception.h:147
Definition: exception.h:113
const std::vector< NativeInteger > & GetqInvModq(size_t i) const
Definition: ckks.h:253
LPLeveledSHEAlgorithmCKKS()
Definition: ckks.h:2415
const vector< vector< NativeInteger > > & GetPartQlHatModp(uint32_t lvl, uint32_t part) const
Definition: ckks.h:588
Abstract interface for encryption algorithm.
Definition: pubkeylp.h:1016
virtual Ciphertext< DCRTPoly > EvalMultApprox(ConstCiphertext< DCRTPoly > ciphertext, ConstPlaintext plaintext) const
Definition: ckks.h:1593
const shared_ptr< ILDCRTParams< BigInteger > > GetParamsQP() const
Definition: ckks.h:291
const std::vector< NativeInteger > & GetQlQlInvModqlDivqlModq(size_t i) const
Definition: ckks.h:233
const BigInteger & GetAuxModulus() const
Definition: ckks.h:282
bool SERIALIZE_PRECOMPUTE
Definition: cryptocontext.cpp:30
Ciphertext< Element > AdjustLevelWithoutRescale(Ciphertext< Element > &ciphertext, uint32_t targetLevel) const
Definition: ckks.h:1575
LPCryptoParametersCKKS(const LPCryptoParametersCKKS &rhs)
Definition: ckks.h:77
Ciphertext< Element > EvalAddMutable(Ciphertext< Element > &ciphertext1, Ciphertext< Element > &ciphertext2) const override
Definition: ckks.h:936
void KeySwitchHybridInPlace(const LPEvalKey< Element > keySwitchHint, Ciphertext< Element > &ciphertext) const
Definition: ckks.h:1305
Parameter generation for CKKS.
Definition: ckks.h:735
Main class for big integers represented as an array of native (primitive) unsigned integers...
Definition: ubintfxd.h:219
Ciphertext< Element > EvalSubMutable(Ciphertext< Element > &ciphertext1, Ciphertext< Element > &ciphertext2) const override
Definition: ckks.h:1047
virtual Ciphertext< Element > EvalAddMutable(Ciphertext< Element > &ciphertext, double constant) const
Definition: ckks.h:987
Main public key encryption scheme for the CKKS/CKKS implementation.
Definition: ckks.h:2560
LPCryptoParametersCKKS()
Definition: ckks.h:64
const std::vector< NativeInteger > & GetQlQlInvModqlDivqlModqPrecon(size_t i) const
Definition: ckks.h:243
Abstract interface for Leveled SHE operations.
Definition: pubkeylp.h:1088
LPAlgorithmSHECKKS()
Definition: ckks.h:910
const vector< vector< NativeInteger > > & GetPHatModq() const
Definition: ckks.h:367
const vector< NativeInteger > & GetPartQlHatInvModq(uint32_t part, uint32_t sublvl) const
Definition: ckks.h:553
enum RescalingTechnique GetRescalingTechnique() const
Definition: ckks.h:427
Abstract interface class for LBC PRE algorithms.
Definition: pubkeylp.h:1239
Ciphertext< Element > EvalAddMutable(Ciphertext< Element > &ciphertext, Plaintext plaintext) const override
Definition: ckks.h:962
const vector< DoubleNativeInt > & GetmodComplPartqBarrettMu(uint32_t lvl, uint32_t part) const
Definition: ckks.h:604
LPCryptoParametersCKKS(shared_ptr< ParmType > params, const PlaintextModulus &plaintextModulus, float distributionParameter, float assuranceMeasure, float securityLevel, usint relinWindow, MODE mode, int depth=1, int maxDepth=2, KeySwitchTechnique ksTech=BV, RescalingTechnique rsTech=APPROXRESCALE)
Definition: ckks.h:109
const shared_ptr< ILDCRTParams< BigInteger > > & GetParamsPartQ(uint32_t part) const
Definition: ckks.h:492
const vector< NativeInteger > & GetPHatInvModp() const
Definition: ckks.h:325
Ciphertext< Element > ComposedEvalMult(ConstCiphertext< Element > cipherText1, ConstCiphertext< Element > cipherText2, const LPEvalKey< Element > quadKeySwitchHint) const override
Definition: ckks.h:2469
uint32_t GetNumPerPartQ() const
Definition: ckks.h:545
main implementation class to capture essential cryptoparameters of any LBC system ...
Definition: pubkeylp.h:73
LPCryptoParametersCKKS(shared_ptr< ParmType > params, EncodingParams encodingParams, float distributionParameter, float assuranceMeasure, float securityLevel, usint relinWindow, MODE mode, int depth=1, int maxDepth=2, KeySwitchTechnique ksTech=BV, RescalingTechnique rsTech=APPROXRESCALE)
Definition: ckks.h:145
const vector< DoubleNativeInt > & GetModpBarrettMu() const
Definition: ckks.h:409
bool ParamsGen(shared_ptr< LPCryptoParameters< Element >> cryptoParams, int32_t evalAddCount=0, int32_t evalMultCount=0, int32_t keySwitchCount=0, size_t dcrtBits=0, uint32_t n=0) const
Definition: ckks.h:759
virtual ~LPCryptoParametersCKKS()
Definition: ckks.h:165
const vector< NativeInteger > & GetPHatInvModpPrecon() const
Definition: ckks.h:332
const std::vector< NativeInteger > & GetqInvModqPrecon(size_t i) const
Definition: ckks.h:262
Definition: pubkeylp.h:879
void RelinearizeInPlace(Ciphertext< Element > &ciphertext, const vector< LPEvalKey< Element >> &ek) const override
Definition: ckks.h:1261
Crypto parameters class for RLWE-based schemes.
Definition: ckks.h:53
Abstract interface class for LBC SHE algorithms.
Definition: pubkeylp.h:1679
double GetScalingFactorOfLevel(uint32_t l=0) const
Definition: ckks.h:440
Definition: binfhecontext.h:36
Ciphertext< Element > EvalMultMutable(Ciphertext< Element > &ciphertext, Plaintext plaintext) const override
Definition: ckks.h:1154
const vector< NativeInteger > & GetPartQHatInvModq(uint32_t part) const
Definition: ckks.h:527
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: ckks.h:211
Abstract interface for public key encryption schemes.
Definition: pubkeylp.h:3181
const shared_ptr< ILDCRTParams< BigInteger > > GetParamsP() const
Definition: ckks.h:272
bool PrecomputeCRTTables(KeySwitchTechnique ksTech, RescalingTechnique rsTech, uint32_t numLargeDigits=0)
virtual ~LPAlgorithmSHECKKS()
Definition: ckks.h:915
LPAlgorithmCKKS()
Definition: ckks.h:820