54 #ifndef LBCRYPTO_CRYPTO_BFVRNS_B_H 55 #define LBCRYPTO_CRYPTO_BFVRNS_B_H 71 template <
class Element>
73 using ParmType =
typename Element::Params;
74 using IntType =
typename Element::Integer;
75 using DugType =
typename Element::DugType;
76 using DggType =
typename Element::DggType;
77 using TugType =
typename Element::TugType;
127 const PlaintextModulus &plaintextModulus,
128 float distributionParameter,
float assuranceMeasure,
129 float securityLevel, usint relinWindow,
130 MODE mode = RLWE,
int depth = 1,
int maxDepth = 2);
148 EncodingParams encodingParams,
149 float distributionParameter,
float assuranceMeasure,
150 float securityLevel, usint relinWindow,
151 MODE mode = RLWE,
int depth = 1,
int maxDepth = 2);
169 EncodingParams encodingParams,
170 float distributionParameter,
float assuranceMeasure,
171 SecurityLevel securityLevel, usint relinWindow,
172 MODE mode = RLWE,
int depth = 1,
int maxDepth = 2);
196 if (el ==
nullptr)
return false;
201 void PrintParameters(std::ostream &os)
const {
220 std::vector<NativeInteger>
const &
GetModuliQ()
const {
return m_moduliQ; }
228 return m_modqBarrettMu;
236 std::vector<NativeInteger>
const &
GetModuliBsk()
const {
return m_moduliBsk; }
244 return m_modbskBarrettMu;
252 const std::vector<NativeInteger> &
GetDelta()
const {
return m_QDivtModq; }
260 return m_mtildeQHatInvModq;
269 return m_mtildeQHatInvModqPrecon;
296 return m_QHatModmtilde;
304 std::vector<NativeInteger>
const &
GetQModbsk()
const {
return m_QModbsk; }
312 return m_QModbskPrecon;
328 return m_mtildeInvModbsk;
337 return m_mtildeInvModbskPrecon;
346 return m_QHatInvModq;
355 return m_tQHatInvModq;
364 return m_tQHatInvModqPrecon;
373 return m_tgammaQHatInvModq;
382 return m_tgammaQHatInvModqPrecon;
391 return m_tQInvModbsk;
400 return m_tQInvModbskPrecon;
409 return m_BHatInvModb;
418 return m_BHatInvModbPrecon;
443 return m_BInvModmskPrecon;
451 std::vector<std::vector<NativeInteger>>
const &
GetBHatModq()
const {
460 std::vector<NativeInteger>
const &
GetBModq()
const {
return m_BModq; }
468 return m_BModqPrecon;
476 uint32_t
const &
Getgamma()
const {
return m_gamma; }
492 return m_negInvqModtgamma;
501 return m_negInvqModtgammaPrecon;
507 template <
class Archive>
508 void save(Archive &ar, std::uint32_t
const version)
const {
512 template <
class Archive>
513 void load(Archive &ar, std::uint32_t
const version) {
514 if (version > SerializedVersion()) {
516 "serialized object version " + std::to_string(version) +
517 " is from a later version of the library");
525 std::string SerializedObjectName()
const {
return "BFVrnsBSchemeParameters"; }
526 static uint32_t SerializedVersion() {
return 1; }
530 std::vector<NativeInteger> m_QDivtModq;
533 shared_ptr<ILDCRTParams<BigInteger>> m_paramsBsk;
548 std::vector<NativeInteger> m_moduliQ;
551 std::vector<DoubleNativeInt> m_modqBarrettMu;
554 std::vector<NativeInteger> m_moduliB;
557 std::vector<NativeInteger> m_rootsBsk;
560 std::vector<NativeInteger> m_moduliBsk;
563 std::vector<DoubleNativeInt> m_modbskBarrettMu;
566 std::vector<NativeInteger> m_QHatInvModq;
569 std::vector<NativeInteger> m_tQHatInvModq;
572 std::vector<NativeInteger> m_tQHatInvModqPrecon;
575 std::vector<std::vector<NativeInteger>> m_QHatModbsk;
578 std::vector<std::vector<NativeInteger>> m_qInvModbsk;
581 std::vector<uint16_t> m_QHatModmtilde;
584 std::vector<NativeInteger> m_mtildeQHatInvModq;
587 std::vector<NativeInteger> m_mtildeQHatInvModqPrecon;
590 uint16_t m_negQInvModmtilde;
593 std::vector<NativeInteger> m_QModbsk;
595 std::vector<NativeInteger> m_QModbskPrecon;
598 std::vector<NativeInteger> m_mtildeInvModbsk;
600 std::vector<NativeInteger> m_mtildeInvModbskPrecon;
603 std::vector<NativeInteger> m_tQInvModbsk;
605 std::vector<NativeInteger> m_tQInvModbskPrecon;
608 std::vector<NativeInteger> m_BHatInvModb;
610 std::vector<NativeInteger> m_BHatInvModbPrecon;
613 std::vector<std::vector<NativeInteger>> m_BHatModq;
616 std::vector<NativeInteger> m_BHatModmsk;
624 std::vector<NativeInteger> m_BModq;
626 std::vector<NativeInteger> m_BModqPrecon;
629 uint32_t m_gamma = 1 << 26;
636 std::vector<NativeInteger> m_negInvqModtgamma;
638 std::vector<NativeInteger> m_negInvqModtgammaPrecon;
641 std::vector<NativeInteger> m_tgammaQHatInvModq;
643 std::vector<NativeInteger> m_tgammaQHatInvModqPrecon;
652 template <
class Element>
654 using ParmType =
typename Element::Params;
655 using IntType =
typename Element::Integer;
656 using DugType =
typename Element::DugType;
657 using DggType =
typename Element::DggType;
658 using TugType =
typename Element::TugType;
682 int32_t evalAddCount = 0, int32_t evalMultCount = 0,
683 int32_t keySwitchCount = 0,
size_t dcrBits = 60,
684 uint32_t n = 0)
const override;
694 template <
class Element>
696 using ParmType =
typename Element::Params;
697 using IntType =
typename Element::Integer;
698 using DugType =
typename Element::DugType;
699 using DggType =
typename Element::DggType;
700 using TugType =
typename Element::TugType;
715 Ciphertext<Element> Encrypt(
const LPPublicKey<Element> publicKey,
716 Element plaintext)
const override;
725 Ciphertext<Element> Encrypt(
const LPPrivateKey<Element> privateKey,
726 Element plaintext)
const override;
737 DecryptResult Decrypt(
const LPPrivateKey<Element> privateKey,
738 ConstCiphertext<Element> ciphertext,
747 template <
class Element>
749 using ParmType =
typename Element::Params;
750 using IntType =
typename Element::Integer;
751 using DugType =
typename Element::DugType;
752 using DggType =
typename Element::DggType;
753 using TugType =
typename Element::TugType;
768 Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ct,
769 ConstPlaintext pt)
const override;
778 Ciphertext<Element> EvalSub(ConstCiphertext<Element> ct,
779 ConstPlaintext pt)
const override;
791 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,
792 ConstCiphertext<Element> ct2)
const override;
801 LPEvalKey<Element> KeySwitchGen(
802 const LPPrivateKey<Element> oldKey,
803 const LPPrivateKey<Element> newKey)
const override;
813 void KeySwitchInPlace(
const LPEvalKey<Element> keySwitchHint,
814 Ciphertext<Element>& ciphertext)
const override;
829 Ciphertext<Element> EvalMultAndRelinearize(
830 ConstCiphertext<Element> ct1, ConstCiphertext<Element> ct2,
831 const vector<LPEvalKey<Element>> &ek)
const override;
839 template <
class Element>
841 using ParmType =
typename Element::Params;
842 using IntType =
typename Element::Integer;
843 using DugType =
typename Element::DugType;
844 using DggType =
typename Element::DggType;
845 using TugType =
typename Element::TugType;
879 LPEvalKey<Element> ReKeyGen(
880 const LPPublicKey<Element> newKey,
881 const LPPrivateKey<Element> oldKey)
const override;
909 Ciphertext<Element> ReEncrypt(
910 const LPEvalKey<Element> ek, ConstCiphertext<Element> ciphertext,
911 const LPPublicKey<Element> publicKey =
nullptr)
const override;
940 template <
class Element>
942 using ParmType =
typename Element::Params;
943 using IntType =
typename Element::Integer;
944 using DugType =
typename Element::DugType;
945 using DggType =
typename Element::DggType;
946 using TugType =
typename Element::TugType;
963 const vector<Ciphertext<Element>> &ciphertextVec,
976 LPEvalKey<Element> MultiKeySwitchGen(
977 const LPPrivateKey<Element> oldKey,
const LPPrivateKey<Element> newKey,
978 const LPEvalKey<Element> ek)
const override;
980 template <
class Archive>
981 void save(Archive &ar)
const {
985 template <
class Archive>
986 void load(Archive &ar) {
990 std::string SerializedObjectName()
const {
return "BFVrnsBMultiparty"; }
997 template <
class Element>
1000 using ParmType =
typename Element::Params;
1001 using IntType =
typename Element::Integer;
1002 using DugType =
typename Element::DugType;
1003 using DggType =
typename Element::DggType;
1004 using TugType =
typename Element::TugType;
1015 void Enable(PKESchemeFeature feature)
override;
1017 template <
class Archive>
1018 void save(Archive &ar, std::uint32_t
const version)
const {
1022 template <
class Archive>
1023 void load(Archive &ar, std::uint32_t
const version) {
1027 std::string SerializedObjectName()
const override {
return "BFVrnsScheme"; }
std::vector< NativeInteger > const & GetQModbsk() const
Definition: bfvrnsB.h:304
const shared_ptr< ILDCRTParams< BigInteger > > GetParamsBsk() const
Definition: bfvrnsB.h:211
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
std::vector< NativeInteger > const & GetBHatModmsk() const
Definition: bfvrnsB.h:426
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: bfvrnsB.h:192
std::vector< NativeInteger > const & GetQModbskPrecon() const
Definition: bfvrnsB.h:311
NativeInteger const & GetBInvModmskPrecon() const
Definition: bfvrnsB.h:442
Main public key encryption scheme for BFVrnsB implementation,.
Definition: bfvrnsB.h:998
std::vector< NativeInteger > const & GetModuliQ() const
Definition: bfvrnsB.h:220
std::vector< NativeInteger > const & GettgammaQHatInvModq() const
Definition: bfvrnsB.h:372
Template for crypto parameters.
Definition: rlwe.h:47
LPAlgorithmMultipartyBFVrnsB()
Definition: bfvrnsB.h:952
Concrete class for the FHE Multiparty algorithms on BFV. A version of this multiparty scheme built on...
Definition: bfv.h:860
uint16_t const & GetNegQInvModmtilde() const
Definition: bfvrnsB.h:320
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: rlwe.h:284
std::vector< std::vector< NativeInteger > > const & GetQHatModbsk() const
Definition: bfvrnsB.h:277
std::vector< NativeInteger > const & GetmtildeInvModbsk() const
Definition: bfvrnsB.h:327
std::vector< NativeInteger > const & GetBModq() const
Definition: bfvrnsB.h:460
std::vector< NativeInteger > const & GetNegInvqModtgammaPrecon() const
Definition: bfvrnsB.h:500
std::vector< NativeInteger > const & GettQHatInvModqPrecon() const
Definition: bfvrnsB.h:363
NativeInteger const & GetBInvModmsk() const
Definition: bfvrnsB.h:435
std::vector< NativeInteger > const & GettQInvModbsk() const
Definition: bfvrnsB.h:390
Encryption algorithm implementation for BFVrnsB for the basic public key encrypt, decrypt and key gen...
Definition: bfvrnsB.h:695
Definition: exception.h:147
std::vector< NativeInteger > const & GetmtildeQHatInvModqPrecon() const
Definition: bfvrnsB.h:268
std::vector< NativeInteger > const & GetQHatInvModq() const
Definition: bfvrnsB.h:345
std::vector< NativeInteger > const & GettQHatInvModq() const
Definition: bfvrnsB.h:354
std::vector< NativeInteger > const & GetBModqPrecon() const
Definition: bfvrnsB.h:467
This is the parameters class for the BFVrnsB encryption scheme. This scheme is also referred to as th...
Definition: bfvrnsB.h:72
LPCryptoParametersBFVrnsB()
Definition: bfvrnsB.cpp:62
bool SERIALIZE_PRECOMPUTE
Definition: cryptocontext.cpp:30
bool PrecomputeCRTTables()
std::vector< NativeInteger > const & GetBHatInvModb() const
Definition: bfvrnsB.h:408
Parameter generation for BFV. This scheme is also referred to as the FV scheme.
Definition: bfv.h:386
uint32_t const & Getgamma() const
Definition: bfvrnsB.h:476
Encryption algorithm implementation for BFV for the basic public key encrypt, decrypt and key generat...
Definition: bfv.h:439
std::vector< NativeInteger > const & GetmtildeQHatInvModq() const
Definition: bfvrnsB.h:259
std::vector< DoubleNativeInt > const & GetModqBarrettMu() const
Definition: bfvrnsB.h:227
std::vector< NativeInteger > const & GetmtildeInvModbskPrecon() const
Definition: bfvrnsB.h:336
virtual ~LPCryptoParametersBFVrnsB()
Definition: bfvrnsB.h:177
PRE algorithms implementation for BFVrnsB.
Definition: bfvrnsB.h:840
main implementation class to capture essential cryptoparameters of any LBC system ...
Definition: pubkeylp.h:73
std::vector< NativeInteger > const & GettQInvModbskPrecon() const
Definition: bfvrnsB.h:399
LPAlgorithmSHEBFVrnsB()
Definition: bfvrnsB.h:759
Concrete class for the FHE Multiparty algorithms on BFVrnsB. This scheme is also referred to as the F...
Definition: bfvrnsB.h:941
std::vector< std::vector< NativeInteger > > const & GetBHatModq() const
Definition: bfvrnsB.h:451
std::vector< NativeInteger > const & GetBHatInvModbPrecon() const
Definition: bfvrnsB.h:417
std::vector< NativeInteger > const & GetNegInvqModtgamma() const
Definition: bfvrnsB.h:491
const std::vector< NativeInteger > & GetDelta() const
Definition: bfvrnsB.h:252
SHE algorithms implementation for BFVrnsB.
Definition: bfvrnsB.h:748
std::vector< DoubleNativeInt > const & GetModbskBarrettMu() const
Definition: bfvrnsB.h:243
Definition: binfhecontext.h:36
Main class for big integers represented as an array of native (primitive) unsigned integers...
Definition: backend.h:60
SHE algorithms implementation for BFV. This scheme is also referred to as the FV scheme.
Definition: bfv.h:517
std::vector< uint16_t > const & GetQHatModmtilde() const
Definition: bfvrnsB.h:295
Abstract interface for public key encryption schemes.
Definition: pubkeylp.h:3181
std::vector< std::vector< NativeInteger > > const & GetqInvModbsk() const
Definition: bfvrnsB.h:286
LPAlgorithmPREBFVrnsB()
Definition: bfvrnsB.h:851
LPAlgorithmParamsGenBFVrnsB()
Definition: bfvrnsB.h:664
NativeInteger const & Gettgamma() const
Definition: bfvrnsB.h:484
std::vector< NativeInteger > const & GettgammaQHatInvModqPrecon() const
Definition: bfvrnsB.h:381
std::vector< NativeInteger > const & GetModuliBsk() const
Definition: bfvrnsB.h:236
LPAlgorithmBFVrnsB()
Definition: bfvrnsB.h:706
Parameter generation for BFVrnsB. This scheme is also referred to as the FV scheme.
Definition: bfvrnsB.h:653