Class BinFHEContext
Defined in File binfhecontext.h
Page Contents
Inheritance Relationships
Base Type
public lbcrypto::Serializable
(Class Serializable)
Class Documentation
-
class lbcrypto::BinFHEContext : public lbcrypto::Serializable
Inheritence diagram for lbcrypto::BinFHEContext:
Collaboration diagram for lbcrypto::BinFHEContext:
The wrapper class for Boolean circuit FHE
Public Functions
-
BinFHEContext() = default
-
void GenerateBinFHEContext(uint32_t n, uint32_t N, const NativeInteger &q, const NativeInteger &Q, double std, uint32_t baseKS, uint32_t baseG, uint32_t baseR, SecretKeyDist keyDist = UNIFORM_TERNARY, BINFHE_METHOD method = GINX, uint32_t numAutoKeys = 10)
Creates a crypto context using custom parameters. Should be used with care (only for advanced users familiar with LWE parameter selection).
- Parameters
n – lattice parameter for additive LWE scheme
N – ring dimension for RingGSW/RLWE used in bootstrapping
q – modulus for additive LWE
Q – modulus for RingGSW/RLWE used in bootstrapping
std – standard deviation
baseKS – the base used for key switching
baseG – the gadget base used in bootstrapping
baseR – the base used for refreshing
keyDist – secret key distribution
method – the bootstrapping method (DM or CGGI or LMKCDEY)
numAutoKeys – number of automorphism keys in LMKCDEY bootstrapping
- Returns
creates the cryptocontext
-
void GenerateBinFHEContext(BINFHE_PARAMSET set, bool arbFunc, uint32_t logQ = 11, int64_t N = 0, BINFHE_METHOD method = GINX, bool timeOptimization = false)
Creates a crypto context using custom parameters. Should be used with care (only for advanced users familiar with LWE parameter selection).
- Parameters
set – the parameter set: TOY, MEDIUM, STD128, STD192, STD256 with variants, see binfhe_constants.h
arbFunc – whether need to evaluate an arbitrary function using functional bootstrapping
logQ – log(input ciphertext modulus)
N – ring dimension for RingGSW/RLWE used in bootstrapping
method – the bootstrapping method (DM or CGGI or LMKCDEY)
timeOptimization – whether to use dynamic bootstrapping technique
- Returns
creates the cryptocontext
-
void GenerateBinFHEContext(BINFHE_PARAMSET set, BINFHE_METHOD method = GINX)
Creates a crypto context using predefined parameters sets. Recommended for most users.
- Parameters
set – the parameter set: TOY, MEDIUM, STD128, STD192, STD256 with variants, see binfhe_constants.h
method – the bootstrapping method (DM or CGGI or LMKCDEY)
- Returns
create the cryptocontext
-
void GenerateBinFHEContext(const BinFHEContextParams ¶ms, BINFHE_METHOD method = GINX)
Creates a crypto context using custom parameters.
- Parameters
params – the parameter context
method – the bootstrapping method (DM or CGGI or LMKCDEY)
- Returns
create the cryptocontext
-
inline const RingGSWACCKey &GetRefreshKey() const
Gets the refresh key (used for serialization).
- Returns
a shared pointer to the refresh key
-
inline const LWESwitchingKey &GetSwitchKey() const
Gets the switching key (used for serialization).
- Returns
a shared pointer to the switching key
-
inline const LWEPublicKey &GetPublicKey() const
Gets the public key (used for serialization).
- Returns
a shared pointer to the public key
-
inline const std::shared_ptr<std::map<uint32_t, RingGSWBTKey>> GetBTKeyMap() const
Gets the bootstrapping key map (used for serialization).
- Returns
a shared pointer to the bootstrapping key map
-
LWEPrivateKey KeyGen() const
Generates a secret key for the main LWE scheme
- Returns
a shared pointer to the secret key
-
LWEKeyPair KeyGenPair() const
Generates a public key, secret key pair for the main LWE scheme
- Returns
a shared pointer to the public key, secret key pair
-
LWEPublicKey PubKeyGen(ConstLWEPrivateKey &sk) const
Generates a public key for a secret key for the main LWE scheme
- Returns
a shared pointer to the public key
-
LWEPrivateKey KeyGenN() const
Generates a secret key used in bootstrapping
- Returns
a shared pointer to the secret key
-
LWECiphertext Encrypt(ConstLWEPrivateKey &sk, LWEPlaintext m, BINFHE_OUTPUT output = BOOTSTRAPPED, LWEPlaintextModulus p = 4, const NativeInteger &mod = 0) const
Encrypts a bit or integer using a secret key (symmetric key encryption)
- Parameters
sk – the secret key
m – the plaintext
output – FRESH to generate fresh ciphertext, BOOTSTRAPPED to generate a refreshed ciphertext (default)
p – plaintext modulus
mod – the ciphertext modulus to encrypt with; by default m_q in params
- Returns
a shared pointer to the ciphertext
-
LWECiphertext Encrypt(ConstLWEPublicKey &pk, LWEPlaintext m, BINFHE_OUTPUT output = SMALL_DIM, LWEPlaintextModulus p = 4, const NativeInteger &mod = 0) const
Encrypts a bit or integer using a public key (public key encryption)
- Parameters
pk – the public key
m – the plaintext
output – SMALL_DIM to generate ciphertext with dimension n (default). LARGE_DIM to generate ciphertext with dimension N
p – plaintext modulus
mod – the ciphertext modulus to encrypt with; by default m_q in params
- Returns
a shared pointer to the ciphertext
-
LWECiphertext SwitchCTtoqn(ConstLWESwitchingKey &ksk, ConstLWECiphertext &ct) const
Converts a ciphertext (public key encryption) with modulus Q and dimension N to ciphertext with q and n
- Parameters
ksk – the key switching key from secret key of dimension N to secret key of dimension n
ct – the ciphertext to convert
- Returns
a shared pointer to the ciphertext
-
void Decrypt(ConstLWEPrivateKey &sk, ConstLWECiphertext &ct, LWEPlaintext *result, LWEPlaintextModulus p = 4) const
Decrypts a ciphertext using a secret key
- Parameters
sk – the secret key
ct – the ciphertext
result – plaintext result
p – plaintext modulus
-
LWESwitchingKey KeySwitchGen(ConstLWEPrivateKey &sk, ConstLWEPrivateKey &skN) const
Generates a switching key to go from a secret key with (Q,N) to a secret key with (q,n)
- Parameters
sk – new secret key
skN – old secret key
- Returns
a shared pointer to the switching key
-
void BTKeyGen(ConstLWEPrivateKey &sk, KEYGEN_MODE keygenMode = SYM_ENCRYPT)
Generates boostrapping keys
- Parameters
sk – secret key
keygenMode – key generation mode for symmetric or public encryption
-
inline void BTKeyLoad(const RingGSWBTKey &key)
Loads bootstrapping keys in the context (typically after deserializing)
- Parameters
key – struct with the bootstrapping keys
-
inline void BTKeyMapLoadSingleElement(uint32_t baseG, const RingGSWBTKey &key)
Loads a bootstrapping key map element in the context (typically after deserializing)
- Parameters
baseG – baseG corresponding to the given key
key – struct with the bootstrapping keys
-
inline void ClearBTKeys()
Clear the bootstrapping keys in the current context
-
LWECiphertext EvalBinGate(BINGATE gate, ConstLWECiphertext &ct1, ConstLWECiphertext &ct2) const
Evaluates a binary gate (calls bootstrapping as a subroutine)
- Parameters
gate – the gate; can be AND, OR, NAND, NOR, XOR, or XNOR
ct1 – first ciphertext
ct2 – second ciphertext
- Returns
a shared pointer to the resulting ciphertext
-
LWECiphertext EvalBinGate(BINGATE gate, const std::vector<LWECiphertext> &ctvector) const
Evaluates a binary gate on vector of ciphertexts (calls bootstrapping as a subroutine)
- Parameters
gate – the gate; can be MAJORITY, AND3, OR3, AND4, OR4, or CMUX
ctvector – vector of ciphertexts
- Returns
a shared pointer to the resulting ciphertext
-
LWECiphertext Bootstrap(ConstLWECiphertext &ct) const
Bootstraps a ciphertext (without peforming any operation)
- Parameters
ct – ciphertext to be bootstrapped
- Returns
a shared pointer to the resulting ciphertext
-
LWECiphertext EvalFunc(ConstLWECiphertext &ct, const std::vector<NativeInteger> &LUT) const
Evaluate an arbitrary function
- Parameters
ct – ciphertext to be bootstrapped
LUT – the look-up table of the to-be-evaluated function
- Returns
a shared pointer to the resulting ciphertext
-
std::vector<NativeInteger> GenerateLUTviaFunction(NativeInteger (*f)(NativeInteger m, NativeInteger p), NativeInteger p)
Generate the LUT for the to-be-evaluated function
- Parameters
f – the to-be-evaluated function on an integer message and a plaintext modulus
p – plaintext modulus
- Returns
a shared pointer to the resulting ciphertext
-
LWECiphertext EvalFloor(ConstLWECiphertext &ct, uint32_t roundbits = 0) const
Evaluate a round down function
- Parameters
ct – ciphertext to be bootstrapped
roundbits – number of bits to be rounded
- Returns
a shared pointer to the resulting ciphertext
-
LWECiphertext EvalSign(ConstLWECiphertext &ct, bool schemeSwitch = false)
Evaluate a sign function over large precisions
- Parameters
ct – ciphertext to be bootstrapped
schemeSwitch – flag that indicates if it should be compatible to scheme switching
- Returns
a shared pointer to the resulting ciphertext
-
std::vector<LWECiphertext> EvalDecomp(ConstLWECiphertext &ct)
Evaluate ciphertext decomposition
- Parameters
ct – ciphertext to be bootstrapped
- Returns
a vector of shared pointers to the resulting ciphertexts
-
LWECiphertext EvalNOT(ConstLWECiphertext &ct) const
Evaluates NOT gate
- Parameters
ct – the input ciphertext
- Returns
a shared pointer to the resulting ciphertext
-
LWECiphertext EvalConstant(bool value) const
Evaluates constant gate
- Parameters
value – the Boolean value to output
- Returns
a shared pointer to the resulting ciphertext
-
inline const std::shared_ptr<BinFHECryptoParams> &GetParams()
Getter for params
- Returns
-
inline const std::shared_ptr<LWEEncryptionScheme> &GetLWEScheme()
Getter for LWE scheme
- Returns
-
inline const std::shared_ptr<BinFHEScheme> &GetBinFHEScheme()
Getter for BinFHE scheme params
- Returns
-
inline virtual std::string SerializedObjectName() const override
-
inline NativeInteger GetMaxPlaintextSpace() const
Getter for maximum plaintext modulus
- Returns
-
inline constexpr NativeInteger GetBeta() const
Getter for the beta security parameter
- Returns
Public Static Functions
-
static inline uint32_t SerializedVersion()
-
BinFHEContext() = default