Template Class DCRTPolyImpl
Defined in File dcrtpoly.h
Inheritance Relationships
Base Type
public lbcrypto::DCRTPolyInterface< DCRTPolyImpl< VecType >, VecType, NativeVector, PolyImpl >
(Template Class DCRTPolyInterface)
Template Parameter Order
typename VecType
Class Documentation
-
template<typename VecType>
class lbcrypto::DCRTPolyImpl : public lbcrypto::DCRTPolyInterface<DCRTPolyImpl<VecType>, VecType, NativeVector, PolyImpl> Inheritence diagram for lbcrypto::DCRTPolyImpl:
Collaboration diagram for lbcrypto::DCRTPolyImpl:
Public Types
-
using Params = ILDCRTParams<Integer>
-
using PolyType = PolyImpl<NativeVector>
-
using DCRTPolyType = DCRTPolyImpl<VecType>
-
using DCRTPolyInterfaceType = DCRTPolyInterface<DCRTPolyImpl<VecType>, VecType, NativeVector, PolyImpl>
-
using Precomputations = typename DCRTPolyInterfaceType::CRTBasisExtensionPrecomputations
-
using DggType = typename DCRTPolyInterfaceType::DggType
-
using DugType = typename DCRTPolyInterfaceType::DugType
-
using TugType = typename DCRTPolyInterfaceType::TugType
-
using BugType = typename DCRTPolyInterfaceType::BugType
Public Functions
-
DCRTPolyImpl() = default
-
inline DCRTPolyImpl(const DCRTPolyType &e) noexcept
-
inline virtual DCRTPolyType &operator=(const DCRTPolyType &rhs) noexcept override
Assignment Operator.
- Parameters
&rhs – the copied element.
- Returns
the resulting element.
-
DCRTPolyType &operator=(const PolyLargeType &rhs) noexcept
-
DCRTPolyType &operator=(const PolyType &rhs) noexcept
-
inline DCRTPolyImpl(DCRTPolyType &&e) noexcept
-
inline virtual DCRTPolyType &operator=(DCRTPolyType &&rhs) noexcept override
Move Assignment Operator.
- Parameters
&rhs – the copied element.
- Returns
the resulting element.
-
virtual DCRTPolyType &operator=(std::initializer_list<uint64_t> rhs) noexcept override
Initalizer list.
- Parameters
&rhs – the list to initalized the element.
- Returns
the resulting element.
-
DCRTPolyType &operator=(uint64_t val) noexcept
-
DCRTPolyType &operator=(const std::vector<int64_t> &rhs) noexcept
-
DCRTPolyType &operator=(const std::vector<int32_t> &rhs) noexcept
-
DCRTPolyType &operator=(std::initializer_list<std::string> rhs) noexcept
-
virtual DCRTPolyType CloneWithNoise(const DiscreteGaussianGeneratorImpl<VecType> &dgg, Format format) const override
Clone with noise. This method creates a new DCRTPoly and clones the params. The tower values will be filled up with noise based on the discrete gaussian.
- Parameters
&dgg – the input discrete Gaussian generator. The dgg will be the seed to populate the towers of the DCRTPoly with random numbers.
format – the input format fixed to EVALUATION. Format is a enum type that indicates if the polynomial is in Evaluation representation or Coefficient representation. It is defined in inttypes.h.
-
DCRTPolyType CloneTowers(uint32_t startTower, uint32_t endTower) const
-
virtual bool operator==(const DCRTPolyType &rhs) const override
Equality operator.
- Parameters
&rhs – is the specified element to be compared with this element.
- Returns
true if this element represents the same values as the specified element, false otherwise.
-
virtual DCRTPolyType &operator+=(const DCRTPolyType &rhs) override
Performs an entry-wise addition over all elements of each tower with the towers of the element on the right hand side.
- Parameters
&rhs – is the element to add with.
- Returns
is the result of the addition.
-
virtual DCRTPolyType &operator+=(const Integer &rhs) override
Performs += operation with a BigInteger and returns the result.
- Parameters
&element – is the element to add
- Returns
is the result of the addition.
-
DCRTPolyType &operator+=(const NativeInteger &rhs) override
-
virtual DCRTPolyType &operator-=(const DCRTPolyType &rhs) override
Performs an entry-wise subtraction over all elements of each tower with the towers of the element on the right hand side.
- Parameters
&rhs – is the element to subtract from.
- Returns
is the result of the addition.
-
virtual DCRTPolyType &operator-=(const Integer &rhs) override
Performs -= operation with a BigInteger and returns the result.
- Parameters
&element – is the element to subtract
- Returns
is the result of the addition.
-
DCRTPolyType &operator-=(const NativeInteger &rhs) override
-
inline virtual DCRTPolyType &operator*=(const DCRTPolyType &rhs) override
Performs a multiplication operation and returns the result.
- Parameters
&element – is the element to multiply with.
- Returns
is the result of the multiplication.
-
virtual DCRTPolyType &operator*=(const Integer &rhs) override
Performs *= operation with a BigInteger and returns the result.
- Parameters
&element – is the element to multiply by
- Returns
is the result of the multiplication.
-
DCRTPolyType &operator*=(const NativeInteger &rhs) override
-
virtual DCRTPolyType Negate() const override
Performs a negation operation and returns the result.
- Returns
is the result of the negation.
-
virtual DCRTPolyType operator-() const override
Unary minus on a element.
- Returns
additive inverse of the an element.
-
virtual std::vector<DCRTPolyType> BaseDecompose(usint baseBits, bool evalModeAnswer) const override
Write the element as and return the vector of ; This is used as a subroutine in the relinearization procedure.
See also
DCRTPolyInterface::CRTDecompose instead.
Warning
not efficient and not fast, uses multiprecision arithmetic and will be removed in future. Use
- Parameters
baseBits – is the number of bits in the base, i.e., .
- Returns
is the pointer where the base decomposition vector is stored
-
virtual std::vector<DCRTPolyType> PowersOfBase(usint baseBits) const override
Generate a vector of PolyImpl’s as , where is the current PolyImpl object; used as a subroutine in the relinearization procedure to get powers of a certain “base” for the secret key element.
See also
DCRTPolyInterface::CRTDecompose instead.
Warning
not efficient and not fast, uses multiprecision arithmetic and will be removed in future. Use
- Parameters
baseBits – is the number of bits in the base, i.e., .
- Returns
is the pointer where the base decomposition vector is stored
-
std::vector<DCRTPolyType> CRTDecompose(uint32_t baseBits) const
-
virtual DCRTPolyType AutomorphismTransform(uint32_t i) const override
Permutes coefficients in a polynomial. Moves the ith index to the first one, it only supports odd indices.
- Parameters
&i – is the element to perform the automorphism transform with.
- Returns
is the result of the automorphism transform.
-
virtual DCRTPolyType AutomorphismTransform(uint32_t i, const std::vector<uint32_t> &vec) const override
Performs an automorphism transform operation using precomputed bit reversal indices.
- Parameters
&i – is the element to perform the automorphism transform with.
&vec – a vector with precomputed indices
- Returns
is the result of the automorphism transform.
-
virtual DCRTPolyType Plus(const Integer &rhs) const override
Scalar addition - add an element to the first index only. This operation is only allowed in COEFFICIENT format.
- Parameters
&element – is the element to add entry-wise.
- Returns
is the return of the addition operation.
-
DCRTPolyType Plus(const std::vector<Integer> &rhs) const
-
inline virtual DCRTPolyType Plus(const DCRTPolyType &rhs) const override
Performs an addition operation and returns the result.
- Parameters
&element – is the element to add with.
- Returns
is the result of the addition.
-
virtual DCRTPolyType Minus(const DCRTPolyType &rhs) const override
Performs a subtraction operation and returns the result.
- Parameters
&element – is the element to subtract from.
- Returns
is the result of the subtraction.
-
virtual DCRTPolyType Minus(const Integer &rhs) const override
Scalar subtraction - subtract an element frp, all entries.
- Parameters
&element – is the element to subtract entry-wise.
- Returns
is the return value of the minus operation.
-
DCRTPolyType Minus(const std::vector<Integer> &rhs) const
-
inline virtual DCRTPolyType Times(const DCRTPolyType &rhs) const override
Performs a multiplication operation and returns the result.
- Parameters
&element – is the element to multiply with.
- Returns
is the result of the multiplication.
-
virtual DCRTPolyType Times(const Integer &rhs) const override
Scalar multiplication - multiply all entries.
- Parameters
&element – is the element to multiply entry-wise.
- Returns
is the return value of the times operation.
-
DCRTPolyType Times(const std::vector<Integer> &rhs) const
-
virtual DCRTPolyType Times(NativeInteger::SignedNativeInt rhs) const override
Scalar multiplication - multiply by a signed integer.
- Parameters
&element – is the element to multiply entry-wise.
- Returns
is the return value of the times operation.
-
inline DCRTPolyType Times(int64_t rhs) const
-
DCRTPolyType Times(const std::vector<NativeInteger> &rhs) const
-
DCRTPolyType TimesNoCheck(const std::vector<NativeInteger> &rhs) const
-
virtual DCRTPolyType MultiplicativeInverse() const override
Performs a multiplicative inverse operation and returns the result.
- Returns
is the result of the multiplicative inverse.
-
virtual bool InverseExists() const override
Determines if inverse exists.
- Returns
is the Boolean representation of the existence of multiplicative inverse.
-
virtual bool IsEmpty() const override
Returns true if ALL the tower(s) are empty.
- Returns
true if all towers are empty
-
virtual void SetValuesToZero() override
Sets all values of element to zero.
-
virtual void AddILElementOne() override
Adds “1” to every entry in every tower.
-
virtual void DropLastElement() override
Drops the last element in the double-CRT representation. The resulting DCRTPoly element will have one less tower.
-
virtual void DropLastElements(size_t i) override
Drops the last i elements in the double-CRT representation.
-
virtual void DropLastElementAndScale(const std::vector<NativeInteger> &QlQlInvModqlDivqlModq, const std::vector<NativeInteger> &qlInvModq) override
Drops the last element in the double-CRT representation and scales down by the last CRT modulus. The resulting DCRTPoly element will have one less tower.
- Parameters
&QlQlInvModqlDivqlModq – precomputed values for [Q^(l)*[Q^(l)^{-1}]_{q_l}/q_l]_{q_i}
&QlQlInvModqlDivqlModqPrecon – NTL-specific precomputations
&qlInvModq – precomputed values for [q_l^{-1}]_{q_i}
&qlInvModqPrecon – NTL-specific precomputations
-
virtual void ModReduce(const NativeInteger &t, const std::vector<NativeInteger> &tModqPrecon, const NativeInteger &negtInvModq, const NativeInteger &negtInvModqPrecon, const std::vector<NativeInteger> &qlInvModq, const std::vector<NativeInteger> &qlInvModqPrecon) override
Used for BGVrns modulus switching This function performs ModReduce on ciphertext element and private key element. The algorithm computes ct’ <- round( ct/qt ).
Modulus reduction reduces a ciphertext from modulus q to a smaller modulus q/qt where qt is generally the last moduli of the tower. ModReduce is written for DCRTPolyImpl and it drops the last tower while updating the necessary parameters.
The rounding is actually computed as a flooring by computing delta such that delta = -ct mod qt and delta = 0 [t]
The steps taken here are as follows:
compute delta <- -ct/ptm mod qt
compute delta <- ptm*delta in Z. E.g., all of delta’s integer coefficients can be in the range [-ptm*qt/2, ptm*qt/2).
let d’ = c + delta mod q/qt. By construction, d’ is divisible by qt and congruent to 0 mod ptm.
output (d’/q’) in R(q/q’).
-
virtual PolyLargeType CRTInterpolate() const override
Interpolates the DCRTPoly to a Poly based on the Chinese Remainder Transform Interpolation. and then returns a Poly with that single element.
- Returns
the interpolated ring element as a Poly object.
-
virtual PolyType DecryptionCRTInterpolate(PlaintextModulus ptm) const override
-
virtual PolyType ToNativePoly() const override
If the values are small enough this is used for efficiency.
Warning
This will be replaced with a non-member utility function.
- Returns
NativePoly
-
virtual PolyLargeType CRTInterpolateIndex(usint i) const override
Interpolates the DCRTPoly to a Poly based on the Chinese Remainder Transform Interpolation, only at element index i, all other elements are zero. and then returns a Poly with that single element.
- Returns
the interpolated ring element as a Poly object.
-
virtual Integer GetWorkingModulus() const override
Computes and returns the product of primes in the current moduli chain. Compared to GetModulus, which always returns the product of all primes in the crypto parameters, this method will return a different modulus, based on the towers/moduli that are currently in the chain (some towers are dropped along the way).
- Returns
the product of moduli in the current towers.
-
virtual void SetValuesModSwitch(const DCRTPolyType &element, const NativeInteger &modulus) override
Sets values with a different modulus.
-
void FastExpandCRTBasisPloverQ(const Precomputations &precomputed) override
-
virtual PolyType ScaleAndRound(const NativeInteger &t, const std::vector<NativeInteger> &tQHatInvModqDivqModt, const std::vector<NativeInteger> &tQHatInvModqDivqModtPrecon, const std::vector<NativeInteger> &tQHatInvModqBDivqModt, const std::vector<NativeInteger> &tQHatInvModqBDivqModtPrecon, const std::vector<double> &tQHatInvModqDivqFrac, const std::vector<double> &tQHatInvModqBDivqFrac) const override
Performs scale and round: {X}_{Q} -> {\round(t/Q*X)}_t {Q} = {q_1,…,q_l} {P} = {p_1,…,p_k}.
Brief algorithm: [\sum_i x_i*[t*QHatInv_i/q_i]_t + Round(\sum_i x_i*{t*QHatInv_i/q_i})]_t
Source: Halevi S., Polyakov Y., and Shoup V. An Improved RNS Variant of the BFV Homomorphic Encryption Scheme. Cryptology ePrint Archive, Report 2018/117. (https://eprint.iacr.org/2018/117)
- Parameters
&t – often corresponds to the plaintext modulus
&tQHatInvModqDivqModt – precomputed values for [Floor{t*QHatInv_i/q_i}]_t
&tQHatInvModqDivqModtPrecon – NTL-specific precomputations
&tQHatInvModqBDivqModt – precomputed values for [Floor{t*QHatInv_i*B/q_i}]_t used when CRT moduli are 45..60 bits long
&tQHatInvBDivqModtPrecon – NTL-specific precomputations used when CRT moduli are 45..60 bits long
&tQHatInvModqDivqFrac – precomputed values for Frac{t*QHatInv_i/q_i}
&tQHatInvBDivqFrac – precomputed values for Frac{t*QHatInv_i*B/q_i} used when CRT moduli are 45..60 bits long
- Returns
the result of computation as a polynomial with native 64-bit coefficients
-
virtual PolyType ScaleAndRound(const std::vector<NativeInteger> &moduliQ, const NativeInteger &t, const NativeInteger &tgamma, const std::vector<NativeInteger> &tgammaQHatModq, const std::vector<NativeInteger> &tgammaQHatModqPrecon, const std::vector<NativeInteger> &negInvqModtgamma, const std::vector<NativeInteger> &negInvqModtgammaPrecon) const override
Computes scale and round for fast rounding: {X}_{Q} -> {\round(t/Q * X)}_t {Q} = {q_1,…,q_l}.
Brief algorithm:
Source: Jean-Claude Bajard and Julien Eynard and Anwar Hasan and Vincent Zucca. A Full RNS Variant of FV like Somewhat Homomorphic Encryption Schemes. Cryptology ePrint Archive: Report 2016/510. (https://eprint.iacr.org/2016/510)
- Parameters
&moduliQ – moduli {q_1,…,q_l}
&t – often corresponds to the plaintext modulus
&tgamma – t * gamma : t * 2^26 reduction
&tgammaQHatModq – [t*gamma*(Q/q_i)]_{q_i}
&tgammaQHatModqPrecon – NTL-specific precomputations
&negInvqModtgamma – [-q^{-1}]_{t*gamma}
&negInvqModtgammaPrecon – NTL-specific precomputations
- Returns
-
virtual void FastRNSFloorq(const NativeInteger &t, const std::vector<NativeInteger> &moduliQ, const std::vector<NativeInteger> &moduliBsk, const std::vector<DoubleNativeInt> &modbskBarrettMu, const std::vector<NativeInteger> &tQHatInvModq, const std::vector<NativeInteger> &tQHatInvModqPrecon, const std::vector<std::vector<NativeInteger>> &QHatModbsk, const std::vector<std::vector<NativeInteger>> &qInvModbsk, const std::vector<NativeInteger> &tQInvModbsk, const std::vector<NativeInteger> &tQInvModbskPrecon) override
Computes scale and floor: {X}_{Q,Bsk} -> {\floor{t/Q * X}}_{Bsk} {Q} = {q_1,…,q_l} {Bsk} = {bsk_1,…,bsk_k} Outputs the resulting polynomial in CRT/RNS.
Source: Jean-Claude Bajard and Julien Eynard and Anwar Hasan and Vincent Zucca. A Full RNS Variant of FV like Somewhat Homomorphic Encryption Schemes. Cryptology ePrint Archive: Report 2016/510. (https://eprint.iacr.org/2016/510)
- Parameters
&t – plaintext modulus
&moduliQ – {Q} = {q_1,…,q_l}
&moduliBsk – {Bsk} = {bsk_1,…,bsk_k}
&modbskBarrettMu – 128-bit Barrett reduction precomputed values for bsk_j
&tQHatInvModq – [(Q/q_i)^{-1}]_{q_i}
&tQHatInvModqPrecon – NTL-specific precomputations
&QHatModbsk – [Q/q_i]_{bsk_i}
&qInvModbsk – [(q_i)^{-1}]_{bsk_j}
&tQInvModbsk – [t*Q^{-1}]_{bsk_j}
&tQInvModbskPrecon – NTL-specific precomputations
-
virtual void SwitchFormat() override
Convert from Coefficient to CRT or vice versa; calls FFT and inverse FFT.
See also
SetFormat(format) instead
Warning
use
-
void SwitchModulusAtIndex(size_t index, const Integer &modulus, const Integer &rootOfUnity) override
-
inline virtual std::string SerializedObjectName() const override
-
inline virtual Format GetFormat() const final
Get method of the format.
- Returns
the format, either COEFFICIENT or EVALUATION
Public Static Functions
-
static inline const std::string GetElementName()
-
static inline uint32_t SerializedVersion()
Protected Attributes
-
std::shared_ptr<Params> m_params = {std::make_shared<DCRTPolyImpl::Params>()}
-
Format m_format = {Format::EVALUATION}
-
using Params = ILDCRTParams<Integer>