PALISADE Lattice Crypto Library  1.11.9
A lattice crypto library for software engineers by software engineers.
cryptocontext.h
1 // @file cryptocontext.h -- Control for encryption operations.
2 // @author TPOC: contact@palisade-crypto.org
3 //
4 // @copyright Copyright (c) 2019, New Jersey Institute of Technology (NJIT))
5 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution. THIS SOFTWARE IS
13 // PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
14 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 // EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 #ifndef SRC_PKE_CRYPTOCONTEXT_H_
25 #define SRC_PKE_CRYPTOCONTEXT_H_
26 
27 #include <map>
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include "palisade.h"
34 #include "scheme/allscheme.h"
35 
36 #include "cryptocontexthelper.h"
37 
38 #include "utils/caller_info.h"
39 #include "utils/serial.h"
40 
41 namespace lbcrypto {
42 
43 // Backend-specific settings for CKKS
44 #if NATIVEINT == 128
45 const size_t FIRSTMODSIZE = 105;
46 const enum RescalingTechnique DEFAULTRSTECH = APPROXAUTO;
47 #else
48 const size_t FIRSTMODSIZE = 60;
49 const enum RescalingTechnique DEFAULTRSTECH = EXACTRESCALE;
50 #endif
51 
52 template <typename Element>
54 
55 template <typename Element>
57 
58 template <typename Element>
59 using CryptoContext = shared_ptr<CryptoContextImpl<Element>>;
60 
77 template <typename Element>
78 class CryptoContextImpl : public Serializable {
79  using IntType = typename Element::Integer;
80  using ParmType = typename Element::Params;
81 
82  friend class CryptoContextFactory<Element>;
83 
84  protected:
85  // crypto parameters used for this context
86  shared_ptr<LPCryptoParameters<Element>> params;
87  // algorithm used; accesses all crypto methods
88  shared_ptr<LPPublicKeyEncryptionScheme<Element>> scheme;
89 
90  static std::map<string, std::vector<LPEvalKey<Element>>>& evalMultKeyMap() {
91  // cached evalmult keys, by secret key UID
92  static std::map<string, std::vector<LPEvalKey<Element>>> s_evalMultKeyMap;
93  return s_evalMultKeyMap;
94  }
95 
96  static std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>&
97  evalSumKeyMap() {
98  // cached evalsum keys, by secret key UID
99  static std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>
100  s_evalSumKeyMap;
101  return s_evalSumKeyMap;
102  }
103 
104  static std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>&
105  evalAutomorphismKeyMap() {
106  // cached evalautomorphism keys, by secret key UID
107  static std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>
108  s_evalAutomorphismKeyMap;
109  return s_evalAutomorphismKeyMap;
110  }
111 
112  string m_schemeId;
113 
114  uint32_t m_keyGenLevel;
115 
121  void TypeCheck(ConstCiphertext<Element> a, ConstCiphertext<Element> b,
122  CALLER_INFO_ARGS_HDR) const {
123  if (a == nullptr || b == nullptr) {
124  std::string errorMsg(std::string("Null Ciphertext") + CALLER_INFO);
125  PALISADE_THROW(type_error, errorMsg);
126  }
127  if (a->GetCryptoContext().get() != this) {
128  std::string errorMsg(
129  std::string("Ciphertext was not created in this CryptoContext") +
130  CALLER_INFO);
131  PALISADE_THROW(type_error, errorMsg);
132  }
133  if (a->GetCryptoContext() != b->GetCryptoContext()) {
134  std::string errorMsg(
135  std::string(
136  "Ciphertexts were not created in the same CryptoContext") +
137  CALLER_INFO);
138  PALISADE_THROW(type_error, errorMsg);
139  }
140  if (a->GetKeyTag() != b->GetKeyTag()) {
141  std::string errorMsg(
142  std::string("Ciphertexts were not encrypted with same keys") +
143  CALLER_INFO);
144  PALISADE_THROW(type_error, errorMsg);
145  }
146  if (a->GetEncodingType() != b->GetEncodingType()) {
147  std::stringstream ss;
148  ss << "Ciphertext encoding types " << a->GetEncodingType();
149  ss << " and " << b->GetEncodingType();
150  ss << " do not match";
151  ss << CALLER_INFO;
152  PALISADE_THROW(type_error, ss.str());
153  }
154  }
155 
164  /*
165  void TypeCheck(Ciphertext<Element> a,
166  Ciphertext<Element> b,
167  CALLER_INFO_ARGS_HDR) const {
168  if (a == nullptr || b == nullptr) {
169  std::string errorMsg(std::string("Null Ciphertext") + CALLER_INFO);
170  PALISADE_THROW(type_error, errorMsg);
171  }
172  if (a->GetCryptoContext().get() != this) {
173  std::string errorMsg(
174  std::string("Ciphertext was not created in this CryptoContext") +
175  CALLER_INFO);
176  PALISADE_THROW(type_error, errorMsg);
177  }
178  if (a->GetCryptoContext() != b->GetCryptoContext()) {
179  std::string errorMsg(
180  std::string("Ciphertexts were not created in the same CryptoContext") +
181  CALLER_INFO);
182  PALISADE_THROW(type_error, errorMsg);
183  }
184  if (a->GetKeyTag() != b->GetKeyTag()) {
185  std::string errorMsg(
186  std::string("Ciphertexts were not encrypted with same keys") +
187  CALLER_INFO);
188  PALISADE_THROW(type_error, errorMsg);
189  }
190  if (a->GetEncodingType() != b->GetEncodingType()) {
191  std::stringstream ss;
192  ss << "Ciphertext encoding types " << a->GetEncodingType();
193  ss << " and " << b->GetEncodingType();
194  ss << " do not match";
195  ss << CALLER_INFO;
196  PALISADE_THROW(type_error, ss.str());
197  }
198  }
199  */
200 
207  void TypeCheck(ConstCiphertext<Element> a, ConstPlaintext b,
208  CALLER_INFO_ARGS_HDR) const {
209  if (a == nullptr) {
210  std::string errorMsg(std::string("Null Ciphertext") + CALLER_INFO);
211  PALISADE_THROW(type_error, errorMsg);
212  }
213  if (b == nullptr) {
214  std::string errorMsg(std::string("Null Plaintext") + CALLER_INFO);
215  PALISADE_THROW(type_error, errorMsg);
216  }
217  if (a->GetCryptoContext().get() != this) {
218  std::string errorMsg(
219  std::string("Ciphertext was not created in this CryptoContext") +
220  CALLER_INFO);
221  PALISADE_THROW(type_error, errorMsg);
222  }
223  if (a->GetEncodingType() != b->GetEncodingType()) {
224  std::stringstream ss;
225  ss << "Ciphertext encoding type " << a->GetEncodingType();
226  ss << " and Plaintext encoding type " << b->GetEncodingType();
227  ss << " do not match";
228  ss << CALLER_INFO;
229  PALISADE_THROW(type_error, ss.str());
230  }
231  }
232 
233  bool Mismatched(const CryptoContext<Element> a) const {
234  if (a.get() != this) {
235  return true;
236  }
237  return false;
238  }
239 
240  public:
241  LPPrivateKey<Element> privateKey;
242 
267  void SetPrivateKey(const LPPrivateKey<Element> sk) {
268 #ifdef DEBUG_KEY
269  cerr << "Warning - SetPrivateKey is only intended to be used for debugging "
270  "purposes - not for production systems."
271  << endl;
272  this->privateKey = sk;
273 #else
274  PALISADE_THROW(
276  "SetPrivateKey is only allowed if DEBUG_KEY is set in palisade.h");
277 #endif
278  }
279 
304  const LPPrivateKey<Element> GetPrivateKey() {
305 #ifdef DEBUG_KEY
306  return this->privateKey;
307 #else
308  PALISADE_THROW(
310  "GetPrivateKey is only allowed if DEBUG_KEY is set in palisade.h");
311 #endif
312  }
313 
314  void setSchemeId(string schemeTag) { this->m_schemeId = schemeTag; }
315 
316  string getSchemeId() const { return this->m_schemeId; }
317 
324  LPPublicKeyEncryptionScheme<Element>* scheme = nullptr,
325  const string& schemeId = "Not") {
326  this->params.reset(params);
327  this->scheme.reset(scheme);
328  this->m_keyGenLevel = 0;
329  this->m_schemeId = schemeId;
330  }
331 
338  shared_ptr<LPPublicKeyEncryptionScheme<Element>> scheme,
339  const string& schemeId = "Not") {
340  this->params = params;
341  this->scheme = scheme;
342  this->m_keyGenLevel = 0;
343  this->m_schemeId = schemeId;
344  }
345 
351  params = c.params;
352  scheme = c.scheme;
353  this->m_keyGenLevel = 0;
354  this->m_schemeId = c.m_schemeId;
355  }
356 
363  params = rhs.params;
364  scheme = rhs.scheme;
365  m_keyGenLevel = rhs.m_keyGenLevel;
366  m_schemeId = rhs.m_schemeId;
367  return *this;
368  }
369 
373  operator bool() const { return params && scheme; }
374 
383  const CryptoContextImpl<Element>& b) {
384  // Identical if the parameters and the schemes are identical... the exact
385  // same object, OR the same type and the same values
386  if (a.params.get() == b.params.get()) {
387  return true;
388  } else {
389  if (typeid(*a.params.get()) != typeid(*b.params.get())) {
390  return false;
391  }
392  if (*a.params.get() != *b.params.get()) return false;
393  }
394 
395  if (a.scheme.get() == b.scheme.get()) {
396  return true;
397  } else {
398  if (typeid(*a.scheme.get()) != typeid(*b.scheme.get())) {
399  return false;
400  }
401  if (*a.scheme.get() != *b.scheme.get()) return false;
402  }
403 
404  return true;
405  }
406 
407  friend bool operator!=(const CryptoContextImpl<Element>& a,
408  const CryptoContextImpl<Element>& b) {
409  return !(a == b);
410  }
411 
420  template <typename ST>
421  static bool SerializeEvalMultKey(std::ostream& ser, const ST& sertype,
422  string id = "");
423 
432  template <typename ST>
433  static bool SerializeEvalMultKey(std::ostream& ser, const ST& sertype,
434  const CryptoContext<Element> cc) {
435  std::map<string, std::vector<LPEvalKey<Element>>> omap;
436  for (const auto& k : GetAllEvalMultKeys()) {
437  if (k.second[0]->GetCryptoContext() == cc) {
438  omap[k.first] = k.second;
439  }
440  }
441 
442  if (omap.size() == 0) return false;
443 
444  Serial::Serialize(omap, ser, sertype);
445  return true;
446  }
447 
456  template <typename ST>
457  static bool DeserializeEvalMultKey(std::istream& ser, const ST& sertype) {
458  std::map<string, std::vector<LPEvalKey<Element>>> evalMultKeys;
459 
460  Serial::Deserialize(GetAllEvalMultKeys(), ser, sertype);
461 
462  // The deserialize call created any contexts that needed to be created....
463  // so all we need to do is put the keys into the maps for their context
464 
465  for (auto k : GetAllEvalMultKeys()) {
466  GetAllEvalMultKeys()[k.first] = k.second;
467  }
468 
469  return true;
470  }
471 
475  static void ClearEvalMultKeys();
476 
481  static void ClearEvalMultKeys(const string& id);
482 
487  static void ClearEvalMultKeys(const CryptoContext<Element> cc);
488 
494  static void InsertEvalMultKey(
495  const std::vector<LPEvalKey<Element>>& vectorToInsert);
496 
505  template <typename ST>
506  static bool SerializeEvalSumKey(std::ostream& ser, const ST& sertype,
507  string id = "") {
508  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>* smap;
509  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>> omap;
510 
511  if (id.length() == 0) {
512  smap = &GetAllEvalSumKeys();
513  } else {
514  auto k = GetAllEvalSumKeys().find(id);
515 
516  if (k == GetAllEvalSumKeys().end()) return false; // no such id
517 
518  smap = &omap;
519  omap[k->first] = k->second;
520  }
521  Serial::Serialize(*smap, ser, sertype);
522  return true;
523  }
524 
533  template <typename ST>
534  static bool SerializeEvalSumKey(std::ostream& ser, const ST& sertype,
535  const CryptoContext<Element> cc) {
536  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>> omap;
537  for (const auto& k : GetAllEvalSumKeys()) {
538  if (k.second->begin()->second->GetCryptoContext() == cc) {
539  omap[k.first] = k.second;
540  }
541  }
542 
543  if (omap.size() == 0) return false;
544 
545  Serial::Serialize(omap, ser, sertype);
546 
547  return true;
548  }
549 
559  template <typename ST>
560  static bool DeserializeEvalSumKey(std::istream& ser, const ST& sertype) {
561  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>
562  evalSumKeys;
563 
564  Serial::Deserialize(evalSumKeys, ser, sertype);
565 
566  // The deserialize call created any contexts that needed to be created....
567  // so all we need to do is put the keys into the maps for their context
568 
569  for (auto k : evalSumKeys) {
570  GetAllEvalSumKeys()[k.first] = k.second;
571  }
572 
573  return true;
574  }
575 
579  static void ClearEvalSumKeys();
580 
585  static void ClearEvalSumKeys(const string& id);
586 
591  static void ClearEvalSumKeys(const CryptoContext<Element> cc);
592 
598  static void InsertEvalSumKey(
599  const shared_ptr<std::map<usint, LPEvalKey<Element>>> mapToInsert);
600 
610  template <typename ST>
611  static bool SerializeEvalAutomorphismKey(std::ostream& ser, const ST& sertype,
612  string id = "") {
613  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>* smap;
614  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>> omap;
615  if (id.length() == 0) {
616  smap = &GetAllEvalAutomorphismKeys();
617  } else {
618  auto k = GetAllEvalAutomorphismKeys().find(id);
619 
620  if (k == GetAllEvalAutomorphismKeys().end()) return false; // no such id
621 
622  smap = &omap;
623  omap[k->first] = k->second;
624  }
625  Serial::Serialize(*smap, ser, sertype);
626  return true;
627  }
628 
637  template <typename ST>
638  static bool SerializeEvalAutomorphismKey(std::ostream& ser, const ST& sertype,
639  const CryptoContext<Element> cc) {
640  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>> omap;
641  for (const auto& k : GetAllEvalAutomorphismKeys()) {
642  if (k.second->begin()->second->GetCryptoContext() == cc) {
643  omap[k.first] = k.second;
644  }
645  }
646 
647  if (omap.size() == 0) return false;
648 
649  Serial::Serialize(omap, ser, sertype);
650  return true;
651  }
652 
662  template <typename ST>
663  static bool DeserializeEvalAutomorphismKey(std::istream& ser,
664  const ST& sertype) {
665  std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>
666  evalSumKeys;
667 
668  Serial::Deserialize(evalSumKeys, ser, sertype);
669 
670  // The deserialize call created any contexts that needed to be created....
671  // so all we need to do is put the keys into the maps for their context
672 
673  for (auto k : evalSumKeys) {
674  GetAllEvalAutomorphismKeys()[k.first] = k.second;
675  }
676 
677  return true;
678  }
679 
683  static void ClearEvalAutomorphismKeys();
684 
689  static void ClearEvalAutomorphismKeys(const string& id);
690 
696  static void ClearEvalAutomorphismKeys(const CryptoContext<Element> cc);
697 
703  static void InsertEvalAutomorphismKey(
704  const shared_ptr<std::map<usint, LPEvalKey<Element>>> mapToInsert);
705 
706  // TURN FEATURES ON
711  void Enable(PKESchemeFeature feature) { scheme->Enable(feature); }
712 
717  void Enable(usint featureMask) { scheme->Enable(featureMask); }
718 
719  // GETTERS
724  const shared_ptr<LPPublicKeyEncryptionScheme<Element>>
726  return scheme;
727  }
728 
733  const shared_ptr<LPCryptoParameters<Element>> GetCryptoParameters() const {
734  return params;
735  }
736 
737  size_t GetKeyGenLevel() const { return m_keyGenLevel; }
738 
739  void SetKeyGenLevel(size_t level) { m_keyGenLevel = level; }
740 
745  const shared_ptr<ParmType> GetElementParams() const {
746  return params->GetElementParams();
747  }
748 
753  const EncodingParams GetEncodingParams() const {
754  return params->GetEncodingParams();
755  }
756 
762  usint GetCyclotomicOrder() const {
763  return params->GetElementParams()->GetCyclotomicOrder();
764  }
765 
771  usint GetRingDimension() const {
772  return params->GetElementParams()->GetRingDimension();
773  }
774 
780  const IntType& GetModulus() const {
781  return params->GetElementParams()->GetModulus();
782  }
783 
789  const IntType& GetRootOfUnity() const {
790  return params->GetElementParams()->GetRootOfUnity();
791  }
792 
798  auto r = GetEncryptionAlgorithm()->KeyGen(
800  return r;
801  }
802 
816  LPKeyPair<Element> MultipartyKeyGen(const LPPublicKey<Element> pk,
817  bool makeSparse = false,
818  bool fresh = false) {
819  if (!pk) PALISADE_THROW(config_error, "Input public key is empty");
820  auto r = GetEncryptionAlgorithm()->MultipartyKeyGen(
822  makeSparse, fresh);
823  return r;
824  }
825 
835  const vector<LPPrivateKey<Element>>& secretKeys) {
836  if (!secretKeys.size())
837  PALISADE_THROW(config_error, "Input private key vector is empty");
838  auto r = GetEncryptionAlgorithm()->MultipartyKeyGen(
840  false);
841  return r;
842  }
843 
851  vector<Ciphertext<Element>> MultipartyDecryptLead(
852  const LPPrivateKey<Element> privateKey,
853  const vector<Ciphertext<Element>>& ciphertext) const {
854  if (privateKey == nullptr || Mismatched(privateKey->GetCryptoContext()))
855  PALISADE_THROW(config_error,
856  "Information passed to MultipartyDecryptLead was not "
857  "generated with this crypto context");
858 
859  vector<Ciphertext<Element>> newCiphertext;
860 
861  for (size_t i = 0; i < ciphertext.size(); i++) {
862  if (ciphertext[i] == nullptr ||
863  Mismatched(ciphertext[i]->GetCryptoContext()))
864  PALISADE_THROW(config_error,
865  "A ciphertext passed to MultipartyDecryptLead was not "
866  "generated with this crypto context");
867 
868  newCiphertext.push_back(GetEncryptionAlgorithm()->MultipartyDecryptLead(
869  privateKey, ciphertext[i]));
870  }
871 
872  return newCiphertext;
873  }
874 
882  vector<Ciphertext<Element>> MultipartyDecryptMain(
883  const LPPrivateKey<Element> privateKey,
884  const vector<Ciphertext<Element>>& ciphertext) const {
885  if (privateKey == nullptr || Mismatched(privateKey->GetCryptoContext()))
886  PALISADE_THROW(config_error,
887  "Information passed to MultipartyDecryptMain was not "
888  "generated with this crypto context");
889 
890  vector<Ciphertext<Element>> newCiphertext;
891 
892  for (size_t i = 0; i < ciphertext.size(); i++) {
893  if (ciphertext[i] == nullptr ||
894  Mismatched(ciphertext[i]->GetCryptoContext()))
895  PALISADE_THROW(config_error,
896  "A ciphertext passed to MultipartyDecryptMain was not "
897  "generated with this crypto context");
898 
899  newCiphertext.push_back(GetEncryptionAlgorithm()->MultipartyDecryptMain(
900  privateKey, ciphertext[i]));
901  }
902 
903  return newCiphertext;
904  }
905 
915  const vector<Ciphertext<Element>>& partialCiphertextVec,
916  Plaintext* plaintext) const;
917 
928  LPEvalKey<Element> MultiKeySwitchGen(
929  const LPPrivateKey<Element> originalPrivateKey,
930  const LPPrivateKey<Element> newPrivateKey,
931  const LPEvalKey<Element> ek) const {
932  if (!originalPrivateKey)
933  PALISADE_THROW(config_error, "Input first private key is nullptr");
934  if (!newPrivateKey)
935  PALISADE_THROW(config_error, "Input second private key is nullptr");
936  if (!ek) PALISADE_THROW(config_error, "Input evaluation key is nullptr");
937  auto r = GetEncryptionAlgorithm()->MultiKeySwitchGen(originalPrivateKey,
938  newPrivateKey, ek);
939  return r;
940  }
941 
953  shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalAutomorphismKeyGen(
954  const LPPrivateKey<Element> privateKey,
955  const shared_ptr<std::map<usint, LPEvalKey<Element>>> eAuto,
956  const std::vector<usint>& indexList, const std::string& keyId = "") {
957  if (!privateKey)
958  PALISADE_THROW(config_error, "Input private key is nullptr");
959  if (!eAuto)
960  PALISADE_THROW(config_error, "Input evaluation key map is nullptr");
961  if (!indexList.size())
962  PALISADE_THROW(config_error, "Input index vector is empty");
963  auto r = GetEncryptionAlgorithm()->MultiEvalAutomorphismKeyGen(
964  privateKey, eAuto, indexList, keyId);
965  return r;
966  }
967 
979  shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalAtIndexKeyGen(
980  const LPPrivateKey<Element> privateKey,
981  const shared_ptr<std::map<usint, LPEvalKey<Element>>> eAuto,
982  const std::vector<int32_t>& indexList, const std::string& keyId = "") {
983  if (!privateKey)
984  PALISADE_THROW(config_error, "Input private key is nullptr");
985  if (!eAuto)
986  PALISADE_THROW(config_error, "Input evaluation key map is nullptr");
987  if (!indexList.size())
988  PALISADE_THROW(config_error, "Input index vector is empty");
989  auto r = GetEncryptionAlgorithm()->MultiEvalAtIndexKeyGen(privateKey, eAuto,
990  indexList, keyId);
991  return r;
992  }
993 
1004  shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalSumKeyGen(
1005  const LPPrivateKey<Element> privateKey,
1006  const shared_ptr<std::map<usint, LPEvalKey<Element>>> eSum,
1007  const std::string& keyId = "") {
1008  if (!privateKey)
1009  PALISADE_THROW(config_error, "Input private key is nullptr");
1010  if (!eSum)
1011  PALISADE_THROW(config_error, "Input evaluation key map is nullptr");
1012  auto r =
1013  GetEncryptionAlgorithm()->MultiEvalSumKeyGen(privateKey, eSum, keyId);
1014  return r;
1015  }
1016 
1025  LPEvalKey<Element> MultiAddEvalKeys(LPEvalKey<Element> a,
1026  LPEvalKey<Element> b,
1027  const std::string& keyId = "") {
1028  if (!a)
1029  PALISADE_THROW(config_error, "Input first evaluation key is nullptr");
1030  if (!b)
1031  PALISADE_THROW(config_error, "Input second evaluation key is nullptr");
1032  auto r = GetEncryptionAlgorithm()->MultiAddEvalKeys(a, b, keyId);
1033  return r;
1034  }
1035 
1046  LPEvalKey<Element> MultiMultEvalKey(LPEvalKey<Element> evalKey,
1047  LPPrivateKey<Element> sk,
1048  const std::string& keyId = "") {
1049  if (!evalKey)
1050  PALISADE_THROW(config_error, "Input evaluation key is nullptr");
1051  if (!sk) PALISADE_THROW(config_error, "Input private key is nullptr");
1052  auto r = GetEncryptionAlgorithm()->MultiMultEvalKey(evalKey, sk, keyId);
1053  return r;
1054  }
1055 
1064  shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiAddEvalSumKeys(
1065  const shared_ptr<std::map<usint, LPEvalKey<Element>>> es1,
1066  const shared_ptr<std::map<usint, LPEvalKey<Element>>> es2,
1067  const std::string& keyId = "") {
1068  if (!es1)
1069  PALISADE_THROW(config_error, "Input first evaluation key map is nullptr");
1070  if (!es2)
1071  PALISADE_THROW(config_error,
1072  "Input second evaluation key map is nullptr");
1073  auto r = GetEncryptionAlgorithm()->MultiAddEvalSumKeys(es1, es2, keyId);
1074  return r;
1075  }
1076 
1085  shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiAddEvalAutomorphismKeys(
1086  const shared_ptr<std::map<usint, LPEvalKey<Element>>> es1,
1087  const shared_ptr<std::map<usint, LPEvalKey<Element>>> es2,
1088  const std::string& keyId = "") {
1089  if (!es1)
1090  PALISADE_THROW(config_error, "Input first evaluation key map is nullptr");
1091  if (!es2)
1092  PALISADE_THROW(config_error,
1093  "Input second evaluation key map is nullptr");
1094  auto r =
1095  GetEncryptionAlgorithm()->MultiAddEvalAutomorphismKeys(es1, es2, keyId);
1096  return r;
1097  }
1098 
1107  LPPublicKey<Element> MultiAddPubKeys(LPPublicKey<Element> pubKey1,
1108  LPPublicKey<Element> pubKey2,
1109  const std::string& keyId = "") {
1110  if (!pubKey1)
1111  PALISADE_THROW(config_error, "Input first public key is nullptr");
1112  if (!pubKey2)
1113  PALISADE_THROW(config_error, "Input second public key is nullptr");
1114 
1115  auto r = GetEncryptionAlgorithm()->MultiAddPubKeys(pubKey1, pubKey2, keyId);
1116  return r;
1117  }
1118 
1127  LPEvalKey<Element> MultiAddEvalMultKeys(LPEvalKey<Element> evalKey1,
1128  LPEvalKey<Element> evalKey2,
1129  const std::string& keyId = "") {
1130  if (!evalKey1)
1131  PALISADE_THROW(config_error, "Input first evaluation key is nullptr");
1132  if (!evalKey2)
1133  PALISADE_THROW(config_error, "Input second evaluation key is nullptr");
1134  auto r = GetEncryptionAlgorithm()->MultiAddEvalMultKeys(evalKey1, evalKey2,
1135  keyId);
1136  return r;
1137  }
1138 
1145  auto r = GetEncryptionAlgorithm()->KeyGen(
1147  return r;
1148  }
1149 
1156  LPEvalKey<Element> ReKeyGen(const LPPublicKey<Element> newKey,
1157  const LPPrivateKey<Element> oldKey) const {
1158  if (newKey == nullptr || oldKey == nullptr ||
1159  Mismatched(newKey->GetCryptoContext()) ||
1160  Mismatched(oldKey->GetCryptoContext()))
1161  PALISADE_THROW(config_error,
1162  "Keys passed to ReKeyGen were not generated with this "
1163  "crypto context");
1164 
1165  auto r = GetEncryptionAlgorithm()->ReKeyGen(newKey, oldKey);
1166  return r;
1167  }
1168 
1176  LPEvalKey<Element> ReKeyGen(const LPPrivateKey<Element> newKey,
1177  const LPPrivateKey<Element> oldKey) const
1178  __attribute__((deprecated("functionality removed from PALISADE")));
1179 
1186  void EvalMultKeyGen(const LPPrivateKey<Element> key);
1187 
1197  void EvalMultKeysGen(const LPPrivateKey<Element> key);
1198 
1204  static const vector<LPEvalKey<Element>>& GetEvalMultKeyVector(
1205  const string& keyID);
1206 
1211  static std::map<string, std::vector<LPEvalKey<Element>>>&
1213 
1221  LPEvalKey<Element> KeySwitchGen(const LPPrivateKey<Element> key1,
1222  const LPPrivateKey<Element> key2) const {
1223  if (key1 == nullptr || key2 == nullptr ||
1224  Mismatched(key1->GetCryptoContext()) ||
1225  Mismatched(key2->GetCryptoContext()))
1226  PALISADE_THROW(config_error,
1227  "Keys passed to KeySwitchGen were not generated with this "
1228  "crypto context");
1229 
1230  auto r = GetEncryptionAlgorithm()->KeySwitchGen(key1, key2);
1231  return r;
1232  }
1233 
1240  Ciphertext<Element> Encrypt(const LPPublicKey<Element> publicKey,
1241  Plaintext plaintext) {
1242  if (publicKey == nullptr)
1243  PALISADE_THROW(type_error, "null key passed to Encrypt");
1244 
1245  if (plaintext == nullptr)
1246  PALISADE_THROW(type_error, "Input plaintext is nullptr");
1247 
1248  if (Mismatched(publicKey->GetCryptoContext()))
1249  PALISADE_THROW(
1250  config_error,
1251  "key passed to Encrypt was not generated with this crypto context");
1252 
1253  Ciphertext<Element> ciphertext = GetEncryptionAlgorithm()->Encrypt(
1254  publicKey, plaintext->GetElement<Element>());
1255 
1256  if (ciphertext) {
1257  ciphertext->SetEncodingType(plaintext->GetEncodingType());
1258  ciphertext->SetScalingFactor(plaintext->GetScalingFactor());
1259  ciphertext->SetDepth(plaintext->GetDepth());
1260  ciphertext->SetLevel(plaintext->GetLevel());
1261  }
1262 
1263  return ciphertext;
1264  }
1265 
1272  Ciphertext<Element> Encrypt(const LPPrivateKey<Element> privateKey,
1273  Plaintext plaintext) const {
1274  if (privateKey == nullptr || Mismatched(privateKey->GetCryptoContext()))
1275  PALISADE_THROW(
1276  config_error,
1277  "key passed to Encrypt was not generated with this crypto context");
1278  if (plaintext == nullptr)
1279  PALISADE_THROW(type_error, "Input plaintext is nullptr");
1280 
1281  Ciphertext<Element> ciphertext = GetEncryptionAlgorithm()->Encrypt(
1282  privateKey, plaintext->GetElement<Element>());
1283 
1284  if (ciphertext) {
1285  ciphertext->SetEncodingType(plaintext->GetEncodingType());
1286  ciphertext->SetScalingFactor(plaintext->GetScalingFactor());
1287  ciphertext->SetDepth(plaintext->GetDepth());
1288  ciphertext->SetLevel(plaintext->GetLevel());
1289  }
1290 
1291  return ciphertext;
1292  }
1293 
1294  // PLAINTEXT FACTORY METHODS
1295  // TODO to be deprecated in 2.0
1301  Plaintext MakeStringPlaintext(const string& str) const {
1302  auto p = PlaintextFactory::MakePlaintext(String, this->GetElementParams(),
1303  this->GetEncodingParams(), str);
1304  return p;
1305  }
1306 
1312  Plaintext MakeCoefPackedPlaintext(const vector<int64_t>& value) const {
1313  auto p = PlaintextFactory::MakePlaintext(
1314  CoefPacked, this->GetElementParams(), this->GetEncodingParams(), value);
1315  return p;
1316  }
1317 
1323  Plaintext MakePackedPlaintext(const vector<int64_t>& value) const {
1324  auto p = PlaintextFactory::MakePlaintext(Packed, this->GetElementParams(),
1325  this->GetEncodingParams(), value);
1326  return p;
1327  }
1328 
1336  template <typename Value1>
1337  static Plaintext MakePlaintext(PlaintextEncodings encoding,
1338  CryptoContext<Element> cc,
1339  const Value1& value) {
1340  return PlaintextFactory::MakePlaintext(encoding, cc->GetElementParams(),
1341  cc->GetEncodingParams(), value);
1342  }
1343 
1344  template <typename Value1, typename Value2>
1345  static Plaintext MakePlaintext(PlaintextEncodings encoding,
1346  CryptoContext<Element> cc, const Value1& value,
1347  const Value2& value2) {
1348  return PlaintextFactory::MakePlaintext(encoding, cc->GetElementParams(),
1349  cc->GetEncodingParams(), value,
1350  value2);
1351  }
1352 
1364  virtual Plaintext MakeCKKSPackedPlaintext(
1365  const std::vector<std::complex<double>>& value, size_t depth = 1,
1366  uint32_t level = 0, const shared_ptr<ParmType> params = nullptr) const {
1367  Plaintext p;
1368  const auto cryptoParamsCKKS =
1369  std::dynamic_pointer_cast<LPCryptoParametersCKKS<DCRTPoly>>(
1370  this->GetCryptoParameters());
1371 
1372  double scFact = cryptoParamsCKKS->GetScalingFactorOfLevel(level);
1373 
1374  if (params == nullptr) {
1375  shared_ptr<ILDCRTParams<DCRTPoly::Integer>> elemParamsPtr;
1376  if (level != 0) {
1377  ILDCRTParams<DCRTPoly::Integer> elemParams =
1378  *(cryptoParamsCKKS->GetElementParams());
1379  for (uint32_t i = 0; i < level; i++) {
1380  elemParams.PopLastParam();
1381  }
1382  elemParamsPtr =
1383  std::make_shared<ILDCRTParams<DCRTPoly::Integer>>(elemParams);
1384  } else {
1385  elemParamsPtr = cryptoParamsCKKS->GetElementParams();
1386  }
1387 
1388  p = Plaintext(std::make_shared<CKKSPackedEncoding>(
1389  elemParamsPtr, this->GetEncodingParams(), value, depth, level,
1390  scFact));
1391  } else {
1392  p = Plaintext(std::make_shared<CKKSPackedEncoding>(
1393  params, this->GetEncodingParams(), value, depth, level, scFact));
1394  }
1395 
1396  p->Encode();
1397  return p;
1398  }
1399 
1409  virtual Plaintext MakeCKKSPackedPlaintext(
1410  const std::vector<double>& value, size_t depth = 1, uint32_t level = 0,
1411  const shared_ptr<ParmType> params = nullptr) const {
1412  std::vector<std::complex<double>> complexValue(value.size());
1413  std::transform(value.begin(), value.end(), complexValue.begin(),
1414  [](double da) { return std::complex<double>(da); });
1415 
1416  return MakeCKKSPackedPlaintext(complexValue, depth, level, params);
1417  }
1418 
1427  static Plaintext GetPlaintextForDecrypt(PlaintextEncodings pte,
1428  shared_ptr<ParmType> evp,
1429  EncodingParams ep);
1430 
1431  public:
1440  DecryptResult Decrypt(const LPPrivateKey<Element> privateKey,
1441  ConstCiphertext<Element> ciphertext,
1442  Plaintext* plaintext);
1443 
1452  Ciphertext<Element> ReEncrypt(
1453  LPEvalKey<Element> evalKey, ConstCiphertext<Element> ciphertext,
1454  const LPPublicKey<Element> publicKey = nullptr) const {
1455  if (evalKey == nullptr || Mismatched(evalKey->GetCryptoContext()))
1456  PALISADE_THROW(config_error,
1457  "Information passed to ReEncrypt was not generated with "
1458  "this crypto context");
1459 
1460  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
1461  PALISADE_THROW(config_error,
1462  "The ciphertext passed to ReEncrypt was not generated "
1463  "with this crypto context");
1464 
1465  Ciphertext<Element> newCiphertext =
1466  GetEncryptionAlgorithm()->ReEncrypt(evalKey, ciphertext, publicKey);
1467 
1468  return newCiphertext;
1469  }
1470 
1477  Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ct1,
1478  ConstCiphertext<Element> ct2) const {
1479  TypeCheck(ct1, ct2);
1480 
1481  auto rv = GetEncryptionAlgorithm()->EvalAdd(ct1, ct2);
1482  return rv;
1483  }
1484 
1491  void EvalAddInPlace(Ciphertext<Element>& ct1,
1492  ConstCiphertext<Element> ct2) const {
1493  TypeCheck(ct1, ct2);
1494 
1495  GetEncryptionAlgorithm()->EvalAddInPlace(ct1, ct2);
1496  }
1497 
1507  Ciphertext<Element> EvalAddMutable(Ciphertext<Element>& ct1,
1508  Ciphertext<Element>& ct2) const {
1509  TypeCheck(ct1, ct2);
1510 
1511  auto rv = GetEncryptionAlgorithm()->EvalAddMutable(ct1, ct2);
1512  return rv;
1513  }
1514 
1521  Ciphertext<Element> EvalSub(ConstCiphertext<Element> ct1,
1522  ConstCiphertext<Element> ct2) const {
1523  TypeCheck(ct1, ct2);
1524 
1525  auto rv = GetEncryptionAlgorithm()->EvalSub(ct1, ct2);
1526  return rv;
1527  }
1528 
1538  Ciphertext<Element> EvalSubMutable(Ciphertext<Element>& ct1,
1539  Ciphertext<Element>& ct2) const {
1540  TypeCheck(ct1, ct2);
1541 
1542  auto rv = GetEncryptionAlgorithm()->EvalSubMutable(ct1, ct2);
1543  return rv;
1544  }
1545 
1552  Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext,
1553  ConstPlaintext plaintext) const {
1554  TypeCheck(ciphertext, plaintext);
1555 
1556  plaintext->SetFormat(EVALUATION);
1557 
1558  auto rv = GetEncryptionAlgorithm()->EvalAdd(ciphertext, plaintext);
1559  return rv;
1560  }
1561 
1571  Ciphertext<Element> EvalAddMutable(Ciphertext<Element>& ciphertext,
1572  Plaintext plaintext) const {
1573  TypeCheck((ConstCiphertext<Element>)ciphertext, (ConstPlaintext)plaintext);
1574 
1575  plaintext->SetFormat(EVALUATION);
1576 
1577  auto rv = GetEncryptionAlgorithm()->EvalAddMutable(ciphertext, plaintext);
1578  return rv;
1579  }
1580 
1587  Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ciphertext,
1588  double constant) const {
1589  Ciphertext<Element> rv;
1590 
1591  if (constant >= 0) {
1592  rv = GetEncryptionAlgorithm()->EvalAdd(ciphertext, constant);
1593  } else {
1594  rv = GetEncryptionAlgorithm()->EvalSub(ciphertext, -constant);
1595  }
1596 
1597  return rv;
1598  }
1599 
1608  Ciphertext<Element> EvalLinearWSum(vector<Ciphertext<Element>> ciphertexts,
1609  vector<double> constants) const {
1610  auto rv = GetEncryptionAlgorithm()->EvalLinearWSum(ciphertexts, constants);
1611  return rv;
1612  }
1613 
1623  Ciphertext<Element> EvalLinearWSumMutable(
1624  vector<Ciphertext<Element>> ciphertexts, vector<double> constants) const {
1625  auto rv =
1626  GetEncryptionAlgorithm()->EvalLinearWSumMutable(ciphertexts, constants);
1627  return rv;
1628  }
1629 
1630  inline Ciphertext<Element> EvalLinearWSum(
1631  vector<double> constants, vector<Ciphertext<Element>> ciphertexts) const {
1632  return EvalLinearWSum(ciphertexts, constants);
1633  }
1634 
1635  inline Ciphertext<Element> EvalLinearWSumMutable(
1636  vector<double> constants, vector<Ciphertext<Element>> ciphertexts) const {
1637  return EvalLinearWSumMutable(ciphertexts, constants);
1638  }
1639 
1640  inline Ciphertext<Element> EvalAdd(
1641  ConstPlaintext plaintext, ConstCiphertext<Element> ciphertext) const {
1642  return EvalAdd(ciphertext, plaintext);
1643  }
1644 
1645  inline Ciphertext<Element> EvalAddMutable(
1646  Plaintext plaintext, Ciphertext<Element>& ciphertext) const {
1647  return EvalAddMutable(ciphertext, plaintext);
1648  }
1649 
1650  inline Ciphertext<Element> EvalAdd(
1651  double constant, ConstCiphertext<Element> ciphertext) const {
1652  return EvalAdd(ciphertext, constant);
1653  }
1654 
1661  Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext,
1662  ConstPlaintext plaintext) const {
1663  TypeCheck(ciphertext, plaintext);
1664 
1665  auto rv = GetEncryptionAlgorithm()->EvalSub(ciphertext, plaintext);
1666  return rv;
1667  }
1668 
1678  Ciphertext<Element> EvalSubMutable(Ciphertext<Element>& ciphertext,
1679  Plaintext plaintext) const {
1680  TypeCheck((ConstCiphertext<Element>)ciphertext, (ConstPlaintext)plaintext);
1681 
1682  auto rv = GetEncryptionAlgorithm()->EvalSubMutable(ciphertext, plaintext);
1683  return rv;
1684  }
1685 
1692  Ciphertext<Element> EvalSub(ConstCiphertext<Element> ciphertext,
1693  double constant) const {
1694  Ciphertext<Element> rv;
1695 
1696  if (constant >= 0) {
1697  rv = GetEncryptionAlgorithm()->EvalSub(ciphertext, constant);
1698  } else {
1699  rv = GetEncryptionAlgorithm()->EvalAdd(ciphertext, -constant);
1700  }
1701 
1702  return rv;
1703  }
1704 
1705  inline Ciphertext<Element> EvalSub(
1706  ConstPlaintext plaintext, ConstCiphertext<Element> ciphertext) const {
1707  return EvalAdd(EvalNegate(ciphertext), plaintext);
1708  }
1709 
1710  inline Ciphertext<Element> EvalSubMutable(
1711  Plaintext plaintext, Ciphertext<Element>& ciphertext) const {
1712  Ciphertext<Element> negated = EvalNegate(ciphertext);
1713  Ciphertext<Element> result = EvalAddMutable(negated, plaintext);
1714  ciphertext = EvalNegate(negated);
1715  return result;
1716  }
1717 
1718  inline Ciphertext<Element> EvalSub(
1719  double constant, ConstCiphertext<Element> ciphertext) const {
1720  return EvalAdd(EvalNegate(ciphertext), constant);
1721  }
1722 
1730  Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,
1731  ConstCiphertext<Element> ct2) const {
1732  TypeCheck(ct1, ct2);
1733 
1734  auto ek = GetEvalMultKeyVector(ct1->GetKeyTag());
1735  if (!ek.size()) {
1736  PALISADE_THROW(type_error,
1737  "Evaluation key has not been generated for EvalMult");
1738  }
1739 
1740  auto rv = GetEncryptionAlgorithm()->EvalMult(ct1, ct2, ek[0]);
1741  return rv;
1742  }
1743 
1753  Ciphertext<Element> EvalMultMutable(Ciphertext<Element>& ct1,
1754  Ciphertext<Element>& ct2) const {
1755  TypeCheck(ct1, ct2);
1756 
1757  auto ek = GetEvalMultKeyVector(ct1->GetKeyTag());
1758  if (!ek.size()) {
1759  PALISADE_THROW(type_error,
1760  "Evaluation key has not been generated for EvalMult");
1761  }
1762 
1763  auto rv = GetEncryptionAlgorithm()->EvalMultMutable(ct1, ct2, ek[0]);
1764  return rv;
1765  }
1766 
1774  Ciphertext<Element> EvalMultNoRelin(ConstCiphertext<Element> ct1,
1775  ConstCiphertext<Element> ct2) const {
1776  TypeCheck(ct1, ct2);
1777 
1778  auto rv = GetEncryptionAlgorithm()->EvalMult(ct1, ct2);
1779  return rv;
1780  }
1781 
1795  Ciphertext<Element> EvalMultMany(
1796  const vector<Ciphertext<Element>>& ct) const {
1797  // input parameter check
1798  if (!ct.size()) PALISADE_THROW(type_error, "Empty input ciphertext vector");
1799 
1800  if (ct.size() == 1){
1801  return ct[0];
1802  }
1803 
1804  const auto ek = GetEvalMultKeyVector(ct[0]->GetKeyTag());
1805  if (ek.size() < (ct[0]->GetElements().size() - 2)) {
1806  PALISADE_THROW(type_error,
1807  "Insufficient value was used for maxDepth to generate "
1808  "keys for EvalMult");
1809  }
1810 
1811  auto rv = GetEncryptionAlgorithm()->EvalMultMany(ct, ek);
1812  return rv;
1813  }
1814 
1823  Ciphertext<Element> EvalAddMany(
1824  const vector<Ciphertext<Element>>& ctList) const {
1825  // input parameter check
1826  if (!ctList.size())
1827  PALISADE_THROW(type_error, "Empty input ciphertext vector");
1828 
1829  if (ctList.size() == 1){
1830  return ctList[0];
1831  }
1832  auto rv = GetEncryptionAlgorithm()->EvalAddMany(ctList);
1833  return rv;
1834  }
1835 
1847  Ciphertext<Element> EvalAddManyInPlace(
1848  vector<Ciphertext<Element>>& ctList) const {
1849  // input parameter check
1850  if (!ctList.size())
1851  PALISADE_THROW(type_error, "Empty input ciphertext vector");
1852 
1853  auto rv = GetEncryptionAlgorithm()->EvalAddManyInPlace(ctList);
1854  return rv;
1855  }
1856 
1868  Ciphertext<Element> EvalMultAndRelinearize(
1869  ConstCiphertext<Element> ct1, ConstCiphertext<Element> ct2) const {
1870  // input parameter check
1871  if (!ct1 || !ct2) PALISADE_THROW(type_error, "Input ciphertext is nullptr");
1872 
1873  const auto ek = GetEvalMultKeyVector(ct1->GetKeyTag());
1874  if (ek.size() <
1875  (ct1->GetElements().size() + ct2->GetElements().size() - 3)) {
1876  PALISADE_THROW(type_error,
1877  "Insufficient value was used for maxDepth to generate "
1878  "keys for EvalMult");
1879  }
1880 
1881  auto rv = GetEncryptionAlgorithm()->EvalMultAndRelinearize(ct1, ct2, ek);
1882  return rv;
1883  }
1884 
1892  Ciphertext<Element> Relinearize(ConstCiphertext<Element> ct) const {
1893  // input parameter check
1894  if (!ct) PALISADE_THROW(type_error, "Input ciphertext is nullptr");
1895 
1896  const auto ek = GetEvalMultKeyVector(ct->GetKeyTag());
1897 
1898  if (ek.size() < (ct->GetElements().size() - 2)) {
1899  PALISADE_THROW(type_error,
1900  "Insufficient value was used for maxDepth to generate "
1901  "keys for EvalMult");
1902  }
1903 
1904  auto rv = GetEncryptionAlgorithm()->Relinearize(ct, ek);
1905  return rv;
1906  }
1907 
1915  void RelinearizeInPlace(Ciphertext<Element> &ct) const {
1916  // input parameter check
1917  if (!ct)
1918  PALISADE_THROW(type_error, "Input ciphertext is nullptr");
1919 
1920  const auto ek = GetEvalMultKeyVector(ct->GetKeyTag());
1921  if (ek.size() < (ct->GetElements().size() - 2)) {
1922  PALISADE_THROW(type_error,
1923  "Insufficient value was used for maxDepth to generate "
1924  "keys for EvalMult");
1925  }
1926 
1927  GetEncryptionAlgorithm()->RelinearizeInPlace(ct, ek);
1928  }
1929 
1936  inline Ciphertext<Element> EvalMult(ConstPlaintext pt2,
1937  ConstCiphertext<Element> ct1) const {
1938  return EvalMult(ct1, pt2);
1939  }
1940 
1947  inline Ciphertext<Element> EvalMultMutable(Plaintext pt2,
1948  Ciphertext<Element>& ct1) const {
1949  return EvalMultMutable(ct1, pt2);
1950  }
1951 
1958  inline Ciphertext<Element> EvalMult(double constant,
1959  ConstCiphertext<Element> ct1) const {
1960  return EvalMult(ct1, constant);
1961  }
1962 
1963  inline Ciphertext<Element> EvalMultMutable(double constant,
1964  Ciphertext<Element>& ct1) const {
1965  return EvalMultMutable(ct1, constant);
1966  }
1967 
1974  Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,
1975  ConstPlaintext pt2) const {
1976  TypeCheck(ct1, pt2);
1977 
1978  auto rv = GetEncryptionAlgorithm()->EvalMult(ct1, pt2);
1979  return rv;
1980  }
1981 
1991  Ciphertext<Element> EvalMultMutable(Ciphertext<Element>& ct1,
1992  Plaintext pt2) const {
1993  TypeCheck(ct1, pt2);
1994 
1995  auto rv = GetEncryptionAlgorithm()->EvalMultMutable(ct1, pt2);
1996  return rv;
1997  }
1998 
2005  Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext,
2006  double constant) const {
2007  // input parameter check
2008  if (!ciphertext) {
2009  PALISADE_THROW(type_error, "Input ciphertext is nullptr");
2010  }
2011 
2012  auto rv = GetEncryptionAlgorithm()->EvalMult(ciphertext, constant);
2013  return rv;
2014  }
2015 
2025  Ciphertext<Element> EvalMultMutable(Ciphertext<Element>& ciphertext,
2026  double constant) const {
2027  // input parameter check
2028  if (!ciphertext) {
2029  PALISADE_THROW(type_error, "Input ciphertext is nullptr");
2030  }
2031 
2032  auto rv = GetEncryptionAlgorithm()->EvalMultMutable(ciphertext, constant);
2033  return rv;
2034  }
2035 
2041  Ciphertext<Element> EvalNegate(ConstCiphertext<Element> ct) const {
2042  if (ct == nullptr || Mismatched(ct->GetCryptoContext()))
2043  PALISADE_THROW(config_error,
2044  "Information passed to EvalNegate was not generated with "
2045  "this crypto context");
2046 
2047  auto rv = GetEncryptionAlgorithm()->EvalNegate(ct);
2048  return rv;
2049  }
2050 
2060  shared_ptr<std::map<usint, LPEvalKey<Element>>> EvalAutomorphismKeyGen(
2061  const LPPublicKey<Element> publicKey,
2062  const LPPrivateKey<Element> origPrivateKey,
2063  const std::vector<usint>& indexList) const {
2064  if (publicKey == nullptr || origPrivateKey == nullptr)
2065  PALISADE_THROW(type_error, "Null Keys");
2066  if (!indexList.size())
2067  PALISADE_THROW(config_error, "Input index vector is empty");
2068  if (publicKey->GetCryptoContext().get() != this)
2069  PALISADE_THROW(type_error,
2070  "Key was not created in this CryptoContextImpl");
2071  if (publicKey->GetCryptoContext() != origPrivateKey->GetCryptoContext())
2072  PALISADE_THROW(type_error,
2073  "Keys were not created in the same CryptoContextImpl");
2074 
2075  auto rv = GetEncryptionAlgorithm()->EvalAutomorphismKeyGen(
2076  publicKey, origPrivateKey, indexList);
2077  return rv;
2078  }
2079 
2089  Ciphertext<Element> EvalAutomorphism(
2090  ConstCiphertext<Element> ciphertext, usint i,
2091  const std::map<usint, LPEvalKey<Element>>& evalKeys,
2092  CALLER_INFO_ARGS_HDR) const {
2093  if (nullptr == ciphertext) {
2094  std::string errorMsg(std::string("Input ciphertext is nullptr") +
2095  CALLER_INFO);
2096  PALISADE_THROW(type_error, errorMsg);
2097  }
2098 
2099  if (evalKeys.empty()) {
2100  std::string errorMsg(std::string("Empty input key map") + CALLER_INFO);
2101  PALISADE_THROW(type_error, errorMsg);
2102  }
2103  auto tk = evalKeys.begin()->second;
2104  if (nullptr == tk) {
2105  std::string errorMsg(std::string("Invalid evalKey") + CALLER_INFO);
2106  PALISADE_THROW(type_error, errorMsg);
2107  }
2108 
2109  if (ciphertext->GetCryptoContext().get() != this) {
2110  std::string errorMsg(
2111  std::string("Ciphertext was not created in this CryptoContextImpl") +
2112  CALLER_INFO);
2113  PALISADE_THROW(type_error, errorMsg);
2114  }
2115 
2116  if (ciphertext->GetCryptoContext() != tk->GetCryptoContext()) {
2117  std::string errorMsg(
2118  std::string("Items were not created in the same CryptoContextImpl") +
2119  CALLER_INFO);
2120  PALISADE_THROW(type_error, errorMsg);
2121  }
2122 
2123  if (ciphertext->GetKeyTag() != tk->GetKeyTag()) {
2124  std::string errorMsg(
2125  std::string("Items were not encrypted with same keys") + CALLER_INFO);
2126  PALISADE_THROW(type_error, errorMsg);
2127  }
2128 
2129  auto rv =
2130  GetEncryptionAlgorithm()->EvalAutomorphism(ciphertext, i, evalKeys);
2131  return rv;
2132  }
2133 
2142  shared_ptr<std::map<usint, LPEvalKey<Element>>> EvalAutomorphismKeyGen(
2143  const LPPrivateKey<Element> privateKey,
2144  const std::vector<usint>& indexList) const {
2145  if (privateKey == nullptr) PALISADE_THROW(type_error, "Null input");
2146  if (!indexList.size())
2147  PALISADE_THROW(config_error, "Input index vector is empty");
2148  if (privateKey->GetCryptoContext().get() != this)
2149  PALISADE_THROW(type_error,
2150  "Key was not created in this CryptoContextImpl");
2151 
2152  auto rv =
2153  GetEncryptionAlgorithm()->EvalAutomorphismKeyGen(privateKey, indexList);
2154  return rv;
2155  }
2156 
2163  void EvalSumKeyGen(const LPPrivateKey<Element> privateKey,
2164  const LPPublicKey<Element> publicKey = nullptr);
2165 
2166  shared_ptr<std::map<usint, LPEvalKey<Element>>> EvalSumRowsKeyGen(
2167  const LPPrivateKey<Element> privateKey,
2168  const LPPublicKey<Element> publicKey = nullptr, usint rowSize = 0,
2169  usint subringDim = 0);
2170 
2171  shared_ptr<std::map<usint, LPEvalKey<Element>>> EvalSumColsKeyGen(
2172  const LPPrivateKey<Element> privateKey,
2173  const LPPublicKey<Element> publicKey = nullptr);
2174 
2180  static const std::map<usint, LPEvalKey<Element>>& GetEvalSumKeyMap(
2181  const string& id);
2182 
2183  static std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>&
2184  GetAllEvalSumKeys();
2185 
2193  Ciphertext<Element> EvalSum(ConstCiphertext<Element> ciphertext,
2194  usint batchSize) const;
2195 
2196  Ciphertext<Element> EvalSumRows(
2197  ConstCiphertext<Element> ciphertext, usint rowSize,
2198  const std::map<usint, LPEvalKey<Element>>& evalKeys,
2199  usint subringDim = 0) const;
2200 
2201  Ciphertext<Element> EvalSumCols(
2202  ConstCiphertext<Element> ciphertext, usint rowSize,
2203  const std::map<usint, LPEvalKey<Element>>& evalKeys) const;
2204 
2212  void EvalAtIndexKeyGen(const LPPrivateKey<Element> privateKey,
2213  const std::vector<int32_t>& indexList,
2214  const LPPublicKey<Element> publicKey = nullptr);
2215 
2243  shared_ptr<vector<Element>> EvalFastRotationPrecompute(
2244  ConstCiphertext<Element> ct) const {
2245  auto rv = GetEncryptionAlgorithm()->EvalFastRotationPrecompute(ct);
2246  return rv;
2247  }
2248 
2285  Ciphertext<Element> EvalFastRotation(
2286  ConstCiphertext<Element> ct, const usint index, const usint m,
2287  const shared_ptr<vector<Element>> digits) const {
2288  auto rv = GetEncryptionAlgorithm()->EvalFastRotation(ct, index, m, digits);
2289  return rv;
2290  }
2291 
2302  Ciphertext<Element> EvalMerge(
2303  const vector<Ciphertext<Element>>& ciphertextVector) const;
2304 
2310  static const std::map<usint, LPEvalKey<Element>>& GetEvalAutomorphismKeyMap(
2311  const string& id);
2312 
2313  static std::map<string, shared_ptr<std::map<usint, LPEvalKey<Element>>>>&
2314  GetAllEvalAutomorphismKeys();
2315 
2323  Ciphertext<Element> EvalAtIndex(ConstCiphertext<Element> ciphertext,
2324  int32_t index) const;
2325 
2334  Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext1,
2335  ConstCiphertext<Element> ciphertext2,
2336  usint batchSize) const;
2337 
2346  Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext1,
2347  ConstPlaintext plaintext,
2348  usint batchSize) const;
2349 
2359  virtual Ciphertext<Element> EvalPoly(
2360  ConstCiphertext<Element> ciphertext,
2361  const std::vector<double>& coefficients) const {
2362  if (ciphertext == nullptr ||
2363  this->Mismatched(ciphertext->GetCryptoContext()))
2364  throw std::logic_error(
2365  "Information passed to EvalPoly was not generated with this crypto "
2366  "context");
2367 
2368  auto rv = std::static_pointer_cast<LPPublicKeyEncryptionScheme<Element>>(
2369  this->GetEncryptionAlgorithm())
2370  ->EvalPoly(ciphertext, coefficients);
2371  return rv;
2372  }
2373 
2380  Ciphertext<Element> KeySwitch(const LPEvalKey<Element> keySwitchHint,
2381  ConstCiphertext<Element> ciphertext) const {
2382  if (keySwitchHint == nullptr ||
2383  Mismatched(keySwitchHint->GetCryptoContext()))
2384  PALISADE_THROW(
2385  config_error,
2386  "Key passed to KeySwitch was not generated with this crypto context");
2387 
2388  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
2389  PALISADE_THROW(config_error,
2390  "Ciphertext passed to KeySwitch was not generated with "
2391  "this crypto context");
2392 
2393  auto rv = GetEncryptionAlgorithm()->KeySwitch(keySwitchHint, ciphertext);
2394  return rv;
2395  }
2396 
2402  void KeySwitchInPlace(const LPEvalKey<Element> keySwitchHint,
2403  Ciphertext<Element>& ciphertext) const {
2404  if (keySwitchHint == nullptr ||
2405  Mismatched(keySwitchHint->GetCryptoContext()))
2406  PALISADE_THROW(config_error,
2407  "Key passed to KeySwitchInPlace was not generated with "
2408  "this crypto context");
2409 
2410  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
2411  PALISADE_THROW(
2412  config_error,
2413  "Ciphertext passed to KeySwitchInPlace was not generated with "
2414  "this crypto context");
2415 
2416  GetEncryptionAlgorithm()->KeySwitchInPlace(keySwitchHint, ciphertext);
2417  }
2418 
2426  Ciphertext<Element> Rescale(ConstCiphertext<Element> ciphertext) const {
2427  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
2428  PALISADE_THROW(config_error,
2429  "Information passed to Rescale was not generated with "
2430  "this crypto context");
2431 
2432  auto rv = GetEncryptionAlgorithm()->ModReduce(ciphertext);
2433  return rv;
2434  }
2435 
2442  void RescaleInPlace(Ciphertext<Element>& ciphertext) const {
2443  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
2444  PALISADE_THROW(
2445  config_error,
2446  "Information passed to RescaleInPlace was not generated with "
2447  "this crypto context");
2448 
2449  GetEncryptionAlgorithm()->ModReduceInPlace(ciphertext);
2450  }
2451 
2457  Ciphertext<Element> ModReduce(ConstCiphertext<Element> ciphertext) const {
2458  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
2459  PALISADE_THROW(
2461  "Information passed to ModReduce was not generated with this crypto "
2462  "context");
2463 
2464  auto rv = GetEncryptionAlgorithm()->ModReduce(ciphertext);
2465  return rv;
2466  }
2467 
2472  void ModReduceInPlace(Ciphertext<Element>& ciphertext) const {
2473  if (ciphertext == nullptr || Mismatched(ciphertext->GetCryptoContext()))
2474  PALISADE_THROW(
2476  "Information passed to ModReduce was not generated with this crypto "
2477  "context");
2478 
2479  GetEncryptionAlgorithm()->ModReduceInPlace(ciphertext);
2480  }
2481 
2488  Ciphertext<Element> LevelReduce(ConstCiphertext<Element> cipherText1,
2489  const LPEvalKey<Element> linearKeySwitchHint,
2490  size_t levels = 1) const {
2491  const auto cryptoParams =
2492  std::dynamic_pointer_cast<LPCryptoParametersCKKS<DCRTPoly>>(
2493  cipherText1->GetCryptoParameters());
2494 
2495  if (cipherText1 == nullptr || Mismatched(cipherText1->GetCryptoContext())) {
2496  PALISADE_THROW(config_error,
2497  "Information passed to LevelReduce was not generated with "
2498  "this crypto context");
2499  }
2500 
2501  auto rv = GetEncryptionAlgorithm()->LevelReduce(
2502  cipherText1, linearKeySwitchHint, levels);
2503  return rv;
2504  }
2505 
2513  Ciphertext<Element> ComposedEvalMult(
2514  ConstCiphertext<Element> ciphertext1,
2515  ConstCiphertext<Element> ciphertext2) const {
2516  if (ciphertext1 == nullptr || ciphertext2 == nullptr ||
2517  ciphertext1->GetKeyTag() != ciphertext2->GetKeyTag() ||
2518  Mismatched(ciphertext1->GetCryptoContext()))
2519  PALISADE_THROW(config_error,
2520  "Ciphertexts passed to ComposedEvalMult were not "
2521  "generated with this crypto context");
2522 
2523  auto ek = GetEvalMultKeyVector(ciphertext1->GetKeyTag());
2524  if (!ek.size()) {
2525  PALISADE_THROW(type_error,
2526  "Evaluation key has not been generated for EvalMult");
2527  }
2528 
2529  auto rv = GetEncryptionAlgorithm()->ComposedEvalMult(ciphertext1,
2530  ciphertext2, ek[0]);
2531  return rv;
2532  }
2533 
2541  Ciphertext<Element> Compress(ConstCiphertext<Element> ciphertext1,
2542  uint32_t numTowers = 1) const {
2543  if (ciphertext1 == nullptr)
2544  PALISADE_THROW(config_error, "input ciphertext is invalid (has no data)");
2545 
2546  auto ct = GetEncryptionAlgorithm()->Compress(ciphertext1, numTowers);
2547  return ct;
2548  }
2549 
2550  template <class Archive>
2551  void save(Archive& ar, std::uint32_t const version) const {
2552  ar(cereal::make_nvp("cc", params));
2553  ar(cereal::make_nvp("kt", scheme));
2554  ar(cereal::make_nvp("si", m_schemeId));
2555  }
2556 
2557  template <class Archive>
2558  void load(Archive& ar, std::uint32_t const version) {
2559  if (version > SerializedVersion()) {
2560  PALISADE_THROW(deserialize_error,
2561  "serialized object version " + std::to_string(version) +
2562  " is from a later version of the library");
2563  }
2564  ar(cereal::make_nvp("cc", params));
2565  ar(cereal::make_nvp("kt", scheme));
2566  ar(cereal::make_nvp("si", m_schemeId));
2567 
2568  // NOTE: a pointer to this object will be wrapped in a shared_ptr, and is a
2569  // "CryptoContext". PALISADE relies on the notion that identical
2570  // CryptoContextImpls are not duplicated in memory Once we deserialize this
2571  // object, we must check to see if there is a matching object for this
2572  // object that's already existing in memory if it DOES exist, use it. If it
2573  // does NOT exist, add this to the cache of all contexts
2574  }
2575 
2576  virtual std::string SerializedObjectName() const { return "CryptoContext"; }
2577  static uint32_t SerializedVersion() { return 1; }
2578 };
2579 
2585 template <typename Element>
2587  protected:
2588  CryptoContext<Element> context; // crypto context this object belongs to
2589  // tag used to find the evaluation key needed
2590  // for SHE/FHE operations
2591  string keyTag;
2592 
2593  public:
2594  explicit CryptoObject(CryptoContext<Element> cc = nullptr,
2595  const string& tag = "")
2596  : context(cc), keyTag(tag) {}
2597 
2598  CryptoObject(const CryptoObject& rhs) {
2599  context = rhs.context;
2600  keyTag = rhs.keyTag;
2601  }
2602 
2603  CryptoObject(const CryptoObject&& rhs) {
2604  context = std::move(rhs.context);
2605  keyTag = std::move(rhs.keyTag);
2606  }
2607 
2608  virtual ~CryptoObject() {}
2609 
2610  const CryptoObject& operator=(const CryptoObject& rhs) {
2611  this->context = rhs.context;
2612  this->keyTag = rhs.keyTag;
2613  return *this;
2614  }
2615 
2616  const CryptoObject& operator=(const CryptoObject&& rhs) {
2617  this->context = std::move(rhs.context);
2618  this->keyTag = std::move(rhs.keyTag);
2619  return *this;
2620  }
2621 
2622  bool operator==(const CryptoObject& rhs) const {
2623  return context.get() == rhs.context.get() && keyTag == rhs.keyTag;
2624  }
2625 
2626  CryptoContext<Element> GetCryptoContext() const { return context; }
2627 
2628  const shared_ptr<LPCryptoParameters<Element>> GetCryptoParameters() const {
2629  return context->GetCryptoParameters();
2630  }
2631 
2632  const EncodingParams GetEncodingParameters() const {
2633  return context->GetCryptoParameters()->GetEncodingParams();
2634  }
2635 
2636  const string GetKeyTag() const { return keyTag; }
2637 
2638  void SetKeyTag(const string& tag) { keyTag = tag; }
2639 
2640  template <class Archive>
2641  void save(Archive& ar, std::uint32_t const version) const {
2642  ar(::cereal::make_nvp("cc", context));
2643  ar(::cereal::make_nvp("kt", keyTag));
2644  }
2645 
2646  template <class Archive>
2647  void load(Archive& ar, std::uint32_t const version) {
2648  if (version > SerializedVersion()) {
2649  PALISADE_THROW(deserialize_error,
2650  "serialized object version " + std::to_string(version) +
2651  " is from a later version of the library");
2652  }
2653  ar(::cereal::make_nvp("cc", context));
2654  ar(::cereal::make_nvp("kt", keyTag));
2655 
2657  context->GetCryptoParameters(),
2658  context->GetEncryptionAlgorithm(),
2659  context->getSchemeId()
2660  );
2661  }
2662 
2663  std::string SerializedObjectName() const { return "CryptoObject"; }
2664  static uint32_t SerializedVersion() { return 1; }
2665 };
2666 
2674 template <typename Element>
2675 class CryptoContextFactory {
2676  using ParmType = typename Element::Params;
2677  using IntType = typename Element::Integer;
2678 
2679  protected:
2680  static vector<CryptoContext<Element>> AllContexts;
2681 
2682  public:
2683  static void ReleaseAllContexts();
2684 
2685  static int GetContextCount();
2686 
2687  static CryptoContext<Element> GetSingleContext();
2688 
2689  static CryptoContext<Element> GetContext(
2690  shared_ptr<LPCryptoParameters<Element>> params,
2691  shared_ptr<LPPublicKeyEncryptionScheme<Element>> scheme,
2692  const string& schemeId = "Not");
2693 
2694  static CryptoContext<Element> GetContextForPointer(
2696 
2697  static const vector<CryptoContext<Element>>& GetAllContexts();
2698 
2724  static CryptoContext<Element> genCryptoContextBFV(
2725  shared_ptr<ParmType> params, const PlaintextModulus plaintextmodulus,
2726  usint relinWindow, float stDev, const std::string& delta,
2727  MODE mode = RLWE, const std::string& bigmodulus = "0",
2728  const std::string& bigrootofunity = "0", int depth = 0,
2729  int assuranceMeasure = 0, float securityLevel = 0,
2730  const std::string& bigmodulusarb = "0",
2731  const std::string& bigrootofunityarb = "0", int maxDepth = 2);
2732 
2758  static CryptoContext<Element> genCryptoContextBFV(
2759  shared_ptr<ParmType> params, EncodingParams encodingParams,
2760  usint relinWindow, float stDev, const std::string& delta,
2761  MODE mode = RLWE, const std::string& bigmodulus = "0",
2762  const std::string& bigrootofunity = "0", int depth = 0,
2763  int assuranceMeasure = 0, float securityLevel = 0,
2764  const std::string& bigmodulusarb = "0",
2765  const std::string& bigrootofunityarb = "0", int maxDepth = 2);
2766 
2791  static CryptoContext<Element> genCryptoContextBFV(
2792  const PlaintextModulus plaintextModulus, float securityLevel,
2793  usint relinWindow, float dist, unsigned int numAdds,
2794  unsigned int numMults, unsigned int numKeyswitches, MODE mode = OPTIMIZED,
2795  int maxDepth = 2, uint32_t n = 0);
2796 
2821  static CryptoContext<Element> genCryptoContextBFV(
2822  const PlaintextModulus plaintextModulus, SecurityLevel securityLevel,
2823  usint relinWindow, float dist, unsigned int numAdds,
2824  unsigned int numMults, unsigned int numKeyswitches, MODE mode = OPTIMIZED,
2825  int maxDepth = 2, uint32_t n = 0);
2826 
2849  static CryptoContext<Element> genCryptoContextBFV(
2850  EncodingParams encodingParams, float securityLevel, usint relinWindow,
2851  float dist, unsigned int numAdds, unsigned int numMults,
2852  unsigned int numKeyswitches, MODE mode = OPTIMIZED, int maxDepth = 2,
2853  uint32_t n = 0);
2854 
2877  static CryptoContext<Element> genCryptoContextBFV(
2878  EncodingParams encodingParams, SecurityLevel securityLevel,
2879  usint relinWindow, float dist, unsigned int numAdds,
2880  unsigned int numMults, unsigned int numKeyswitches, MODE mode = OPTIMIZED,
2881  int maxDepth = 2, uint32_t n = 0);
2882 
2908  static CryptoContext<Element> genCryptoContextBFVrns(
2909  const PlaintextModulus plaintextModulus, float securityLevel, float dist,
2910  unsigned int numAdds, unsigned int numMults, unsigned int numKeyswitches,
2911  MODE mode = OPTIMIZED, int maxDepth = 2, uint32_t relinWindow = 0,
2912  size_t dcrtBits = 60, uint32_t n = 0);
2913 
2939  static CryptoContext<Element> genCryptoContextBFVrns(
2940  const PlaintextModulus plaintextModulus, SecurityLevel securityLevel,
2941  float dist, unsigned int numAdds, unsigned int numMults,
2942  unsigned int numKeyswitches, MODE mode = OPTIMIZED, int maxDepth = 2,
2943  uint32_t relinWindow = 0, size_t dcrtBits = 60, uint32_t n = 0);
2944 
2970  static CryptoContext<Element> genCryptoContextBFVrns(
2971  EncodingParams encodingParams, float securityLevel, float dist,
2972  unsigned int numAdds, unsigned int numMults, unsigned int numKeyswitches,
2973  MODE mode = OPTIMIZED, int maxDepth = 2, uint32_t relinWindow = 0,
2974  size_t dcrtBits = 60, uint32_t n = 0);
2975 
3001  static CryptoContext<Element> genCryptoContextBFVrns(
3002  EncodingParams encodingParams, SecurityLevel securityLevel, float dist,
3003  unsigned int numAdds, unsigned int numMults, unsigned int numKeyswitches,
3004  MODE mode = OPTIMIZED, int maxDepth = 2, uint32_t relinWindow = 0,
3005  size_t dcrtBits = 60, uint32_t n = 0);
3006 
3032  static CryptoContext<Element> genCryptoContextBFVrnsB(
3033  const PlaintextModulus plaintextModulus, float securityLevel, float dist,
3034  unsigned int numAdds, unsigned int numMults, unsigned int numKeyswitches,
3035  MODE mode = OPTIMIZED, int maxDepth = 2, uint32_t relinWindow = 0,
3036  size_t dcrtBits = 60, uint32_t n = 0);
3037 
3063  static CryptoContext<Element> genCryptoContextBFVrnsB(
3064  const PlaintextModulus plaintextModulus, SecurityLevel securityLevel,
3065  float dist, unsigned int numAdds, unsigned int numMults,
3066  unsigned int numKeyswitches, MODE mode = OPTIMIZED, int maxDepth = 2,
3067  uint32_t relinWindow = 0, size_t dcrtBits = 60, uint32_t = 0);
3068 
3094  static CryptoContext<Element> genCryptoContextBFVrnsB(
3095  EncodingParams encodingParams, float securityLevel, float dist,
3096  unsigned int numAdds, unsigned int numMults, unsigned int numKeyswitches,
3097  MODE mode = OPTIMIZED, int maxDepth = 2, uint32_t relinWindow = 0,
3098  size_t dcrtBits = 60, uint32_t n = 0);
3099 
3125  static CryptoContext<Element> genCryptoContextBFVrnsB(
3126  EncodingParams encodingParams, SecurityLevel securityLevel, float dist,
3127  unsigned int numAdds, unsigned int numMults, unsigned int numKeyswitches,
3128  MODE mode = OPTIMIZED, int maxDepth = 2, uint32_t relinWindow = 0,
3129  size_t dcrtBits = 60, uint32_t n = 0);
3130 
3148  static CryptoContext<Element> genCryptoContextCKKS(
3149  shared_ptr<ParmType> params, const PlaintextModulus plaintextmodulus,
3150  usint relinWindow, float stDev, MODE mode = RLWE, int depth = 1,
3151  int maxDepth = 2, KeySwitchTechnique ksTech = BV,
3152  RescalingTechnique rsTech = APPROXRESCALE);
3153 
3170  static CryptoContext<Element> genCryptoContextCKKS(
3171  shared_ptr<ParmType> params, EncodingParams encodingParams,
3172  usint relinWindow, float stDev, MODE mode = RLWE, int depth = 1,
3173  int maxDepth = 2, enum KeySwitchTechnique ksTech = BV,
3174  RescalingTechnique rsTech = APPROXRESCALE);
3175 
3198  static CryptoContext<Element> genCryptoContextCKKSWithParamsGen(
3199  usint cyclOrder, usint numPrimes, usint scaleExp, usint relinWindow,
3200  usint batchSize, MODE mode, int depth = 1, int maxDepth = 2,
3201  usint firstModSize = FIRSTMODSIZE, enum KeySwitchTechnique ksTech = BV,
3202  enum RescalingTechnique rsTech = APPROXRESCALE,
3203  uint32_t numLargeDigits = 4);
3204 
3229  static CryptoContext<Element> genCryptoContextCKKS(
3230  usint multiplicativeDepth, usint scalingFactorBits, usint batchSize,
3231  SecurityLevel stdLevel = HEStd_128_classic, usint ringDim = 0,
3232  enum RescalingTechnique rsTech = DEFAULTRSTECH,
3233  enum KeySwitchTechnique ksTech = HYBRID, uint32_t numLargeDigits = 0,
3234  int maxDepth = 2, usint firstModSize = FIRSTMODSIZE,
3235  usint relinWindow = 0, MODE mode = OPTIMIZED);
3236 
3253  static CryptoContext<Element> genCryptoContextBGVrns(
3254  shared_ptr<ParmType> params, const PlaintextModulus plaintextmodulus,
3255  usint relinWindow, float stDev, MODE mode = RLWE, int depth = 1,
3256  int maxDepth = 2, KeySwitchTechnique ksTech = BV,
3257  enum ModSwitchMethod msMethod = MANUAL);
3258 
3274  static CryptoContext<Element> genCryptoContextBGVrns(
3275  shared_ptr<ParmType> params, EncodingParams encodingParams,
3276  usint relinWindow, float stDev, MODE mode = RLWE, int depth = 1,
3277  int maxDepth = 2, enum KeySwitchTechnique ksTech = BV,
3278  enum ModSwitchMethod msMethod = MANUAL);
3279 
3301  static CryptoContext<Element> genCryptoContextBGVrnsWithParamsGen(
3302  usint cyclOrder, usint numPrimes, usint ptm, usint relinWindow, MODE mode,
3303  int depth = 1, int maxDepth = 2, enum KeySwitchTechnique ksTech = BV,
3304  usint firstModSize = 0, usint dcrtBits = 0, uint32_t numLargeDigits = 4,
3305  usint batchSize = 0, enum ModSwitchMethod msMethod = MANUAL);
3306 
3332  static CryptoContext<Element> genCryptoContextBGVrns(
3333  usint multiplicativeDepth, usint ptm,
3334  SecurityLevel stdLevel = HEStd_128_classic, float stdDev = 3.19,
3335  int maxDepth = 2, MODE mode = OPTIMIZED,
3336  enum KeySwitchTechnique ksTech = HYBRID, usint ringDim = 0,
3337  uint32_t numLargeDigits = 0, usint firstModSize = 0, usint dcrtBits = 0,
3338  usint relinWindow = 0, usint batchSize = 0,
3339  enum ModSwitchMethod msMethod = AUTO);
3340 
3348  static CryptoContext<Element> genCryptoContextNull(
3349  unsigned int m, const PlaintextModulus ptModulus);
3350 
3358  static CryptoContext<Element> genCryptoContextNull(
3359  unsigned int m, EncodingParams encodingParams);
3360 
3361 };
3362 
3363 } // namespace lbcrypto
3364 
3365 #endif /* SRC_PKE_CRYPTOCONTEXT_H_ */
Ciphertext< Element > EvalAddManyInPlace(vector< Ciphertext< Element >> &ctList) const
Definition: cryptocontext.h:1847
Base class for PALISADE serialization.
Definition: serializable.h:76
Ciphertext< Element > EvalLinearWSumMutable(vector< Ciphertext< Element >> ciphertexts, vector< double > constants) const
Definition: cryptocontext.h:1623
CryptoContextImpl.
Definition: cryptocontext.h:56
CryptoContextImpl(LPCryptoParameters< Element > *params=nullptr, LPPublicKeyEncryptionScheme< Element > *scheme=nullptr, const string &schemeId="Not")
Definition: cryptocontext.h:323
Ciphertext< Element > Relinearize(ConstCiphertext< Element > ct) const
Definition: cryptocontext.h:1892
Ciphertext< Element > EvalAdd(ConstCiphertext< Element > ciphertext, double constant) const
Definition: cryptocontext.h:1587
Ciphertext< Element > EvalMultMutable(Ciphertext< Element > &ct1, Ciphertext< Element > &ct2) const
Definition: cryptocontext.h:1753
Decryption result. This represents whether the decryption of a cipheretext was performed correctly...
Definition: pubkeylp.h:105
Ciphertext< Element > EvalMultMutable(Plaintext pt2, Ciphertext< Element > &ct1) const
Definition: cryptocontext.h:1947
LPEvalKey< Element > KeySwitchGen(const LPPrivateKey< Element > key1, const LPPrivateKey< Element > key2) const
Definition: cryptocontext.h:1221
Ciphertext< Element > EvalSub(ConstCiphertext< Element > ciphertext, double constant) const
Definition: cryptocontext.h:1692
static const vector< LPEvalKey< Element > > & GetEvalMultKeyVector(const string &keyID)
Definition: cryptocontext.cpp:61
void RescaleInPlace(Ciphertext< Element > &ciphertext) const
Definition: cryptocontext.h:2442
Ciphertext< Element > EvalAddMany(const vector< Ciphertext< Element >> &ctList) const
Definition: cryptocontext.h:1823
CryptoContextImpl(const CryptoContextImpl< Element > &c)
Definition: cryptocontext.h:350
const shared_ptr< LPCryptoParameters< Element > > GetCryptoParameters() const
Definition: cryptocontext.h:733
void KeySwitchInPlace(const LPEvalKey< Element > keySwitchHint, Ciphertext< Element > &ciphertext) const
Definition: cryptocontext.h:2402
Ciphertext< Element > EvalMultMany(const vector< Ciphertext< Element >> &ct) const
Definition: cryptocontext.h:1795
Ciphertext< Element > EvalFastRotation(ConstCiphertext< Element > ct, const usint index, const usint m, const shared_ptr< vector< Element >> digits) const
Definition: cryptocontext.h:2285
Plaintext MakeStringPlaintext(const string &str) const
Definition: cryptocontext.h:1301
static bool DeserializeEvalAutomorphismKey(std::istream &ser, const ST &sertype)
Definition: cryptocontext.h:663
Ciphertext< Element > EvalLinearWSum(vector< Ciphertext< Element >> ciphertexts, vector< double > constants) const
Definition: cryptocontext.h:1608
static void ClearEvalAutomorphismKeys()
Definition: cryptocontext.cpp:286
Ciphertext< Element > EvalSub(ConstCiphertext< Element > ct1, ConstCiphertext< Element > ct2) const
Definition: cryptocontext.h:1521
CryptoContextFactory.
Definition: cryptocontext.h:53
static bool SerializeEvalSumKey(std::ostream &ser, const ST &sertype, string id="")
Definition: cryptocontext.h:506
shared_ptr< std::map< usint, LPEvalKey< Element > > > MultiAddEvalAutomorphismKeys(const shared_ptr< std::map< usint, LPEvalKey< Element >>> es1, const shared_ptr< std::map< usint, LPEvalKey< Element >>> es2, const std::string &keyId="")
Definition: cryptocontext.h:1085
void ModReduceInPlace(Ciphertext< Element > &ciphertext) const
Definition: cryptocontext.h:2472
LPEvalKey< Element > MultiMultEvalKey(LPEvalKey< Element > evalKey, LPPrivateKey< Element > sk, const std::string &keyId="")
Definition: cryptocontext.h:1046
Definition: exception.h:133
CryptoObject.
Definition: cryptocontext.h:2586
void RelinearizeInPlace(Ciphertext< Element > &ct) const
Definition: cryptocontext.h:1915
Ciphertext< Element > EvalSub(ConstCiphertext< Element > ciphertext, ConstPlaintext plaintext) const
Definition: cryptocontext.h:1661
shared_ptr< vector< Element > > EvalFastRotationPrecompute(ConstCiphertext< Element > ct) const
Definition: cryptocontext.h:2243
LPKeyPair< Element > KeyGen()
Definition: cryptocontext.h:797
static void InsertEvalSumKey(const shared_ptr< std::map< usint, LPEvalKey< Element >>> mapToInsert)
Definition: cryptocontext.cpp:235
friend bool operator==(const CryptoContextImpl< Element > &a, const CryptoContextImpl< Element > &b)
Definition: cryptocontext.h:382
Definition: exception.h:147
Ciphertext< Element > EvalAddMutable(Ciphertext< Element > &ciphertext, Plaintext plaintext) const
Definition: cryptocontext.h:1571
Ciphertext< Element > Encrypt(const LPPrivateKey< Element > privateKey, Plaintext plaintext) const
Definition: cryptocontext.h:1272
Ciphertext< Element > EvalMult(ConstPlaintext pt2, ConstCiphertext< Element > ct1) const
Definition: cryptocontext.h:1936
static Plaintext MakePlaintext(PlaintextEncodings encoding, CryptoContext< Element > cc, const Value1 &value)
Definition: cryptocontext.h:1337
CryptoContextImpl< Element > & operator=(const CryptoContextImpl< Element > &rhs)
Definition: cryptocontext.h:362
static std::map< string, std::vector< LPEvalKey< Element > > > & GetAllEvalMultKeys()
Definition: cryptocontext.cpp:72
static const std::map< usint, LPEvalKey< Element > > & GetEvalAutomorphismKeyMap(const string &id)
Definition: cryptocontext.cpp:270
vector< Ciphertext< Element > > MultipartyDecryptMain(const LPPrivateKey< Element > privateKey, const vector< Ciphertext< Element >> &ciphertext) const
Definition: cryptocontext.h:882
LPEvalKey< Element > MultiAddEvalMultKeys(LPEvalKey< Element > evalKey1, LPEvalKey< Element > evalKey2, const std::string &keyId="")
Definition: cryptocontext.h:1127
LPEvalKey< Element > ReKeyGen(const LPPublicKey< Element > newKey, const LPPrivateKey< Element > oldKey) const
Definition: cryptocontext.h:1156
DecryptResult Decrypt(const LPPrivateKey< Element > privateKey, ConstCiphertext< Element > ciphertext, Plaintext *plaintext)
Definition: cryptocontext.cpp:464
static void ClearEvalSumKeys()
Definition: cryptocontext.cpp:203
Ciphertext< Element > EvalSubMutable(Ciphertext< Element > &ciphertext, Plaintext plaintext) const
Definition: cryptocontext.h:1678
const IntType & GetModulus() const
Definition: cryptocontext.h:780
static bool DeserializeEvalSumKey(std::istream &ser, const ST &sertype)
Definition: cryptocontext.h:560
static bool SerializeEvalMultKey(std::ostream &ser, const ST &sertype, const CryptoContext< Element > cc)
Definition: cryptocontext.h:433
Ciphertext< Element > Encrypt(const LPPublicKey< Element > publicKey, Plaintext plaintext)
Definition: cryptocontext.h:1240
Ciphertext< Element > EvalAdd(ConstCiphertext< Element > ciphertext, ConstPlaintext plaintext) const
Definition: cryptocontext.h:1552
void EvalAddInPlace(Ciphertext< Element > &ct1, ConstCiphertext< Element > ct2) const
Definition: cryptocontext.h:1491
vector< Ciphertext< Element > > MultipartyDecryptLead(const LPPrivateKey< Element > privateKey, const vector< Ciphertext< Element >> &ciphertext) const
Definition: cryptocontext.h:851
shared_ptr< std::map< usint, LPEvalKey< Element > > > MultiEvalSumKeyGen(const LPPrivateKey< Element > privateKey, const shared_ptr< std::map< usint, LPEvalKey< Element >>> eSum, const std::string &keyId="")
Definition: cryptocontext.h:1004
Ciphertext< Element > KeySwitch(const LPEvalKey< Element > keySwitchHint, ConstCiphertext< Element > ciphertext) const
Definition: cryptocontext.h:2380
CryptoContextImpl(shared_ptr< LPCryptoParameters< Element >> params, shared_ptr< LPPublicKeyEncryptionScheme< Element >> scheme, const string &schemeId="Not")
Definition: cryptocontext.h:337
Ciphertext< Element > EvalAdd(ConstCiphertext< Element > ct1, ConstCiphertext< Element > ct2) const
Definition: cryptocontext.h:1477
void TypeCheck(ConstCiphertext< Element > a, ConstPlaintext b, CALLER_INFO_ARGS_HDR) const
Definition: cryptocontext.h:207
static void InsertEvalAutomorphismKey(const shared_ptr< std::map< usint, LPEvalKey< Element >>> mapToInsert)
Definition: cryptocontext.cpp:319
Ciphertext< Element > Compress(ConstCiphertext< Element > ciphertext1, uint32_t numTowers=1) const
Definition: cryptocontext.h:2541
LPEvalKey< Element > MultiKeySwitchGen(const LPPrivateKey< Element > originalPrivateKey, const LPPrivateKey< Element > newPrivateKey, const LPEvalKey< Element > ek) const
Definition: cryptocontext.h:928
static bool SerializeEvalSumKey(std::ostream &ser, const ST &sertype, const CryptoContext< Element > cc)
Definition: cryptocontext.h:534
const EncodingParams GetEncodingParams() const
Definition: cryptocontext.h:753
Ciphertext< Element > EvalMult(ConstCiphertext< Element > ciphertext, double constant) const
Definition: cryptocontext.h:2005
Ciphertext< Element > EvalInnerProduct(ConstCiphertext< Element > ciphertext1, ConstCiphertext< Element > ciphertext2, usint batchSize) const
Definition: cryptocontext.cpp:417
static Plaintext GetPlaintextForDecrypt(PlaintextEncodings pte, shared_ptr< ParmType > evp, EncodingParams ep)
Definition: cryptocontext.cpp:453
usint GetCyclotomicOrder() const
Definition: cryptocontext.h:762
const shared_ptr< LPPublicKeyEncryptionScheme< Element > > GetEncryptionAlgorithm() const
Definition: cryptocontext.h:725
Ciphertext< Element > EvalMultMutable(Ciphertext< Element > &ct1, Plaintext pt2) const
Definition: cryptocontext.h:1991
void SetPrivateKey(const LPPrivateKey< Element > sk)
Definition: cryptocontext.h:267
virtual Plaintext MakeCKKSPackedPlaintext(const std::vector< std::complex< double >> &value, size_t depth=1, uint32_t level=0, const shared_ptr< ParmType > params=nullptr) const
Definition: cryptocontext.h:1364
Ciphertext< Element > EvalAtIndex(ConstCiphertext< Element > ciphertext, int32_t index) const
Definition: cryptocontext.cpp:374
void EvalMultKeysGen(const LPPrivateKey< Element > key)
Definition: cryptocontext.cpp:46
const shared_ptr< ParmType > GetElementParams() const
Definition: cryptocontext.h:745
void EvalAtIndexKeyGen(const LPPrivateKey< Element > privateKey, const std::vector< int32_t > &indexList, const LPPublicKey< Element > publicKey=nullptr)
Definition: cryptocontext.cpp:245
static bool SerializeEvalMultKey(std::ostream &ser, const ST &sertype, string id="")
Definition: cryptocontext-ser.h:55
const IntType & GetRootOfUnity() const
Definition: cryptocontext.h:789
static bool SerializeEvalAutomorphismKey(std::ostream &ser, const ST &sertype, const CryptoContext< Element > cc)
Definition: cryptocontext.h:638
LPKeyPair< Element > MultipartyKeyGen(const vector< LPPrivateKey< Element >> &secretKeys)
Definition: cryptocontext.h:834
void Enable(usint featureMask)
Definition: cryptocontext.h:717
Ciphertext< Element > EvalMultAndRelinearize(ConstCiphertext< Element > ct1, ConstCiphertext< Element > ct2) const
Definition: cryptocontext.h:1868
virtual Ciphertext< Element > EvalPoly(ConstCiphertext< Element > ciphertext, const std::vector< double > &coefficients) const
Definition: cryptocontext.h:2359
LPKeyPair< Element > MultipartyKeyGen(const LPPublicKey< Element > pk, bool makeSparse=false, bool fresh=false)
Definition: cryptocontext.h:816
static const std::map< usint, LPEvalKey< Element > > & GetEvalSumKeyMap(const string &id)
Definition: cryptocontext.cpp:187
virtual Plaintext MakeCKKSPackedPlaintext(const std::vector< double > &value, size_t depth=1, uint32_t level=0, const shared_ptr< ParmType > params=nullptr) const
Definition: cryptocontext.h:1409
Ciphertext< Element > EvalSubMutable(Ciphertext< Element > &ct1, Ciphertext< Element > &ct2) const
Definition: cryptocontext.h:1538
Ciphertext< Element > EvalMult(ConstCiphertext< Element > ct1, ConstPlaintext pt2) const
Definition: cryptocontext.h:1974
static bool SerializeEvalAutomorphismKey(std::ostream &ser, const ST &sertype, string id="")
Definition: cryptocontext.h:611
void PopLastParam()
Removes the last parameter set and adjust the multiplied moduli.
Definition: ildcrtparams.h:283
void EvalSumKeyGen(const LPPrivateKey< Element > privateKey, const LPPublicKey< Element > publicKey=nullptr)
Definition: cryptocontext.cpp:115
Ciphertext< Element > ComposedEvalMult(ConstCiphertext< Element > ciphertext1, ConstCiphertext< Element > ciphertext2) const
Definition: cryptocontext.h:2513
static void ClearEvalMultKeys()
Definition: cryptocontext.cpp:77
shared_ptr< std::map< usint, LPEvalKey< Element > > > MultiEvalAtIndexKeyGen(const LPPrivateKey< Element > privateKey, const shared_ptr< std::map< usint, LPEvalKey< Element >>> eAuto, const std::vector< int32_t > &indexList, const std::string &keyId="")
Definition: cryptocontext.h:979
LPKeyPair< Element > SparseKeyGen()
Definition: cryptocontext.h:1144
Ciphertext< Element > EvalMultMutable(Ciphertext< Element > &ciphertext, double constant) const
Definition: cryptocontext.h:2025
shared_ptr< std::map< usint, LPEvalKey< Element > > > MultiAddEvalSumKeys(const shared_ptr< std::map< usint, LPEvalKey< Element >>> es1, const shared_ptr< std::map< usint, LPEvalKey< Element >>> es2, const std::string &keyId="")
Definition: cryptocontext.h:1064
DecryptResult MultipartyDecryptFusion(const vector< Ciphertext< Element >> &partialCiphertextVec, Plaintext *plaintext) const
Definition: cryptocontext.cpp:521
Ciphertext< Element > LevelReduce(ConstCiphertext< Element > cipherText1, const LPEvalKey< Element > linearKeySwitchHint, size_t levels=1) const
Definition: cryptocontext.h:2488
Ciphertext< Element > ReEncrypt(LPEvalKey< Element > evalKey, ConstCiphertext< Element > ciphertext, const LPPublicKey< Element > publicKey=nullptr) const
Definition: cryptocontext.h:1452
Plaintext MakePackedPlaintext(const vector< int64_t > &value) const
Definition: cryptocontext.h:1323
main implementation class to capture essential cryptoparameters of any LBC system ...
Definition: pubkeylp.h:73
void TypeCheck(ConstCiphertext< Element > a, ConstCiphertext< Element > b, CALLER_INFO_ARGS_HDR) const
Definition: cryptocontext.h:121
Ciphertext< Element > EvalSum(ConstCiphertext< Element > ciphertext, usint batchSize) const
Definition: cryptocontext.cpp:327
static bool DeserializeEvalMultKey(std::istream &ser, const ST &sertype)
Definition: cryptocontext.h:457
shared_ptr< std::map< usint, LPEvalKey< Element > > > EvalAutomorphismKeyGen(const LPPublicKey< Element > publicKey, const LPPrivateKey< Element > origPrivateKey, const std::vector< usint > &indexList) const
Definition: cryptocontext.h:2060
usint GetRingDimension() const
Definition: cryptocontext.h:771
const LPPrivateKey< Element > GetPrivateKey()
Definition: cryptocontext.h:304
Definition: pubkeylp.h:879
Ciphertext< Element > EvalNegate(ConstCiphertext< Element > ct) const
Definition: cryptocontext.h:2041
LPEvalKey< Element > MultiAddEvalKeys(LPEvalKey< Element > a, LPEvalKey< Element > b, const std::string &keyId="")
Definition: cryptocontext.h:1025
Ciphertext< Element > EvalMult(ConstCiphertext< Element > ct1, ConstCiphertext< Element > ct2) const
Definition: cryptocontext.h:1730
Ciphertext< Element > EvalAddMutable(Ciphertext< Element > &ct1, Ciphertext< Element > &ct2) const
Definition: cryptocontext.h:1507
Ciphertext< Element > EvalMerge(const vector< Ciphertext< Element >> &ciphertextVector) const
Definition: cryptocontext.cpp:398
Ciphertext< Element > EvalAutomorphism(ConstCiphertext< Element > ciphertext, usint i, const std::map< usint, LPEvalKey< Element >> &evalKeys, CALLER_INFO_ARGS_HDR) const
Definition: cryptocontext.h:2089
Crypto parameters class for RLWE-based schemes.
Definition: ckks.h:53
double GetScalingFactorOfLevel(uint32_t l=0) const
Definition: ckks.h:440
shared_ptr< std::map< usint, LPEvalKey< Element > > > EvalAutomorphismKeyGen(const LPPrivateKey< Element > privateKey, const std::vector< usint > &indexList) const
Definition: cryptocontext.h:2142
Definition: binfhecontext.h:36
Ciphertext< Element > EvalMult(double constant, ConstCiphertext< Element > ct1) const
Definition: cryptocontext.h:1958
shared_ptr< std::map< usint, LPEvalKey< Element > > > MultiEvalAutomorphismKeyGen(const LPPrivateKey< Element > privateKey, const shared_ptr< std::map< usint, LPEvalKey< Element >>> eAuto, const std::vector< usint > &indexList, const std::string &keyId="")
Definition: cryptocontext.h:953
Ciphertext< Element > ModReduce(ConstCiphertext< Element > ciphertext) const
Definition: cryptocontext.h:2457
Definition: exception.h:126
Abstract interface for public key encryption schemes.
Definition: pubkeylp.h:3181
void Enable(PKESchemeFeature feature)
Definition: cryptocontext.h:711
Parameters for array of ideal lattices (used for Double-CRT).
Definition: backend.h:71
Plaintext MakeCoefPackedPlaintext(const vector< int64_t > &value) const
Definition: cryptocontext.h:1312
Ciphertext< Element > EvalMultNoRelin(ConstCiphertext< Element > ct1, ConstCiphertext< Element > ct2) const
Definition: cryptocontext.h:1774
void EvalMultKeyGen(const LPPrivateKey< Element > key)
Definition: cryptocontext.cpp:33
Definition: exception.h:107
LPPublicKey< Element > MultiAddPubKeys(LPPublicKey< Element > pubKey1, LPPublicKey< Element > pubKey2, const std::string &keyId="")
Definition: cryptocontext.h:1107
Ciphertext< Element > Rescale(ConstCiphertext< Element > ciphertext) const
Definition: cryptocontext.h:2426
static void InsertEvalMultKey(const std::vector< LPEvalKey< Element >> &vectorToInsert)
Definition: cryptocontext.cpp:109