Maintaining the HE scheme parameters. More...
#include <Context.h>
Classes | |
| struct | BootStrapParams |
| struct | ModChainParams |
| struct | SerializableContent |
Public Member Functions | |
| long | getM () const |
Getter method for the m used to create this context. More... | |
| long | getP () const |
Getter method for the p used to create this context. More... | |
| long | getPhiM () const |
Getter method for the phi(m) of the created context. More... | |
| long | getOrdP () const |
Getter method for the ord(p) of the created context. More... | |
| long | getNSlots () const |
Getter method for the number of plaintext slots of the created context. More... | |
| double | getScale () const |
| Getter method for the scale. More... | |
| NTL::xdouble | getStdev () const |
| Getter method for the standard deviation used.. More... | |
| long | getR () const |
Getter method for the default r value of the created context. More... | |
| long | getPPowR () const |
Getter method for the default p^r value of the created context. More... | |
| long | getPrecision () const |
Getter method for the precision value of the created CKKS context. More... | |
| const PowerfulDCRT & | getPowerfulConverter () const |
| Get a powerful converter. More... | |
| const std::shared_ptr< PolyModRing > & | getSlotRing () const |
| Get a slot ring. More... | |
| const IndexSet & | getSmallPrimes () const |
| Getter method to the index set to the small primes. More... | |
| const IndexSet & | getCtxtPrimes () const |
| Getter method to the index set to the ciphertext primes. More... | |
| const IndexSet & | getSpecialPrimes () const |
| Getter method to the index set to the special primes. More... | |
| const std::vector< IndexSet > & | getDigits () const |
| Getter method to the digits. More... | |
| const IndexSet & | getDigit (long i) const |
| Getter method to get a single digit. More... | |
| const ThinRecryptData & | getRcData () const |
| Getter method for a recryption data object. More... | |
| bool | isCKKS () const |
Return whether this is a CKKS context or not Context. More... | |
| long | getHwt () const |
| Getter method for the Hamming weight value. More... | |
| long | getE () const |
| Getter method for the e parameter. More... | |
| long | getEPrime () const |
| Getter method for the e prime parameter. More... | |
| const PAlgebra & | getZMStar () const |
Get the underlying zMStar object. More... | |
| const PAlgebraMod & | getAlMod () const |
Get the underlying AlMod object. More... | |
| const EncryptedArray & | getView () const |
Getter method returning the default view object of the created context. More... | |
| const EncryptedArray & | getEA () const |
Getter method returning the default EncryptedArray object of the created context. More... | |
| const std::shared_ptr< const EncryptedArray > & | shareEA () const |
Getter method returning the std::shared_ptr to default EncryptedArray object of the created context. More... | |
| double | noiseBoundForUniform (double magBound, long degBound) const |
| NTL::xdouble | noiseBoundForUniform (NTL::xdouble magBound, long degBound) const |
| double | noiseBoundForMod (long modulus, long degBound) const |
| double | noiseBoundForGaussian (double sigma, long degBound) const |
| NTL::xdouble | noiseBoundForGaussian (NTL::xdouble sigma, long degBound) const |
| double | noiseBoundForSmall (double prob, long degBound) const |
| double | noiseBoundForHWt (long hwt, UNUSED long degBound) const |
| double | stdDevForRecryption () const |
| Calculate the standard deviation for recryption. More... | |
| double | boundForRecryption () const |
| Calculate the bound for recryption. More... | |
| const ModuliSizes & | getModSizeTable () const |
| Get the helper table to map required modulo-sizes to primeSets. More... | |
| void | setModSizeTable () |
| Set the helper table to map required modulo-sizes to primeSets. More... | |
| ~Context ()=default | |
| Default destructor. More... | |
| Context ()=delete | |
| Deleted default constructor. More... | |
| Context (const Context &other)=delete | |
| Deleted copy constructor. More... | |
| Context (Context &&other)=delete | |
| Deleted move constructor. More... | |
| Context & | operator= (const Context &other)=delete |
| Deleted copy assignment. More... | |
| Context & | operator= (Context &&other)=delete |
| Deleted move assignment. More... | |
| void | enableBootStrapping (const NTL::Vec< long > &mvec, bool build_cache=false, bool alsoThick=true) |
| Initialises the recryption data. More... | |
| bool | isBootstrappable () const |
Check if a Context is bootstrappable. More... | |
| IndexSet | fullPrimes () const |
Getter method that returns the handles of both the ctxtPrimes and specialPrimes associated with this Context. More... | |
| IndexSet | allPrimes () const |
Getter method that returns the handles of all primes associated with this Context. More... | |
| IndexSet | getCtxtPrimes (long nprimes) const |
Getter method that returns the first nprimes ctxtPrimes associated with this Context. More... | |
| long | BPL () const |
| bool | operator== (const Context &other) const |
Equals operator between two Context objects. More... | |
| bool | operator!= (const Context &other) const |
Not equals operator between two Context objects. More... | |
| long | ithPrime (unsigned long i) const |
Getter method for the small prime of the modulus chain at index i as a long. More... | |
| const Cmodulus & | ithModulus (unsigned long i) const |
Getter method for the small prime of the modulus chain at index i as a Cmodulus. More... | |
| long | numPrimes () const |
| Return the total number of small primes in the modulus chain. More... | |
| bool | isZeroDivisor (const NTL::ZZ &num) const |
| Check if a number is divisible by any of the primes in the modulus chain. More... | |
| bool | inChain (long p) const |
| Check if value is already contained within the modulus chain. More... | |
| void | productOfPrimes (NTL::ZZ &p, const IndexSet &s) const |
| Calculate the product of all primes in the given set. More... | |
| NTL::ZZ | productOfPrimes (const IndexSet &s) const |
| double | logOfPrime (unsigned long i) const |
Calculate the natural logarithm of the ith prime of the modulus chain. More... | |
| double | logOfProduct (const IndexSet &s) const |
Calculate the natural logarithm of productOfPrimes(s) for a given set of primes s. More... | |
| long | bitSizeOfQ () const |
Calculate the size of the ciphertext modulus Q in bits. More... | |
| double | securityLevel () const |
| An estimate for the security-level. This has a lower bound of 0. More... | |
| void | printout (std::ostream &out=std::cout) const |
| Print out algebra and other important info. More... | |
| void | writeTo (std::ostream &str) const |
Write out the Context object in binary format. More... | |
| void | writeToJSON (std::ostream &str) const |
Write out the Context object to the output stream using JSON format. More... | |
| JsonWrapper | writeToJSON () const |
Write out the Context object to a JsonWrapper. More... | |
| void | clearModChain () |
| 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. More... | |
| void | endBuildModChain () |
Static Public Member Functions | |
| static Context | readFrom (std::istream &str) |
Read from the stream the serialized Context object in binary format. More... | |
| static Context * | readPtrFrom (std::istream &str) |
Read from the stream the serialized Context object in binary format. More... | |
| static Context | readFromJSON (std::istream &str) |
Read from the stream the serialized Context object using JSON format. More... | |
| static Context | readFromJSON (const JsonWrapper &j) |
Read from the JsonWrapper the serialized Context object. More... | |
| static Context * | readPtrFromJSON (std::istream &str) |
Read from the JsonWrapper the serialized Context object. More... | |
Static Public Attributes | |
| static constexpr std::string_view | typeName = "Context" |
| Class label to be added to JSON serialization as object type information. More... | |
Friends | |
| template<typename SCHEME > | |
| class | ContextBuilder |
| std::ostream & | operator<< (std::ostream &str, const Context &context) |
Write out all other data associated with a given Context object. More... | |
| 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. More... | |
| std::istream & | operator>> (std::istream &str, Context &context) |
Read in all other data associated with a given Context object. More... | |
Detailed Description
Maintaining the HE scheme parameters.
Constructor & Destructor Documentation
◆ ~Context()
|
default |
Default destructor.
◆ Context() [1/3]
|
delete |
Deleted default constructor.
◆ Context() [2/3]
|
delete |
Deleted copy constructor.
- Parameters
-
other Contextto copy.
◆ Context() [3/3]
|
delete |
Deleted move constructor.
- Parameters
-
other Contextto move.
Member Function Documentation
◆ allPrimes()
|
inline |
◆ bitSizeOfQ()
|
inline |
Calculate the size of the ciphertext modulus Q in bits.
- Returns
- The bit size of the ciphertext modulus
Q = ctxtPrimes | specialPrimes.
◆ boundForRecryption()
|
inline |
Calculate the bound for recryption.
- Returns
- The bound for recryption.
◆ BPL()
|
inline |
◆ buildModChain()
| void helib::Context::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.
- Parameters
-
nBits Total number of bits required for the modulus chain. nDgts Number of digits/columns in the key-switching matrix. Default is 3. willBeBoostrappable Flag for initializing bootstrapping data. Default is false.skHwt The Hamming weight of the secret key. Default is 0. resolution The bit size of resolution of the modulus chain. Default is 3. bitsInSpecialPrimes The bit size of the special primes in the modulus chain. Default is 0.
◆ clearModChain()
|
inline |
◆ enableBootStrapping()
|
inline |
Initialises the recryption data.
- Parameters
-
mvec A std::vectorof unique prime factors ofm.build_cache Flag for building a cache for improved efficiency. Default is false. alsoThick Flag for initialising additional information needed for thick bootstrapping. Default is true.
◆ endBuildModChain()
| void helib::Context::endBuildModChain | ( | ) |
◆ fullPrimes()
|
inline |
◆ getAlMod()
|
inline |
Get the underlying AlMod object.
- Returns
- A
AlModobject.
◆ getCtxtPrimes() [1/2]
|
inline |
Getter method to the index set to the ciphertext primes.
- Returns
- A
constreference to the index set to the ciphertext primes.
◆ getCtxtPrimes() [2/2]
|
inline |
◆ getDigit()
|
inline |
Getter method to get a single digit.
- Parameters
-
i The ithe digit.
- Returns
- A
constreference to an index set that representing theith digit.
◆ getDigits()
|
inline |
Getter method to the digits.
- Returns
- A
constreference to astd::vectorof index sets that represent the digits.
◆ getE()
|
inline |
Getter method for the e parameter.
- Returns
- The e parameter.
◆ getEA()
|
inline |
Getter method returning the default EncryptedArray object of the created context.
- Returns
- A reference to the
EncryptedArrayobject.
- Note
- It is foreseen that this method will be eventually deprecated in favour of the alternative
getView.
◆ getEPrime()
|
inline |
Getter method for the e prime parameter.
- Returns
- The e prime parameter.
◆ getHwt()
|
inline |
Getter method for the Hamming weight value.
- Returns
- The Hamming weight value.
◆ getM()
|
inline |
Getter method for the m used to create this context.
- Returns
- The cyclotomic index
m.
◆ getModSizeTable()
|
inline |
Get the helper table to map required modulo-sizes to primeSets.
- Returns
- The table as
ModuliSizestype.
◆ getNSlots()
|
inline |
Getter method for the number of plaintext slots of the created context.
- Returns
- The number of plaintext slots
phi(m)/ord(p).
◆ getOrdP()
|
inline |
Getter method for the ord(p) of the created context.
- Returns
- The order of
pin(Z/mZ)^*.
◆ getP()
|
inline |
Getter method for the p used to create this context.
- Returns
- The plaintext modulus
p.
◆ getPhiM()
|
inline |
Getter method for the phi(m) of the created context.
- Returns
- The degree of the cyclotomic polynomial
Phi_m(X).
◆ getPowerfulConverter()
|
inline |
Get a powerful converter.
- Returns
- A powerful converter.
◆ getPPowR()
|
inline |
Getter method for the default p^r value of the created context.
- Returns
- The raised plaintext modulus
p^r.
- Note
- This value is not invariant: it is possible to work "view" objects that use different
PAlgebraobjects.
◆ getPrecision()
|
inline |
◆ getR()
|
inline |
◆ getRcData()
|
inline |
Getter method for a recryption data object.
- Returns
- A
constreference to the recryption data object.
◆ getScale()
|
inline |
Getter method for the scale.
- Returns
- the scale as a
double.
◆ getSlotRing()
|
inline |
Get a slot ring.
- Returns
- A reference to a
std::sharedpointer pointing to a slotRing.
◆ getSmallPrimes()
|
inline |
Getter method to the index set to the small primes.
- Returns
- A
constreference to the index set to the small primes.
◆ getSpecialPrimes()
|
inline |
Getter method to the index set to the special primes.
- Returns
- A
constreference to the index set to the special primes.
◆ getStdev()
|
inline |
Getter method for the standard deviation used..
- Returns
- the standard deviation as an
NTL::xdouble.
◆ getView()
|
inline |
Getter method returning the default view object of the created context.
- Returns
- A reference to the
viewobject.
◆ getZMStar()
|
inline |
Get the underlying zMStar object.
- Returns
- A
zMStarobject.
◆ inChain()
|
inline |
Check if value is already contained within the modulus chain.
- Parameters
-
p The number to check.
- Returns
trueifpis already contained within the modulus chain,falseotherwise.
◆ isBootstrappable()
|
inline |
Check if a Context is bootstrappable.
- Returns
trueif recryption data is found,falseotherwise.
◆ isCKKS()
|
inline |
◆ isZeroDivisor()
|
inline |
Check if a number is divisible by any of the primes in the modulus chain.
- Parameters
-
num The number to check.
- Returns
trueif the modulus chain contains at least one divisor ofnum, false otherwise.
◆ ithModulus()
|
inline |
Getter method for the small prime of the modulus chain at index i as a Cmodulus.
- Parameters
-
i Index of the desired small prime.
- Returns
- Reference to the small prime modulus at index
i.
◆ ithPrime()
|
inline |
Getter method for the small prime of the modulus chain at index i as a long.
- Parameters
-
i Index of the desired small prime.
- Returns
- The small prime of the modulus chain at index
i.
◆ logOfPrime()
|
inline |
Calculate the natural logarithm of the ith prime of the modulus chain.
- Parameters
-
i Index of the desired prime.
- Returns
- The natural logarithm of the
ith prime of the modulus chain.
◆ logOfProduct()
|
inline |
Calculate the natural logarithm of productOfPrimes(s) for a given set of primes s.
- Parameters
-
s The set of input primes.
- Returns
- The natural logarithm of the product of the input primes.
◆ noiseBoundForGaussian() [1/2]
|
inline |
◆ noiseBoundForGaussian() [2/2]
|
inline |
◆ noiseBoundForHWt()
|
inline |
◆ noiseBoundForMod()
|
inline |
◆ noiseBoundForSmall()
|
inline |
◆ noiseBoundForUniform() [1/2]
|
inline |
◆ noiseBoundForUniform() [2/2]
|
inline |
◆ numPrimes()
|
inline |
Return the total number of small primes in the modulus chain.
- Returns
- The total number of small primes in the modulus chain.
◆ operator!=()
|
inline |
◆ operator=() [1/2]
Deleted copy assignment.
- Parameters
-
other Contextto copy.
◆ operator=() [2/2]
Deleted move assignment.
- Parameters
-
other Contextto move.
◆ operator==()
| bool helib::Context::operator== | ( | const Context & | other | ) | const |
◆ printout()
| void helib::Context::printout | ( | std::ostream & | out = std::cout | ) | const |
Print out algebra and other important info.
- Parameters
-
out Output std::ostream.
◆ productOfPrimes() [1/2]
|
inline |
◆ productOfPrimes() [2/2]
| void helib::Context::productOfPrimes | ( | NTL::ZZ & | p, |
| const IndexSet & | s | ||
| ) | const |
Calculate the product of all primes in the given set.
- Parameters
-
p The product of the input primes. s The set of input primes to the product.
◆ readFrom()
|
static |
◆ readFromJSON() [1/2]
|
static |
Read from the JsonWrapper the serialized Context object.
- Parameters
-
j The JsonWrappercontaining the serializedContextobject.
- Returns
- The deserialized
Contextobject.
◆ readFromJSON() [2/2]
|
static |
◆ readPtrFrom()
|
static |
◆ readPtrFromJSON()
|
static |
Read from the JsonWrapper the serialized Context object.
- Parameters
-
j The JsonWrappercontaining the serializedContextobject.
- Returns
- Raw pointer to the deserialized
Contextobject.
◆ securityLevel()
|
inline |
An estimate for the security-level. This has a lower bound of 0.
- Parameters
-
hwt The Hamming weight of the secret key.
- Note
- This function uses experimental affine approximations to the lwe-estimator from https://bitbucket.org/malb/lwe-estimator/raw/HEAD/estimator.py, from Aug-2020 (see script in misc/estimator/lwe-estimator.sage).
Let s=3.2 if m is a power of two, or s=3.2*sqrt(m) otherwise. For the estimator we use alpha=s/q (so log2AlphaInv = log_2(q/s)), and n=phi(m).
◆ setModSizeTable()
|
inline |
Set the helper table to map required modulo-sizes to primeSets.
◆ shareEA()
|
inline |
Getter method returning the std::shared_ptr to default EncryptedArray object of the created context.
- Returns
- A reference to
std::shared_ptrto theEncryptedArrayobject.
◆ stdDevForRecryption()
|
inline |
Calculate the standard deviation for recryption.
- Returns
- The standard deviation for recryption.
◆ writeTo()
| void helib::Context::writeTo | ( | std::ostream & | str | ) | const |
Write out the Context object in binary format.
- Parameters
-
str Output std::ostream.
◆ writeToJSON() [1/2]
| JsonWrapper helib::Context::writeToJSON | ( | ) | const |
Write out the Context object to a JsonWrapper.
- Returns
- The
JsonWrapper.
◆ writeToJSON() [2/2]
| void helib::Context::writeToJSON | ( | std::ostream & | str | ) | const |
Write out the Context object to the output stream using JSON format.
- Parameters
-
str Output std::ostream.
Friends And Related Function Documentation
◆ ContextBuilder
|
friend |
◆ operator<<
|
friend |
◆ operator>>
|
friend |
◆ readContextBase
|
friend |
Read in the basic information m, p and r required to construct a Context object.
- Parameters
-
str Input std::istream.m Destination of the index of the cyclotomic polynomial. p Destination of the plaintext modulus. r Destination of BGV: The Hensel lifting parameter.CKKS: The bit precision.gens Destination of the generators of (Z/mZ)^*(other thanp).ords Destination of the orders of each of the generators of (Z/mZ)^*.
Member Data Documentation
◆ typeName
|
staticconstexpr |
Class label to be added to JSON serialization as object type information.
1.9.1