41 #ifndef LBCRYPTO_CRYPTO_BFV_H 42 #define LBCRYPTO_CRYPTO_BFV_H 50 #include "utils/caller_info.h" 71 template <
class Element>
72 class LPCryptoParametersBFV :
public LPCryptoParametersRLWE<Element> {
73 using IntType =
typename Element::Integer;
74 using ParmType =
typename Element::Params;
133 const PlaintextModulus &plaintextModulus,
134 float distributionParameter,
float assuranceMeasure,
135 float securityLevel, usint relinWindow,
136 const IntType &delta = IntType(0), MODE mode = RLWE,
137 const IntType &bigModulus = IntType(0),
138 const IntType &bigRootOfUnity = IntType(0),
139 const IntType &bigModulusArb = IntType(0),
140 const IntType &bigRootOfUnityArb = IntType(0),
141 int depth = 1,
int maxDepth = 2);
167 EncodingParams encodingParams,
168 float distributionParameter,
float assuranceMeasure,
169 float securityLevel, usint relinWindow,
170 const IntType &delta = IntType(0), MODE mode = RLWE,
171 const IntType &bigModulus = IntType(0),
172 const IntType &bigRootOfUnity = IntType(0),
173 const IntType &bigModulusArb = IntType(0),
174 const IntType &bigRootOfUnityArb = IntType(0),
175 int depth = 1,
int maxDepth = 2);
201 EncodingParams encodingParams,
202 float distributionParameter,
float assuranceMeasure,
203 SecurityLevel securityLevel, usint relinWindow,
204 const IntType &delta = IntType(0), MODE mode = RLWE,
205 const IntType &bigModulus = IntType(0),
206 const IntType &bigRootOfUnity = IntType(0),
207 const IntType &bigModulusArb = IntType(0),
208 const IntType &bigRootOfUnityArb = IntType(0),
209 int depth = 1,
int maxDepth = 2);
222 const IntType &
GetDelta()
const {
return m_delta; }
259 void SetDelta(
const IntType &delta) { m_delta = delta; }
266 void SetBigModulus(
const IntType &bigModulus) { m_bigModulus = bigModulus; }
274 m_bigRootOfUnity = bigRootOfUnity;
282 m_bigModulusArb = bigModulusArb;
290 m_bigRootOfUnityArb = bigRootOfUnityArb;
301 if (el ==
nullptr)
return false;
303 if (m_delta != el->m_delta)
return false;
304 if (m_bigModulus != el->m_bigModulus)
return false;
305 if (m_bigRootOfUnity != el->m_bigRootOfUnity)
return false;
306 if (m_bigModulusArb != el->m_bigModulusArb)
return false;
307 if (m_bigRootOfUnityArb != el->m_bigRootOfUnityArb)
return false;
312 void PrintParameters(std::ostream &os)
const {
315 os <<
" delta: " << m_delta <<
" bigmodulus: " << m_bigModulus
316 <<
" bigrootofunity: " << m_bigRootOfUnity
317 <<
" bigmodulusarb: " << m_bigModulusArb
318 <<
" bigrootofunityarb: " << m_bigRootOfUnityArb;
321 template <
class Archive>
322 void save(Archive &ar, std::uint32_t
const version)
const {
324 ar(::cereal::make_nvp(
"d", m_delta));
325 ar(::cereal::make_nvp(
"bm", m_bigModulus));
326 ar(::cereal::make_nvp(
"br", m_bigRootOfUnity));
327 ar(::cereal::make_nvp(
"bma", m_bigModulusArb));
328 ar(::cereal::make_nvp(
"bra", m_bigRootOfUnityArb));
331 template <
class Archive>
332 void load(Archive &ar, std::uint32_t
const version) {
333 if (version > SerializedVersion()) {
335 "serialized object version " + std::to_string(version) +
336 " is from a later version of the library");
339 ar(::cereal::make_nvp(
"d", m_delta));
340 ar(::cereal::make_nvp(
"bm", m_bigModulus));
341 ar(::cereal::make_nvp(
"br", m_bigRootOfUnity));
342 ar(::cereal::make_nvp(
"bma", m_bigModulusArb));
343 ar(::cereal::make_nvp(
"bra", m_bigRootOfUnityArb));
346 std::string SerializedObjectName()
const {
return "BFVSchemeParameters"; }
347 static uint32_t SerializedVersion() {
return 1; }
356 IntType m_bigModulus;
359 IntType m_bigRootOfUnity;
362 IntType m_bigModulusArb;
365 IntType m_bigRootOfUnityArb;
385 template <
class Element>
387 using IntType =
typename Element::Integer;
388 using ParmType =
typename Element::Params;
413 int32_t evalAddCount = 0, int32_t evalMultCount = 0,
414 int32_t keySwitchCount = 0,
size_t dcrtBits = 0,
415 uint32_t n = 0)
const;
438 template <
class Element>
440 using IntType =
typename Element::Integer;
441 using ParmType =
typename Element::Params;
442 using DggType =
typename Element::DggType;
443 using DugType =
typename Element::DugType;
444 using TugType =
typename Element::TugType;
461 virtual Ciphertext<Element> Encrypt(
const LPPublicKey<Element> publicKey,
462 Element plaintext)
const;
471 virtual Ciphertext<Element> Encrypt(
const LPPrivateKey<Element> privateKey,
472 Element plaintext)
const;
483 virtual DecryptResult Decrypt(
const LPPrivateKey<Element> privateKey,
484 ConstCiphertext<Element> ciphertext,
516 template <
class Element>
518 using IntType =
typename Element::Integer;
519 using ParmType =
typename Element::Params;
520 using DggType =
typename Element::DggType;
521 using DugType =
typename Element::DugType;
522 using TugType =
typename Element::TugType;
539 void EvalAddInPlace(Ciphertext<Element>& ct1,
540 ConstCiphertext<Element> ct2)
const override;
549 Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ct,
550 ConstPlaintext pt)
const override;
559 Ciphertext<Element> EvalSub(ConstCiphertext<Element> ct1,
560 ConstCiphertext<Element> ct2)
const override;
569 Ciphertext<Element> EvalSub(ConstCiphertext<Element> ct1,
570 ConstPlaintext pt)
const override;
582 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,
583 ConstCiphertext<Element> ct2)
const override;
592 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ciphertext,
593 ConstPlaintext plaintext)
const override;
607 Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,
608 ConstCiphertext<Element> ct,
609 const LPEvalKey<Element> ek)
const override;
624 Ciphertext<Element> EvalMultMany(
625 const vector<Ciphertext<Element>> &cipherTextList,
626 const vector<LPEvalKey<Element>> &evalKeys)
const override;
640 Ciphertext<Element> EvalMultAndRelinearize(
641 ConstCiphertext<Element> ct1, ConstCiphertext<Element> ct,
642 const vector<LPEvalKey<Element>> &ek)
const override;
650 Ciphertext<Element> EvalNegate(ConstCiphertext<Element> ct)
const override;
659 LPEvalKey<Element> KeySwitchGen(
660 const LPPrivateKey<Element> originalPrivateKey,
661 const LPPrivateKey<Element> newPrivateKey)
const override;
671 void KeySwitchInPlace(
const LPEvalKey<Element> keySwitchHint,
672 Ciphertext<Element> &cipherText)
const override;
681 LPEvalKey<Element> EvalMultKeyGen(
682 const LPPrivateKey<Element> k1)
const override;
694 vector<LPEvalKey<Element>> EvalMultKeysGen(
695 const LPPrivateKey<Element> k1)
const override;
706 Ciphertext<Element> EvalAutomorphism(
707 ConstCiphertext<Element> ciphertext, usint i,
708 const std::map<usint, LPEvalKey<Element>> &evalKeys,
709 CALLER_INFO_ARGS_HDR)
const override;
719 shared_ptr<std::map<usint, LPEvalKey<Element>>> EvalAutomorphismKeyGen(
720 const LPPrivateKey<Element> privateKey,
721 const std::vector<usint> &indexList)
const override;
733 const LPPublicKey<Element> publicKey,
734 const LPPrivateKey<Element> privateKey,
735 const std::vector<usint> &indexList)
const override {
737 "LPAlgorithmSHEBFV::EvalAutomorphismKeyGen is not implemented for BFV " 748 template <
class Element>
750 using IntType =
typename Element::Integer;
751 using ParmType =
typename Element::Params;
752 using DggType =
typename Element::DggType;
753 using TugType =
typename Element::TugType;
771 LPEvalKey<Element> ReKeyGen(
const LPPrivateKey<Element> newKey,
772 const LPPrivateKey<Element> origPrivateKey)
const;
800 LPEvalKey<Element> ReKeyGen(
const LPPublicKey<Element> newKey,
801 const LPPrivateKey<Element> origPrivateKey)
const;
829 Ciphertext<Element> ReEncrypt(
830 const LPEvalKey<Element> evalKey, ConstCiphertext<Element> ciphertext,
831 const LPPublicKey<Element> publicKey =
nullptr)
const;
859 template <
class Element>
861 using IntType =
typename Element::Integer;
862 using ParmType =
typename Element::Params;
863 using DggType =
typename Element::DggType;
864 using DugType =
typename Element::DugType;
865 using TugType =
typename Element::TugType;
890 const LPPublicKey<Element> pk1,
891 bool makeSparse =
false,
892 bool fresh =
false)
override;
906 CryptoContext<Element> cc,
907 const vector<LPPrivateKey<Element>> &secretKeys,
908 bool makeSparse =
false)
override;
917 Ciphertext<Element> MultipartyDecryptMain(
918 const LPPrivateKey<Element> privateKey,
919 ConstCiphertext<Element> ciphertext)
const override;
928 Ciphertext<Element> MultipartyDecryptLead(
929 const LPPrivateKey<Element> privateKey,
930 ConstCiphertext<Element> ciphertext)
const override;
941 const vector<Ciphertext<Element>> &ciphertextVec,
954 LPEvalKey<Element> MultiKeySwitchGen(
955 const LPPrivateKey<Element> originalPrivateKey,
956 const LPPrivateKey<Element> newPrivateKey,
957 const LPEvalKey<Element> ek)
const override;
969 shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalAutomorphismKeyGen(
970 const LPPrivateKey<Element> privateKey,
971 const shared_ptr<std::map<usint, LPEvalKey<Element>>> eAuto,
972 const std::vector<usint> &indexList)
const override;
983 shared_ptr<std::map<usint, LPEvalKey<Element>>> MultiEvalSumKeyGen(
984 const LPPrivateKey<Element> privateKey,
985 const shared_ptr<std::map<usint, LPEvalKey<Element>>> eSum)
995 LPEvalKey<Element> MultiAddEvalKeys(
996 LPEvalKey<Element> evalKey1, LPEvalKey<Element> evalKey2)
const override;
1007 LPEvalKey<Element> MultiMultEvalKey(LPEvalKey<Element> evalKey,
1008 LPPrivateKey<Element> sk)
const override;
1010 template <
class Archive>
1011 void save(Archive &ar)
const {
1015 template <
class Archive>
1016 void load(Archive &ar) {
1020 std::string SerializedObjectName()
const {
return "BFVMultiparty"; }
1027 template <
class Element>
1030 using IntType =
typename Element::Integer;
1031 using ParmType =
typename Element::Params;
1032 using DggType =
typename Element::DggType;
1033 using TugType =
typename Element::TugType;
1044 void Enable(PKESchemeFeature feature)
override;
1046 template <
class Archive>
1047 void save(Archive &ar, std::uint32_t
const version)
const {
1051 template <
class Archive>
1052 void load(Archive &ar, std::uint32_t
const version) {
1056 std::string SerializedObjectName()
const override {
return "BFVScheme"; }
LPAlgorithmBFV()
Definition: bfv.h:450
Abstract interface for parameter generation algorithm.
Definition: pubkeylp.h:899
void SetBigModulus(const IntType &bigModulus)
Definition: bfv.h:266
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
shared_ptr< std::map< usint, LPEvalKey< Element > > > EvalAutomorphismKeyGen(const LPPublicKey< Element > publicKey, const LPPrivateKey< Element > privateKey, const std::vector< usint > &indexList) const override
Definition: bfv.h:732
LPAlgorithmSHEBFV()
Definition: bfv.h:528
const IntType & GetDelta() const
Definition: bfv.h:222
Template for crypto parameters.
Definition: rlwe.h:47
void SetDelta(const IntType &delta)
Definition: bfv.h:259
Concrete class for the FHE Multiparty algorithms on BFV. A version of this multiparty scheme built on...
Definition: bfv.h:860
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: rlwe.h:284
void SetBigRootOfUnityArb(const IntType &bigRootOfUnityArb)
Definition: bfv.h:289
Abstract interface class for LBC Multiparty algorithms based on threshold FHE. A version of this mult...
Definition: pubkeylp.h:1299
const IntType & GetBigModulus() const
Definition: bfv.h:229
Definition: exception.h:119
bool operator==(const LPCryptoParameters< Element > &rhs) const
Definition: bfv.h:298
Definition: exception.h:147
virtual ~LPCryptoParametersBFV()
Definition: bfv.h:214
Abstract interface for encryption algorithm.
Definition: pubkeylp.h:1016
LPAlgorithmMultipartyBFV()
Definition: bfv.h:871
LPAlgorithmParamsGenBFV()
Definition: bfv.h:394
This is the parameters class for the BFV encryption scheme. This scheme is also referred to as the FV...
Definition: pubkeylp.h:76
Parameter generation for BFV. This scheme is also referred to as the FV scheme.
Definition: bfv.h:386
void SetBigRootOfUnity(const IntType &bigRootOfUnity)
Definition: bfv.h:273
Main public key encryption scheme for BFV implementation,.
Definition: bfv.h:1028
const IntType & GetBigRootOfUnityArb() const
Definition: bfv.h:253
void SetBigModulusArb(const IntType &bigModulusArb)
Definition: bfv.h:281
Encryption algorithm implementation for BFV for the basic public key encrypt, decrypt and key generat...
Definition: bfv.h:439
LPCryptoParametersBFV()
Definition: bfv.cpp:65
const IntType & GetBigRootOfUnity() const
Definition: bfv.h:237
Abstract interface class for LBC PRE algorithms.
Definition: pubkeylp.h:1239
const IntType & GetBigModulusArb() const
Definition: bfv.h:245
main implementation class to capture essential cryptoparameters of any LBC system ...
Definition: pubkeylp.h:73
Definition: pubkeylp.h:879
Abstract interface class for LBC SHE algorithms.
Definition: pubkeylp.h:1679
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
LPAlgorithmPREBFV()
Definition: bfv.h:759