Context.h
Provides FFT and iFFT routines modulo a single-precision prime.
Definition: CModulus.h:43
Context build() const
Builds a Context object from the arguments stored in the ContextBuilder object.
Definition: Context.cpp:1211
ContextBuilder & skHwt(long skHwt)
Sets the secret key Hamming weight.
Definition: Context.h:1226
ContextBuilder & buildModChain(bool yesno)
Sets a flag determining whether the modulus chain will be built.
Definition: Context.h:1261
ContextBuilder & gens(const std::vector< long > &gens)
Sets gens the generators of the ZMStar group.
Definition: Context.h:1187
ContextBuilder & bitsInSpecialPrimes(long bits)
Sets the bit size of the special primes in the modulus chain.
Definition: Context.h:1248
ContextBuilder & c(long c)
Sets c the number of columns (a.k.a. digits) in the key switching matrices.
Definition: Context.h:1176
ContextBuilder & m(long m)
Sets m the order of the cyclotomic polynomial.
Definition: Context.h:1100
ContextBuilder & scale(double scale)
Sets scale the scale parameter.
Definition: Context.h:1153
ContextBuilder & mvec(const std::vector< long > &mvec)
Sets mvec the unique primes which are factors of m.
Definition: Context.h:1289
ContextBuilder & thinboot()
Sets boostrapping to be thin.
Definition: Context.h:1302
ContextBuilder & buildCache(bool yesno)
Sets flag to choose that the cache for boostrapping will be built.
Definition: Context.h:1330
Context * buildPtr() const
Builds a Context object from the arguments stored in the ContextBuilder object.
Definition: Context.cpp:1218
ContextBuilder & bootstrappable(bool yesno=true)
Sets a flag determining if the context will be bootstrappable.
Definition: Context.h:1346
ContextBuilder & precision(long precision)
Sets precision the bit precision parameter.
Definition: Context.h:1142
static constexpr std::string_view typeName
Class label to be added to JSON serialization as object type information.
Definition: Context.h:1093
ContextBuilder & ords(const std::vector< long > &ords)
Sets ords the order of the corresponding generators in gens in ZmStar.
Definition: Context.h:1201
ContextBuilder & thickboot()
Sets boostrapping to be thick.
Definition: Context.h:1315
ContextBuilder & p(long p)
Sets p the prime number of the ciphertext space.
Definition: Context.h:1114
ContextBuilder & r(long r)
Sets r the Hensel lifting parameter.
Definition: Context.h:1128
ContextBuilder & bits(long bits)
Sets the bit size of the primes in the modulus chain.
Definition: Context.h:1213
ContextBuilder & resolution(long bits)
Sets the resolution for the modulus chain.
Definition: Context.h:1237
ContextBuilder & stdev(double stdev)
Sets stdev the standard deviation parameter.
Definition: Context.h:1164
ContextBuilder & mvec(const NTL::Vec< long > &mvec)
Sets mvec the unique primes which are factors of m.
Definition: Context.h:1275
const ThinRecryptData & getRcData() const
Getter method for a recryption data object.
Definition: Context.h:371
static Context * readPtrFrom(std::istream &str)
Read from the stream the serialized Context object in binary format.
Definition: Context.cpp:540
double securityLevel() const
An estimate for the security-level. This has a lower bound of 0.
Definition: Context.h:874
static Context * readPtrFromJSON(std::istream &str)
Read from the JsonWrapper the serialized Context object.
Definition: Context.cpp:592
long getHwt() const
Getter method for the Hamming weight value.
Definition: Context.h:385
void writeTo(std::ostream &str) const
Write out the Context object in binary format.
Definition: Context.cpp:415
const std::shared_ptr< const EncryptedArray > & shareEA() const
Getter method returning the std::shared_ptr to default EncryptedArray object of the created context.
Definition: Context.h:432
double noiseBoundForSmall(double prob, long degBound) const
Definition: Context.h:571
double logOfProduct(const IndexSet &s) const
Calculate the natural logarithm of productOfPrimes(s) for a given set of primes s.
Definition: Context.h:840
const ModuliSizes & getModSizeTable() const
Get the helper table to map required modulo-sizes to primeSets.
Definition: Context.h:643
void buildModChain(long nBits, long nDgts=3, bool willBeBootstrappable=false, long skHwt=0, long resolution=3, long bitsInSpecialPrimes=0)
Build the modulus chain for given Context object.
Definition: Context.cpp:1127
bool isZeroDivisor(const NTL::ZZ &num) const
Check if a number is divisible by any of the primes in the modulus chain.
Definition: Context.h:790
long getM() const
Getter method for the m used to create this context.
Definition: Context.h:252
bool operator!=(const Context &other) const
Not equals operator between two Context objects.
Definition: Context.h:756
friend std::ostream & operator<<(std::ostream &str, const Context &context)
Write out all other data associated with a given Context object.
Definition: Context.cpp:664
void setModSizeTable()
Set the helper table to map required modulo-sizes to primeSets.
Definition: Context.h:648
friend void readContextBase(std::istream &str, unsigned long &m, unsigned long &p, unsigned long &r, std::vector< long > &gens, std::vector< long > &ords)
Read in the basic information m, p and r required to construct a Context object.
static Context readFromJSON(std::istream &str)
Read from the stream the serialized Context object using JSON format.
Definition: Context.cpp:578
const IndexSet & getSmallPrimes() const
Getter method to the index set to the small primes.
Definition: Context.h:338
NTL::xdouble noiseBoundForGaussian(NTL::xdouble sigma, long degBound) const
Definition: Context.h:548
double stdDevForRecryption() const
Calculate the standard deviation for recryption.
Definition: Context.h:615
long numPrimes() const
Return the total number of small primes in the modulus chain.
Definition: Context.h:781
const PowerfulDCRT & getPowerfulConverter() const
Get a powerful converter.
Definition: Context.h:326
long getPrecision() const
Getter method for the precision value of the created CKKS context.
Definition: Context.h:320
void printout(std::ostream &out=std::cout) const
Print out algebra and other important info.
Definition: Context.cpp:728
friend std::istream & operator>>(std::istream &str, Context &context)
Read in all other data associated with a given Context object.
const IndexSet & getDigit(long i) const
Getter method to get a single digit.
Definition: Context.h:365
long getPPowR() const
Getter method for the default p^r value of the created context.
Definition: Context.h:306
double getScale() const
Getter method for the scale.
Definition: Context.h:283
JsonWrapper writeToJSON() const
Write out the Context object to a JsonWrapper.
Definition: Context.cpp:601
const EncryptedArray & getView() const
Getter method returning the default view object of the created context.
Definition: Context.h:416
long getP() const
Getter method for the p used to create this context.
Definition: Context.h:258
const IndexSet & getCtxtPrimes() const
Getter method to the index set to the ciphertext primes.
Definition: Context.h:344
IndexSet fullPrimes() const
Getter method that returns the handles of both the ctxtPrimes and specialPrimes associated with this ...
Definition: Context.h:714
double noiseBoundForMod(long modulus, long degBound) const
Definition: Context.h:516
bool inChain(long p) const
Check if value is already contained within the modulus chain.
Definition: Context.h:804
NTL::ZZ productOfPrimes(const IndexSet &s) const
Definition: Context.h:818
long ithPrime(unsigned long i) const
Getter method for the small prime of the modulus chain at index i as a long.
Definition: Context.h:764
long getPhiM() const
Getter method for the phi(m) of the created context.
Definition: Context.h:264
const EncryptedArray & getEA() const
Getter method returning the default EncryptedArray object of the created context.
Definition: Context.h:425
NTL::xdouble noiseBoundForUniform(NTL::xdouble magBound, long degBound) const
Definition: Context.h:482
double noiseBoundForUniform(double magBound, long degBound) const
Definition: Context.h:474
void enableBootStrapping(const NTL::Vec< long > &mvec, bool build_cache=false, bool alsoThick=true)
Initialises the recryption data.
Definition: Context.h:692
bool isBootstrappable() const
Check if a Context is bootstrappable.
Definition: Context.h:707
double logOfPrime(unsigned long i) const
Calculate the natural logarithm of the ith prime of the modulus chain.
Definition: Context.h:832
long getR() const
Getter method for the default r value of the created context.
Definition: Context.h:298
IndexSet getCtxtPrimes(long nprimes) const
Getter method that returns the first nprimes ctxtPrimes associated with this Context.
Definition: Context.h:734
double noiseBoundForGaussian(double sigma, long degBound) const
Definition: Context.h:540
static constexpr std::string_view typeName
Class label to be added to JSON serialization as object type information.
Definition: Context.h:243
long getOrdP() const
Getter method for the ord(p) of the created context.
Definition: Context.h:270
double noiseBoundForHWt(long hwt, UNUSED long degBound) const
Definition: Context.h:595
IndexSet allPrimes() const
Getter method that returns the handles of all primes associated with this Context.
Definition: Context.h:722
NTL::xdouble getStdev() const
Getter method for the standard deviation used..
Definition: Context.h:289
double boundForRecryption() const
Calculate the bound for recryption.
Definition: Context.h:634
const Cmodulus & ithModulus(unsigned long i) const
Getter method for the small prime of the modulus chain at index i as a Cmodulus.
Definition: Context.h:775
bool isCKKS() const
Return whether this is a CKKS context or not Context.
Definition: Context.h:379
long bitSizeOfQ() const
Calculate the size of the ciphertext modulus Q in bits.
Definition: Context.h:856
const std::vector< IndexSet > & getDigits() const
Getter method to the digits.
Definition: Context.h:357
long getNSlots() const
Getter method for the number of plaintext slots of the created context.
Definition: Context.h:277
const IndexSet & getSpecialPrimes() const
Getter method to the index set to the special primes.
Definition: Context.h:350
bool operator==(const Context &other) const
Equals operator between two Context objects.
Definition: Context.cpp:368
long getEPrime() const
Getter method for the e prime parameter.
Definition: Context.h:397
const PAlgebraMod & getAlMod() const
Get the underlying AlMod object.
Definition: Context.h:409
const PAlgebra & getZMStar() const
Get the underlying zMStar object.
Definition: Context.h:403
static Context readFrom(std::istream &str)
Read from the stream the serialized Context object in binary format.
Definition: Context.cpp:535
const std::shared_ptr< PolyModRing > & getSlotRing() const
Get a slot ring.
Definition: Context.h:332
void productOfPrimes(NTL::ZZ &p, const IndexSet &s) const
Calculate the product of all primes in the given set.
Definition: Context.cpp:361
A simple wrapper for a smart pointer to an EncryptedArrayBase. This is the interface that higher-leve...
Definition: EncryptedArray.h:1583
long first() const
Returns the first element, 0 if the set is empty.
Definition: IndexSet.h:68
long last() const
Returns the last element, -1 if the set is empty.
Definition: IndexSet.h:71
A helper class to map required modulo-sizes to primeSets.
Definition: primeChain.h:28
void init(const Context &context)
initialize helper table for a given chain
Definition: primeChain.cpp:68
long getNSlots() const
The number of plaintext slots = phi(m)/ord(p)
Definition: PAlgebra.h:188
long getNFactors() const
The number of distinct prime factors of m.
Definition: PAlgebra.h:176
long getPow2() const
if m = 2^k, then pow2 == k; otherwise, pow2 == 0
Definition: PAlgebra.h:191
PA_tag getTag() const
Returns the type tag: PA_GF2_tag or PA_zz_p_tag.
Definition: PAlgebra.h:860
Conversion between powerful representation, DoubleCRT, and ZZX.
Definition: powerful.h:131
std::shared_ptr< const PAlgebraMod > alMod
for plaintext space p^{e-e'+r}
Definition: recryption.h:49
Same as above, but for "thin" bootstrapping, where the slots are assumed to contain constants.
Definition: recryption.h:99
void init(const Context &context, const NTL::Vec< long > &mvec_, bool alsoThick, bool build_cache=false, bool minimal=false)
Initialize the recryption data in the context.
Definition: recryption.cpp:773
Definition: apiAttributes.h:21
long FindM(long k, long nBits, long c, long p, long d, long s, long chosen_m, bool verbose=false)
Returns smallest parameter m satisfying various constraints.
Definition: Context.cpp:207
void assertTrue(const T &value, const std::string &message)
Definition: assertions.h:61
double lweEstimateSecurity(int n, double log2AlphaInv, int hwt)
An estimate for the security-level. This has a lower bound of 0.
Definition: Context.cpp:32
std::ostream & operator<<(std::ostream &os, const ContextBuilder< SCHEME > &cb)
ostream operator for serializing the ContextBuilder object.
double fsquare(double x)
Return the square of a number as a double.
Definition: NumbTh.h:149
Definition: Context.cpp:180
Definition: Context.cpp:168
Definition: Context.cpp:187
Definition: Context.h:1373
Definition: JsonWrapper.h:9
Lightweight type for describing the structure of a single slot of the plaintext space.
Definition: PolyModRing.h:43