56 #ifndef LBCRYPTO_CRYPTO_BFVRNS_H 57 #define LBCRYPTO_CRYPTO_BFVRNS_H 73 template <
class Element>
75 using IntType =
typename Element::Integer;
76 using ParmType =
typename Element::Params;
77 using DggType =
typename Element::DggType;
78 using DugType =
typename Element::DugType;
79 using TugType =
typename Element::TugType;
129 const PlaintextModulus& plaintextModulus,
130 float distributionParameter,
float assuranceMeasure,
131 float securityLevel, usint relinWindow,
132 MODE mode = RLWE,
int depth = 1,
int maxDepth = 2);
150 EncodingParams encodingParams,
151 float distributionParameter,
float assuranceMeasure,
152 float securityLevel, usint relinWindow,
153 MODE mode = RLWE,
int depth = 1,
int maxDepth = 2);
171 EncodingParams encodingParams,
172 float distributionParameter,
float assuranceMeasure,
173 SecurityLevel securityLevel, usint relinWindow,
174 MODE mode = RLWE,
int depth = 1,
int maxDepth = 2);
194 const shared_ptr<ILDCRTParams<BigInteger>>
GetParamsP()
const {
213 std::vector<double>
const&
GetqInv()
const {
return m_qInv; }
220 std::vector<double>
const&
GetpInv()
const {
return m_pInv; }
228 return m_modqBarrettMu;
237 return m_modpBarrettMu;
246 return m_tQHatInvModqDivqFrac;
256 return m_tQHatInvModqBDivqFrac;
265 return m_tQHatInvModqDivqModt;
274 return m_tQHatInvModqDivqModtPrecon;
284 return m_tQHatInvModqBDivqModt;
294 return m_tQHatInvModqBDivqModtPrecon;
302 const std::vector<NativeInteger>&
GetDelta()
const {
return m_QDivtModq; }
310 return m_QHatInvModq;
319 return m_QHatInvModqPrecon;
327 const std::vector<std::vector<NativeInteger>>&
GetQHatModp()
const {
347 return m_tPSHatInvModsDivsFrac;
358 return m_tPSHatInvModsDivsModp;
367 return m_PHatInvModp;
376 return m_PHatInvModpPrecon;
384 const std::vector<std::vector<NativeInteger>>&
GetPHatModq()
const {
406 if (el ==
nullptr)
return false;
411 void PrintParameters(std::ostream& os)
const {
418 template <
class Archive>
419 void save(Archive& ar, std::uint32_t
const version)
const {
423 template <
class Archive>
424 void load(Archive& ar, std::uint32_t
const version) {
425 if (version > SerializedVersion()) {
427 "serialized object version " + std::to_string(version) +
428 " is from a later version of the library");
436 std::string SerializedObjectName()
const {
return "BFVrnsSchemeParameters"; }
437 static uint32_t SerializedVersion() {
return 1; }
442 shared_ptr<ILDCRTParams<BigInteger>> m_paramsP;
446 shared_ptr<ILDCRTParams<BigInteger>> m_paramsQP;
449 std::vector<double> m_qInv;
452 std::vector<double> m_pInv;
455 std::vector<DoubleNativeInt> m_modqBarrettMu;
458 std::vector<DoubleNativeInt> m_modpBarrettMu;
461 std::vector<double> m_tQHatInvModqDivqFrac;
465 std::vector<double> m_tQHatInvModqBDivqFrac;
468 std::vector<NativeInteger> m_tQHatInvModqDivqModt;
470 std::vector<NativeInteger> m_tQHatInvModqDivqModtPrecon;
474 std::vector<NativeInteger> m_tQHatInvModqBDivqModt;
478 std::vector<NativeInteger> m_tQHatInvModqBDivqModtPrecon;
481 std::vector<NativeInteger> m_QDivtModq;
484 std::vector<NativeInteger> m_QHatInvModq;
486 std::vector<NativeInteger> m_QHatInvModqPrecon;
489 std::vector<std::vector<NativeInteger>> m_QHatModp;
492 std::vector<std::vector<NativeInteger>> m_alphaQModp;
496 std::vector<std::vector<NativeInteger>> m_tPSHatInvModsDivsModp;
500 std::vector<double> m_tPSHatInvModsDivsFrac;
503 std::vector<NativeInteger> m_PHatInvModp;
505 std::vector<NativeInteger> m_PHatInvModpPrecon;
508 std::vector<std::vector<NativeInteger>> m_PHatModq;
511 std::vector<std::vector<NativeInteger>> m_alphaPModq;
520 template <
class Element>
522 using IntType =
typename Element::Integer;
523 using ParmType =
typename Element::Params;
524 using DggType =
typename Element::DggType;
525 using DugType =
typename Element::DugType;
526 using TugType =
typename Element::TugType;
551 int32_t evalAddCount = 0, int32_t evalMultCount = 0,
552 int32_t keySwitchCount = 0,
size_t dcrBits = 60,
553 uint32_t n = 0)
const;
563 template <
class Element>
565 using IntType =
typename Element::Integer;
566 using ParmType =
typename Element::Params;
567 using DggType =
typename Element::DggType;
568 using DugType =
typename Element::DugType;
569 using TugType =
typename Element::TugType;
584 Ciphertext<Element> Encrypt(
const LPPublicKey<Element> publicKey,
585 Element plaintext)
const;
594 Ciphertext<Element> Encrypt(
const LPPrivateKey<Element> privateKey,
595 Element plaintext)
const;
606 DecryptResult Decrypt(
const LPPrivateKey<Element> privateKey,
607 ConstCiphertext<Element> ciphertext,
616 template <
class Element>
618 using IntType =
typename Element::Integer;
619 using ParmType =
typename Element::Params;
620 using DggType =
typename Element::DggType;
621 using DugType =
typename Element::DugType;
622 using TugType =
typename Element::TugType;
637 Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ct,
638 ConstPlaintext pt)
const override;
647 Ciphertext<Element> EvalSub(ConstCiphertext<Element> ct1,
648 ConstPlaintext pt)
const override;
660 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,
661 ConstCiphertext<Element> ct2)
const override;
670 LPEvalKey<Element> KeySwitchGen(
671 const LPPrivateKey<Element> oldKey,
672 const LPPrivateKey<Element> newKey)
const override;
682 void KeySwitchInPlace(
const LPEvalKey<Element> keySwitchHint,
683 Ciphertext<Element>& ciphertext)
const override;
697 Ciphertext<Element> EvalMultAndRelinearize(
698 ConstCiphertext<Element> ct1, ConstCiphertext<Element> ct2,
699 const vector<LPEvalKey<Element>>& ek)
const override;
707 template <
class Element>
709 using IntType =
typename Element::Integer;
710 using ParmType =
typename Element::Params;
711 using DggType =
typename Element::DggType;
712 using DugType =
typename Element::DugType;
713 using TugType =
typename Element::TugType;
747 LPEvalKey<Element> ReKeyGen(
const LPPublicKey<Element> newKey,
748 const LPPrivateKey<Element> oldKey)
const;
776 Ciphertext<Element> ReEncrypt(
777 const LPEvalKey<Element> ek, ConstCiphertext<Element> ciphertext,
778 const LPPublicKey<Element> publicKey =
nullptr)
const;
807 template <
class Element>
809 using IntType =
typename Element::Integer;
810 using ParmType =
typename Element::Params;
811 using DggType =
typename Element::DggType;
812 using DugType =
typename Element::DugType;
813 using TugType =
typename Element::TugType;
830 const vector<Ciphertext<Element>>& ciphertextVec,
833 template <
class Archive>
834 void save(Archive& ar)
const {
838 template <
class Archive>
839 void load(Archive& ar) {
853 LPEvalKey<Element> MultiKeySwitchGen(
854 const LPPrivateKey<Element> oldKey,
const LPPrivateKey<Element> newKey,
855 const LPEvalKey<Element> ek)
const override;
857 std::string SerializedObjectName()
const {
return "BFVrnsMultiparty"; }
864 template <
class Element>
867 using IntType =
typename Element::Integer;
868 using ParmType =
typename Element::Params;
869 using DggType =
typename Element::DggType;
870 using DugType =
typename Element::DugType;
871 using TugType =
typename Element::TugType;
882 void Enable(PKESchemeFeature feature)
override;
884 template <
class Archive>
885 void save(Archive& ar, std::uint32_t
const version)
const {
889 template <
class Archive>
890 void load(Archive& ar, std::uint32_t
const version) {
894 std::string SerializedObjectName()
const override {
return "BFVrnsScheme"; }
const std::vector< std::vector< NativeInteger > > & GetPHatModq() const
Definition: bfvrns.h:384
LPAlgorithmMultipartyBFVrns()
Definition: bfvrns.h:819
bool PrecomputeCRTTables()
const std::vector< std::vector< NativeInteger > > & GetQHatModp() const
Definition: bfvrns.h:327
PRE scheme based on BFV. This functionality is currently DISABLED in LPPublicKeyEncryptionSchemeBFV b...
Definition: bfv.h:749
Decryption result. This represents whether the decryption of a cipheretext was performed correctly...
Definition: pubkeylp.h:105
const std::vector< NativeInteger > & GettQHatInvModqDivqModt() const
Definition: bfvrns.h:264
std::vector< DoubleNativeInt > const & GetModqBarrettMu() const
Definition: bfvrns.h:227
const std::vector< NativeInteger > & GetPHatInvModpPrecon() const
Definition: bfvrns.h:375
const std::vector< NativeInteger > & GetQHatInvModq() const
Definition: bfvrns.h:309
Template for crypto parameters.
Definition: rlwe.h:47
std::vector< double > const & GetpInv() const
Definition: bfvrns.h:220
PRE algorithms implementation for BFVrns.
Definition: bfvrns.h:708
Concrete class for the FHE Multiparty algorithms on BFV. A version of this multiparty scheme built on...
Definition: bfv.h:860
const std::vector< NativeInteger > & GettQHatInvModqBDivqModtPrecon() const
Definition: bfvrns.h:293
LPAlgorithmBFVrns()
Definition: bfvrns.h:575
const std::vector< NativeInteger > & GettQHatInvModqBDivqModt() const
Definition: bfvrns.h:283
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: rlwe.h:284
const shared_ptr< ILDCRTParams< BigInteger > > GetParamsP() const
Definition: bfvrns.h:194
LPAlgorithmPREBFVrns()
Definition: bfvrns.h:719
const std::vector< std::vector< NativeInteger > > & GettPSHatInvModsDivsModp() const
Definition: bfvrns.h:356
Definition: exception.h:147
const std::vector< NativeInteger > & GetDelta() const
Definition: bfvrns.h:302
std::vector< double > const & GetqInv() const
Definition: bfvrns.h:213
Main public key encryption scheme for BFVrns implementation,.
Definition: bfvrns.h:865
const std::vector< NativeInteger > & GettQHatInvModqDivqModtPrecon() const
Definition: bfvrns.h:273
This is the parameters class for the BFVrns encryption scheme. This scheme is also referred to as the...
Definition: bfvrns.h:74
Concrete class for the FHE Multiparty algorithms on BFVrns. This scheme is also referred to as the FV...
Definition: bfvrns.h:808
bool SERIALIZE_PRECOMPUTE
Definition: cryptocontext.cpp:30
Parameter generation for BFV. This scheme is also referred to as the FV scheme.
Definition: bfv.h:386
Encryption algorithm implementation for BFV for the basic public key encrypt, decrypt and key generat...
Definition: bfv.h:439
LPAlgorithmSHEBFVrns()
Definition: bfvrns.h:628
const std::vector< std::vector< NativeInteger > > & GetalphaPModq() const
Definition: bfvrns.h:393
const std::vector< NativeInteger > & GetPHatInvModp() const
Definition: bfvrns.h:366
const std::vector< double > & GettQHatInvModqBDivqFrac() const
Definition: bfvrns.h:255
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: bfvrns.h:402
Parameter generation for BFVrns. This scheme is also referred to as the FV scheme.
Definition: bfvrns.h:521
const std::vector< double > & GettQHatInvModqDivqFrac() const
Definition: bfvrns.h:245
SHE algorithms implementation for BFVrns.
Definition: bfvrns.h:617
LPCryptoParametersBFVrns()
Definition: bfvrns.cpp:65
main implementation class to capture essential cryptoparameters of any LBC system ...
Definition: pubkeylp.h:73
LPAlgorithmParamsGenBFVrns()
Definition: bfvrns.h:532
std::vector< DoubleNativeInt > const & GetModpBarrettMu() const
Definition: bfvrns.h:236
const std::vector< std::vector< NativeInteger > > & GetalphaQModp() const
Definition: bfvrns.h:336
const std::vector< double > & GettPSHatInvModsDivsFrac() const
Definition: bfvrns.h:346
Definition: binfhecontext.h:36
SHE algorithms implementation for BFV. This scheme is also referred to as the FV scheme.
Definition: bfv.h:517
Abstract interface for public key encryption schemes.
Definition: pubkeylp.h:3181
const std::vector< NativeInteger > & GetQHatInvModqPrecon() const
Definition: bfvrns.h:318
Encryption algorithm implementation for BFVrns for the basic public key encrypt, decrypt and key gene...
Definition: bfvrns.h:564
const shared_ptr< ILDCRTParams< BigInteger > > GetParamsQP() const
Definition: bfvrns.h:204
virtual ~LPCryptoParametersBFVrns()
Definition: bfvrns.h:179