Template Class FHEBase

Template Parameter Order

  1. class Element

Class Documentation

template<class Element>
class lbcrypto::FHEBase

Abstract interface class for LBC PRE algorithms.

Template Parameters

Element – a ring element.

Public Functions

inline virtual ~FHEBase()
inline virtual void EvalBootstrapSetup(const CryptoContextImpl<Element> &cc, std::vector<uint32_t> levelBudget, std::vector<uint32_t> dim1, uint32_t slots, uint32_t correctionFactor, bool precompute)

Bootstrap functionality: There are three methods that have to be called in this specific order:

  1. EvalBootstrapSetup: computes and encodes the coefficients for encoding and decoding and stores the necessary parameters

  2. EvalBootstrapKeyGen: computes and stores the keys for rotations and conjugation

  3. EvalBootstrap: refreshes the given ciphertext Sets all parameters for the linear method for the FFT-like method

Parameters
  • levelBudget – - vector of budgets for the amount of levels in encoding and decoding

  • dim1 – - vector of inner dimension in the baby-step giant-step routine for encoding and decoding

  • slots – - number of slots to be bootstrapped

  • correctionFactor – - value to rescale message by to improve precision. If set to 0, we use the default logic. This value is only used when NATIVE_SIZE=64

  • precompute – - flag specifying whether to precompute the plaintexts for encoding and decoding.

inline virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalBootstrapKeyGen(const PrivateKey<Element> privateKey, uint32_t slots)

Virtual function to define the generation of all automorphism keys for EvalBT (with FFT evaluation). EvalBTKeyGen uses the baby-step/giant-step strategy.

Parameters
  • privateKey – private key.

  • slots – - number of slots to be bootstrapped

Returns

the dictionary of evaluation key indices.

inline virtual void EvalBootstrapPrecompute(const CryptoContextImpl<Element> &cc, uint32_t slots)

Computes the plaintexts for encoding and decoding for both linear and FFT-like methods. Supported in CKKS only.

Parameters

slots – - number of slots to be bootstrapped

inline virtual Ciphertext<Element> EvalBootstrap(ConstCiphertext<Element> ciphertext, uint32_t numIterations, uint32_t precision) const

Defines the bootstrapping evaluation of ciphertext

The flavor of bootstrapping that uses the numIterations and precision parameters is described in the Meta-BTS paper. Source: Bae Y., Cheon J., Cho W., Kim J., and Kim T. META-BTS: Bootstrapping Precision Beyond the Limit. Cryptology ePrint Archive, Report 2022/1167. (https://eprint.iacr.org/2022/1167.pdf)

Parameters
  • ciphertext – the input ciphertext.

  • numIterations – number of iterations to run iterative bootstrapping (Meta-BTS). Increasing the iterations increases the precision of bootstrapping.

  • precision – precision of initial bootstrapping algorithm. This value is determined by the user experimentally by first running EvalBootstrap with numIterations = 1 and precision = 0 (unused).

Returns

the refreshed ciphertext.

inline virtual LWEPrivateKey EvalCKKStoFHEWSetup(const SchSwchParams &params)

Sets all parameters for switching from CKKS to FHEW

Parameters

params – objects holding all necessary paramters

Returns

the FHEW secret key

inline virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalCKKStoFHEWKeyGen(const KeyPair<Element> &keyPair, ConstLWEPrivateKey &lwesk)

Virtual function to define the generation of all keys for scheme switching between CKKS and FHEW: the rotation keys for the baby-step/giant-step strategy, conjugation keys, switching key from CKKS to FHEW

Parameters
  • keypair – CKKS key pair

  • lwesk – FHEW secret key

inline virtual void EvalCKKStoFHEWPrecompute(const CryptoContextImpl<Element> &cc, double scale)

Performs precomputations for the homomorphic decoding in CKKS. Given as a separate method than EvalCKKStoFHEWSetup to allow the user to specify a scale that depends on the CKKS and FHEW cryptocontexts

Parameters
  • cc – the CKKS cryptocontext from which to switch

  • scale – factor with which to scale the matrix in the linear transform

  • dim1 – baby-step for the linear transform

  • L – level on which the hom. decoding matrix should be. We want the hom. decoded ciphertext to be on the last level

inline virtual std::vector<std::shared_ptr<LWECiphertextImpl>> EvalCKKStoFHEW(ConstCiphertext<Element> ciphertext, uint32_t numCtxts)

Performs the scheme switching on a CKKS ciphertext

Parameters
  • ciphertext – CKKS ciphertext to switch

  • numCtxts – number of coefficients to extract from the CKKS ciphertext. If it is zero, it defaults to number of slots

Returns

a vector of LWE ciphertexts of length the numCtxts

inline virtual void EvalFHEWtoCKKSSetup(const CryptoContextImpl<Element> &ccCKKS, const std::shared_ptr<BinFHEContext> &ccLWE, uint32_t numSlotsCKKS, uint32_t logQ)

Sets all parameters for switching from FHEW to CKKS. The CKKS cryptocontext to switch to is already generated.

Parameters
  • ccCKKS – the CKKS cryptocontext to switch to

  • ccLWE – the FHEW cryptocontext from which to switch

  • numSlotsCKKS – number of FHEW ciphertexts that becomes the number of slots in CKKS encryption

  • logQ – the logarithm of a ciphertext modulus in FHEW

inline virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalFHEWtoCKKSKeyGen(const KeyPair<Element> &keyPair, ConstLWEPrivateKey &lwesk, uint32_t numSlots = 0, uint32_t numCtxts = 0, uint32_t dim1 = 0, uint32_t L = 0)

Generates all keys for scheme switching: the rotation keys for the baby-step/giant-step strategy in the linear transform for the partial decryption, the switching key from FHEW to CKKS

Parameters
  • keypair – CKKS key pair

  • lwesk – FHEW secret key

  • numSlots – number of slots for the CKKS encryption of the FHEW secret key

  • numCtxts – number of values to encrypt from the LWE ciphertexts in the new CKKS ciphertext

  • dim1 – baby-step for the linear transform

  • L – level on which the hom. decoding matrix should be. We want the hom. decoded ciphertext to be on the last level

inline virtual void EvalCompareSwitchPrecompute(const CryptoContextImpl<Element> &ccCKKS, uint32_t pLWE, double scaleSign, bool unit)

Performs precomputations for the homomorphic decoding in CKKS. Given as a separate method than EvalSchemeSwitchingSetup to allow the user to specify a scale that depends on the CKKS and FHEW cryptocontexts

Parameters
  • cc – the CKKS cryptocontext from which to switch

  • pLWE – the desired plaintext modulus for the new FHEW ciphertexts

  • scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this

  • unit – whether the input messages are normalized to the unit circle

inline virtual Ciphertext<Element> EvalFHEWtoCKKS(std::vector<std::shared_ptr<LWECiphertextImpl>> &LWECiphertexts, uint32_t numCtxts, uint32_t numSlots, uint32_t p, double pmin, double pmax, uint32_t dim1) const

Performs the scheme switching on a vector of FHEW ciphertexts

Parameters
  • LWECiphertexts – FHEW/LWE ciphertexts to switch

  • numCtxts – number of values to encrypt from the LWE ciphertexts in the new CKKS ciphertext

  • numSlots – number of slots to encode in the new CKKS/RLWE ciphertext

  • p – plaintext modulus to use to decide postscaling, by default p = 4

  • pmin, pmax – plaintext space of the resulting messages (by default [0,2] assuming the LWE ciphertext had plaintext modulus p = 4 and only bits were encrypted)

  • dim1 – baby-step for the linear transform, necessary only for argmin

Returns

a CKKS ciphertext encrypting in its slots the messages in the LWE ciphertexts

inline virtual LWEPrivateKey EvalSchemeSwitchingSetup(const SchSwchParams &params)

Sets all parameters for switching from CKKS to FHEW and back

Parameters

params – objects holding all necessary paramters

Returns

the FHEW secret key TODO: add an overload for when BinFHEContext is already generated and fed as a parameter

inline virtual std::shared_ptr<std::map<usint, EvalKey<Element>>> EvalSchemeSwitchingKeyGen(const KeyPair<Element> &keyPair, ConstLWEPrivateKey &lwesk)

Generates all keys for scheme switching: the rotation keys for the baby-step/giant-step strategy in the linear transform for the homomorphic encoding and partial decryption, the switching key from FHEW to CKKS

Parameters
  • keypair – CKKS key pair

  • lwesk – FHEW secret key

inline virtual Ciphertext<Element> EvalCompareSchemeSwitching(ConstCiphertext<Element> ciphertext1, ConstCiphertext<Element> ciphertext2, uint32_t numCtxts, uint32_t numSlots, uint32_t pLWE, double scaleSign, bool unit)

Performs the scheme switching on the difference of two CKKS ciphertexts to compare, evaluates the sign function over the resulting FHEW ciphertexts, then performs the scheme switching back to a CKKS ciphertext

Parameters
  • ciphertext1, ciphertext2 – CKKS ciphertexts of messages that need to be compared

  • numCtxts – number of coefficients to extract from the CKKS ciphertext. If it is zero, it defaults to number of slots

  • numSlots – number of slots to encode the new CKKS ciphertext with

  • pLWE – the desired plaintext modulus for the new FHEW ciphertexts. If it is zero, it defaults to the large precision plaintext modulus Q/2beta

  • scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this

  • unit – whether the input messages are normalized to the unit circle

Returns

a CKKS ciphertext encrypting in its slots the sign of messages in the LWE ciphertexts

inline virtual std::vector<Ciphertext<Element>> EvalMinSchemeSwitching(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign)

Computes the minimum and argument of the first numValues packed in a CKKS ciphertext via repeated scheme switchings to FHEW and back.

Parameters
  • ciphertext – CKKS ciphertexts of values that need to be compared

  • publicKey – public key of the CKKS cryptocontext

  • numValues – number of values to extract from the CKKS ciphertext. We always assume for the moment numValues is a power of two

  • numSlots – number of slots to encode the new CKKS ciphertext with

  • pLWE – the desired plaintext modulus for the new FHEW ciphertexts

  • scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this pLWE and scaleSign are given here only if the homomorphic decoding matrix is not scaled with the desired values

Returns

a vector of two CKKS ciphertexts where the first encrypts the minimum value and the second encrypts the index (in the representation specified by oneHot). The ciphertexts have junk after the first slot in the first ciphertext and after numValues in the second ciphertext if oneHot=true and after the first slot if oneHot=false.

inline virtual std::vector<Ciphertext<Element>> EvalMinSchemeSwitchingAlt(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign)

Performs more operations in FHEW than in CKKS. Slightly better precision but slower.

inline virtual std::vector<Ciphertext<Element>> EvalMaxSchemeSwitching(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign)

Computes the maximum and argument of the first numValues packed in a CKKS ciphertext via repeated scheme switchings to FHEW and back.

Parameters
  • ciphertext – CKKS ciphertexts of values that need to be compared

  • publicKey – public key of the CKKS cryptocontext

  • numValues – number of values to extract from the CKKS ciphertext. We always assume for the moment numValues is a power of two

  • numSlots – number of slots to encode the new CKKS ciphertext with

  • pLWE – the desired plaintext modulus for the new FHEW ciphertexts

  • scaleSign – factor to multiply the CKKS ciphertext when switching to FHEW in case the messages are too small; the resulting FHEW ciphertexts will encrypt values modulo pLWE, so scaleSign should account for this pLWE and scaleSign are given here only if the homomorphic decoding matrix is not scaled with the desired values

Returns

a vector of two CKKS ciphertexts where the first encrypts the maximum value and the second encrypts the index (in the representation specified by oneHot). The ciphertexts have junk after the first slot in the first ciphertext and after numValues in the second ciphertext if oneHot=true and after the first slot if oneHot=false.

inline virtual std::vector<Ciphertext<Element>> EvalMaxSchemeSwitchingAlt(ConstCiphertext<Element> ciphertext, PublicKey<Element> publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign)

Performs more operations in FHEW than in CKKS. Slightly better precision but slower.

inline virtual std::shared_ptr<lbcrypto::BinFHEContext> GetBinCCForSchemeSwitch()

Getter and setter for the binFHE cryptocontext used in scheme switching

inline virtual void SetBinCCForSchemeSwitch(std::shared_ptr<lbcrypto::BinFHEContext> ccLWE)
inline virtual Ciphertext<Element> GetSwkFC()

Getter and setter for the switching key between FHEW to CKKS

inline virtual void SetSwkFC(Ciphertext<Element> FHEWtoCKKSswk)
template<class Archive>
inline void save(Archive &ar) const
template<class Archive>
inline void load(Archive &ar)