A Ctxt object holds a single ciphertext. More...

#include <Ctxt.h>

Public Member Functions

 Ctxt (const Ctxt &other)=default
 
 Ctxt (const PubKey &newPubKey, long newPtxtSpace=0)
 
 Ctxt (ZeroCtxtLike_type, const Ctxt &ctxt)
 
void DummyEncrypt (const NTL::ZZX &ptxt, double size=-1.0)
 
Ctxtoperator= (const Ctxt &other)
 
bool operator== (const Ctxt &other) const
 
bool operator!= (const Ctxt &other) const
 
bool equalsTo (const Ctxt &other, bool comparePkeys=true) const
 
void writeTo (std::ostream &str) const
 Write out the Ctxt object in binary format. More...
 
void read (std::istream &str)
 In-place read from the stream the serialized Ctxt object in binary format. More...
 
void writeToJSON (std::ostream &str) const
 Write out the ciphertext (Ctxt) object to the output stream using JSON format. More...
 
JsonWrapper writeToJSON () const
 Write out the ciphertext (Ctxt) object to a JsonWrapper. More...
 
void readJSON (std::istream &str)
 In-place read from the str std::istream the serialized ciphertext (Ctxt) object. More...
 
void readJSON (const JsonWrapper &j)
 In-place read from the JsonWrapper the serialized ciphertext (Ctxt) object. More...
 
void addedNoiseForCKKSDecryption (const SecKey &sk, double eps, NTL::ZZX &noise) const
 
Ciphertext maintenance
void reducePtxtSpace (long newPtxtSpace)
 Reduce plaintext space to a divisor of the original plaintext space. More...
 
void hackPtxtSpace (long newPtxtSpace)
 
void bumpNoiseBound (double factor)
 
void relin_CKKS_adjust ()
 
void reLinearize (long keyIdx=0)
 
CtxtcleanUp ()
 
void blindCtxt (const NTL::ZZX &poly)
 Add a high-noise encryption of the given constant. More...
 
NTL::xdouble modSwitchAddedNoiseBound () const
 Estimate the added noise. More...
 
void modUpToSet (const IndexSet &s)
 Modulus-switching up (to a larger modulus). Must have primeSet <= s, and s must contain either all the special primes or none of them. More...
 
void modDownToSet (const IndexSet &s)
 Modulus-switching down (to a smaller modulus). mod-switch down to primeSet \intersect s, after this call we have primeSet<=s. s must contain either all special primes or none of them. More...
 
void bringToSet (const IndexSet &s)
 make the primeSet equal to newPrimeSet, via modUpToSet and modDownToSet More...
 
double naturalSize () const
 
IndexSet naturalPrimeSet () const
 "natural size" is size before squaring More...
 
void dropSmallAndSpecialPrimes ()
 the corresponding primeSet More...
 
NTL::xdouble totalNoiseBound () const
 returns the total noise bound, which for CKKS is ptxtMag*ratFactor + noiseBound More...
 
double errorBound () const
 for CKKS, returns a bound on the absolute error (which is noiseBound/ratFactor); for BGV, returns 0. More...
 
double capacity () const
 returns the "capacity" of a ciphertext, which is the log2 of the ratio of the modulus to the total noise bound More...
 
double logOfPrimeSet () const
 returns the log of the prime set More...
 
long bitCapacity () const
 the capacity in bits, returned as an integer More...
 
double rawModSwitch (std::vector< NTL::ZZX > &zzParts, long toModulus) const
 Special-purpose modulus-switching for bootstrapping. More...
 
void evalPoly (const NTL::ZZX &poly)
 compute the power X,X^2,...,X^n More...
 
Utility methods
void clear ()
 
bool isEmpty () const
 Is this an empty ciphertext without any parts. More...
 
bool inCanonicalForm (long keyID=0) const
 A canonical ciphertext has (at most) handles pointing to (1,s) More...
 
bool isCorrect () const
 Would this ciphertext be decrypted without errors? More...
 
const ContextgetContext () const
 
const PubKeygetPubKey () const
 
const IndexSetgetPrimeSet () const
 
long getPtxtSpace () const
 
const NTL::xdouble & getNoiseBound () const
 
const NTL::xdouble & getRatFactor () const
 
const NTL::xdouble & getPtxtMag () const
 
void setPtxtMag (const NTL::xdouble &z)
 
long getKeyID () const
 
bool isCKKS () const
 
long effectiveR () const
 
double log_of_ratio () const
 Returns log(noiseBound) - log(q) More...
 

Static Public Member Functions

static Ctxt readFrom (std::istream &str, const PubKey &pubKey)
 Read from the stream the serialized Ctxt object in binary format. More...
 
static Ctxt readFromJSON (std::istream &str, const PubKey &pubKey)
 Read from the stream the serialized ciphertext (Ctxt) object using JSON format. More...
 
static Ctxt readFromJSON (const JsonWrapper &j, const PubKey &pubKey)
 Read from the JsonWrapper the serialized ciphertext (Ctxt) object. More...
 
static void equalizeRationalFactors (Ctxt &c1, Ctxt &c2)
 

Static Public Attributes

static constexpr std::string_view typeName = "Ctxt"
 Class label to be added to JSON serialization as object type information. More...
 

Friends

class PubKey
 
class SecKey
 
class BasicAutomorphPrecon
 
std::istream & operator>> (std::istream &str, Ctxt &ctxt)
 
std::ostream & operator<< (std::ostream &str, const Ctxt &ctxt)
 

Ciphertext arithmetic

void negate ()
 
Ctxtoperator+= (const Ctxt &other)
 
Ctxtoperator-= (const Ctxt &other)
 
void addCtxt (const Ctxt &other, bool negative=false)
 
void multLowLvl (const Ctxt &other, bool destructive=false)
 
Ctxtoperator*= (const Ctxt &other)
 
void automorph (long k)
 
Ctxtoperator>>= (long k)
 
void complexConj ()
 
void smartAutomorph (long k)
 automorphism with re-linearization More...
 
void frobeniusAutomorph (long j)
 applies the automorphism p^j using smartAutomorphism More...
 
Ctxtoperator*= (const NTL::ZZX &poly)
 Times equals operator with a ZZX. More...
 
void addConstant (const DoubleCRT &dcrt, double size=-1.0)
 
void addConstant (const NTL::ZZX &poly, double size=-1.0)
 
template<typename Scheme >
void addConstant (const Ptxt< Scheme > &ptxt, bool neg=false)
 Add a plaintext to this Ctxt. More...
 
template<typename Scheme >
Ctxtoperator+= (const Ptxt< Scheme > &ptxt)
 
template<typename Scheme >
Ctxtoperator-= (const Ptxt< Scheme > &ptxt)
 
void addConstantCKKS (std::pair< long, long >)
 add a rational number in the form a/b, a,b are long More...
 
void addConstantCKKS (double x)
 
void addConstantCKKS (const DoubleCRT &dcrt, NTL::xdouble size=NTL::xdouble(-1.0), NTL::xdouble factor=NTL::xdouble(-1.0))
 
void addConstantCKKS (const NTL::ZZX &poly, NTL::xdouble size=NTL::xdouble(-1.0), NTL::xdouble factor=NTL::xdouble(-1.0))
 
void addConstantCKKS (const std::vector< std::complex< double >> &ptxt)
 
void addConstantCKKS (const Ptxt< CKKS > &ptxt)
 Add a CKKS plaintext to this Ctxt. More...
 
void addConstantCKKS (const NTL::ZZ &c)
 
void multByConstant (const DoubleCRT &dcrt, double size=-1.0)
 
void multByConstant (const NTL::ZZX &poly, double size=-1.0)
 
void multByConstant (const zzX &poly, double size=-1.0)
 
void multByConstant (const PtxtArray &ptxt)
 Multiply a Ctxt with a specified plaintext constant. More...
 
void multByConstant (const EncodedPtxt &ptxt)
 Multiply a Ctxt with a specified plaintext constant. More...
 
void multByConstant (const FatEncodedPtxt &ptxt)
 Multiply a Ctxt with a specified plaintext constant. More...
 
void multByConstant (const NTL::ZZ &ptxt)
 Multiply a Ctxt with an NTL::ZZ scalar. More...
 
void multByConstant (long ptxt)
 Multiply a Ctxt with a long scalar. More...
 
void multByConstant (double ptxt)
 Multiply a Ctxt with a double scalar. More...
 
void multByConstant (NTL::xdouble ptxt)
 Multiply a Ctxt with an NTL::xdouble scalar. More...
 
Ctxtoperator*= (const PtxtArray &ptxt)
 Times equals operator with a plaintext constant. More...
 
Ctxtoperator*= (const EncodedPtxt &ptxt)
 Times equals operator with a plaintext constant. More...
 
Ctxtoperator*= (const FatEncodedPtxt &ptxt)
 Times equals operator with a plaintext constant. More...
 
Ctxtoperator*= (const NTL::ZZ &ptxt)
 Times equals operator with an NTL::ZZ scalar. More...
 
Ctxtoperator*= (long ptxt)
 Times equals operator with a long scalar. More...
 
Ctxtoperator*= (double ptxt)
 Times equals operator with a double scalar. More...
 
Ctxtoperator*= (NTL::xdouble ptxt)
 Times equals operator with an NTL::xdouble scalar. More...
 
void addConstant (const PtxtArray &ptxt, bool neg=false)
 Add to a Ctxt a specified plaintext constant. More...
 
void addConstant (const EncodedPtxt &ptxt, bool neg=false)
 Add to a Ctxt a specified plaintext constant. More...
 
void addConstant (const FatEncodedPtxt &ptxt, bool neg=false)
 Add to a Ctxt a specified plaintext constant. More...
 
void addConstant (const NTL::ZZ &ptxt, bool neg=false)
 Add to a Ctxt an NTL::ZZ scalar. More...
 
void addConstant (long ptxt, bool neg=false)
 Add to a Ctxt a long scalar. More...
 
void addConstant (double ptxt, bool neg=false)
 Add to a Ctxt a double scalar. More...
 
void addConstant (NTL::xdouble ptxt, bool neg=false)
 Add to a Ctxt an NTL::xdouble scalar. More...
 
Ctxtoperator+= (const PtxtArray &ptxt)
 Plus equals operator with plaintext constant. More...
 
Ctxtoperator+= (const EncodedPtxt &ptxt)
 Plus equals operator with plaintext constant. More...
 
Ctxtoperator+= (const FatEncodedPtxt &ptxt)
 Plus equals operator with plaintext constant. More...
 
Ctxtoperator+= (const NTL::ZZ &ptxt)
 Plus equals operator with an NTL::ZZ scalar. More...
 
Ctxtoperator+= (long ptxt)
 Plus equals operator with a long scalar. More...
 
Ctxtoperator+= (double ptxt)
 Plus equals operator with a double scalar. More...
 
Ctxtoperator+= (NTL::xdouble ptxt)
 Plus equals operator with an NTL::xdouble scalar. More...
 
Ctxtoperator-= (const PtxtArray &ptxt)
 Minus equals operator with plaintext constant. More...
 
Ctxtoperator-= (const EncodedPtxt &ptxt)
 Minus equals operator with plaintext constant. More...
 
Ctxtoperator-= (const FatEncodedPtxt &ptxt)
 Minus equals operator with plaintext constant. More...
 
Ctxtoperator-= (const NTL::ZZ &ptxt)
 Minus equals operator with an NTL::ZZ scalar. More...
 
Ctxtoperator-= (long ptxt)
 Minus equals operator with a long scalar. More...
 
Ctxtoperator-= (double ptxt)
 Minus equals operator with a double scalar. More...
 
Ctxtoperator-= (NTL::xdouble ptxt)
 Minus equals operator with an NTL::xdouble scalar. More...
 
template<typename Scheme >
void multByConstant (const Ptxt< Scheme > &ptxt)
 Multiply a plaintext to this Ctxt. More...
 
template<typename Scheme >
Ctxtoperator*= (const Ptxt< Scheme > &ptxt)
 
void multByConstantCKKS (double x)
 multiply by a rational number or floating point More...
 
void multByConstantCKKS (std::pair< long, long > num)
 
void multByConstantCKKS (const DoubleCRT &dcrt, NTL::xdouble size=NTL::xdouble(-1.0), NTL::xdouble factor=NTL::xdouble(-1.0), double roundingErr=-1.0)
 
void multByConstantCKKS (const NTL::ZZX &poly, NTL::xdouble size=NTL::xdouble(-1.0), NTL::xdouble factor=NTL::xdouble(-1.0), double roundingErr=-1.0)
 
void multByConstantCKKS (const Ptxt< CKKS > &ptxt)
 Multiply a CKKS plaintext to this Ctxt. More...
 
void multByConstantCKKS (const std::vector< std::complex< double >> &ptxt)
 
void xorConstant (const DoubleCRT &poly, UNUSED double size=-1.0)
 
void xorConstant (const NTL::ZZX &poly, double size=-1.0)
 
void nxorConstant (const DoubleCRT &poly, UNUSED double size=-1.0)
 
void nxorConstant (const NTL::ZZX &poly, double size=-1.0)
 
void divideByP ()
 
void multByP (long e=1)
 
void divideBy2 ()
 
void extractBits (std::vector< Ctxt > &bits, long nBits2extract=0)
 
void multiplyBy (const Ctxt &other)
 
void multiplyBy2 (const Ctxt &other1, const Ctxt &other2)
 
void square ()
 
void cube ()
 
void power (long e)
 raise ciphertext to some power More...
 

Detailed Description

A Ctxt object holds a single ciphertext.

The class Ctxt includes a std::vector<CtxtPart>: For a Ctxt c, c[i] is the i'th ciphertext part, which can be used also as a DoubleCRT object (since CtxtPart is derived from DoubleCRT). By convention, c[0], the first CtxtPart object in the std::vector, has skHndl that points to 1 (i.e., it is just added in upon decryption, without being multiplied by anything). We maintain the invariance that all the parts of a ciphertext are defined relative to the same set of primes.

A ciphertext contains also pointers to the general parameters of this FHE instance and the public key, and a high-probability bound on the noise magnitude (kept in the noiseBound data member). The noise bound is a bound on the l-infinity norm of the canonical embedding of the noise polynomial, namely its evaluation in roots of the ring polynomial (which are the complex primitive roots of unity). The noise bound is added on addition, multiplied on multiplications, remains unchanged for automorphism, and is roughly scaled down by mod-switching with some added factor, and similarly scaled up by key-switching with some added factor.

Constructor & Destructor Documentation

◆ Ctxt() [1/3]

helib::Ctxt::Ctxt ( const Ctxt other)
default

◆ Ctxt() [2/3]

helib::Ctxt::Ctxt ( const PubKey newPubKey,
long  newPtxtSpace = 0 
)
explicit

◆ Ctxt() [3/3]

helib::Ctxt::Ctxt ( ZeroCtxtLike_type  ,
const Ctxt ctxt 
)

Member Function Documentation

◆ addConstant() [1/10]

void helib::Ctxt::addConstant ( const DoubleCRT dcrt,
double  size = -1.0 
)

Add a constant polynomial. If provided, size should be a high-probability bound on the L-infty norm of the canonical embedding Otherwise, for the DoubleCRT variant, a bound based on the assumption that the coefficients are uniformly and independently distributed over [-ptxtSpace/2, ptxtSpace/2]. For the other variants, explicit bounds are computed (if not CKKS).

◆ addConstant() [2/10]

void helib::Ctxt::addConstant ( const EncodedPtxt ptxt,
bool  neg = false 
)

Add to a Ctxt a specified plaintext constant.

Parameters
ptxtThe constant to add as an EncodedPtxt object.
negFlag to specify if the constant is negative. Default is false.
Note
EncodedPtxt is a plaintext object containing NTL::ZZX data.

◆ addConstant() [3/10]

void helib::Ctxt::addConstant ( const FatEncodedPtxt ptxt,
bool  neg = false 
)

Add to a Ctxt a specified plaintext constant.

Parameters
ptxtThe constant to add as a FatEncodedPtxt object.
negFlag to specify if the constant is negative. Default is false.
Note
FatEncodedPtxt is a plaintext object containing helib::DoubleCRT data.

◆ addConstant() [4/10]

void helib::Ctxt::addConstant ( const NTL::ZZ &  ptxt,
bool  neg = false 
)

Add to a Ctxt an NTL::ZZ scalar.

Parameters
ptxtThe scalar to add.
negFlag to specify if the constant is negative. Default is false.

◆ addConstant() [5/10]

void helib::Ctxt::addConstant ( const NTL::ZZX &  poly,
double  size = -1.0 
)

◆ addConstant() [6/10]

template<typename Scheme >
void helib::Ctxt::addConstant ( const Ptxt< Scheme > &  ptxt,
bool  neg = false 
)
inline

Add a plaintext to this Ctxt.

Parameters
ptxtPlaintext Ptxt object with which to add.

◆ addConstant() [7/10]

void helib::Ctxt::addConstant ( const PtxtArray ptxt,
bool  neg = false 
)

Add to a Ctxt a specified plaintext constant.

Parameters
ptxtThe constant to add as a PtxtArray object.
negFlag to specify if the constant is negative. Default is false.

◆ addConstant() [8/10]

void helib::Ctxt::addConstant ( double  ptxt,
bool  neg = false 
)

Add to a Ctxt a double scalar.

Parameters
ptxtThe scalar to add.
negFlag to specify if the constant is negative. Default is false.

◆ addConstant() [9/10]

void helib::Ctxt::addConstant ( long  ptxt,
bool  neg = false 
)

Add to a Ctxt a long scalar.

Parameters
ptxtThe scalar to add.
negFlag to specify if the constant is negative. Default is false.

◆ addConstant() [10/10]

void helib::Ctxt::addConstant ( NTL::xdouble  ptxt,
bool  neg = false 
)

Add to a Ctxt an NTL::xdouble scalar.

Parameters
ptxtThe scalar to add.
negFlag to specify if the constant is negative. Default is false.

◆ addConstantCKKS() [1/7]

void helib::Ctxt::addConstantCKKS ( const DoubleCRT dcrt,
NTL::xdouble  size = NTL::xdouble(-1.0),
NTL::xdouble  factor = NTL::xdouble(-1.0) 
)
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(const FatEncodedPtxt& ptxt) instead.

◆ addConstantCKKS() [2/7]

void helib::Ctxt::addConstantCKKS ( const NTL::ZZ &  c)
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(const NTL::ZZ& ptxt) instead.

◆ addConstantCKKS() [3/7]

void helib::Ctxt::addConstantCKKS ( const NTL::ZZX &  poly,
NTL::xdouble  size = NTL::xdouble(-1.0),
NTL::xdouble  factor = NTL::xdouble(-1.0) 
)
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(const EncodedPtxt& ptxt) instead.

◆ addConstantCKKS() [4/7]

void helib::Ctxt::addConstantCKKS ( const Ptxt< CKKS > &  ptxt)

Add a CKKS plaintext to this Ctxt.

Parameters
ptxtPlaintext Ptxt object with which to add.
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(const PtxtArray& ptxt) instead.

◆ addConstantCKKS() [5/7]

void helib::Ctxt::addConstantCKKS ( const std::vector< std::complex< double >> &  ptxt)
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(const PtxtArray& ptxt) instead.

◆ addConstantCKKS() [6/7]

void helib::Ctxt::addConstantCKKS ( double  x)
inline
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(double ptxt) instead.

◆ addConstantCKKS() [7/7]

void helib::Ctxt::addConstantCKKS ( std::pair< long, long >  num)

add a rational number in the form a/b, a,b are long

Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator+=(double ptxt) instead.

◆ addCtxt()

void helib::Ctxt::addCtxt ( const Ctxt other,
bool  negative = false 
)

◆ addedNoiseForCKKSDecryption()

void helib::Ctxt::addedNoiseForCKKSDecryption ( const SecKey sk,
double  eps,
NTL::ZZX &  noise 
) const

◆ automorph()

void helib::Ctxt::automorph ( long  k)

◆ bitCapacity()

long helib::Ctxt::bitCapacity ( ) const
inline

the capacity in bits, returned as an integer

◆ blindCtxt()

void helib::Ctxt::blindCtxt ( const NTL::ZZX &  poly)

Add a high-noise encryption of the given constant.

◆ bringToSet()

void helib::Ctxt::bringToSet ( const IndexSet s)

make the primeSet equal to newPrimeSet, via modUpToSet and modDownToSet

◆ bumpNoiseBound()

void helib::Ctxt::bumpNoiseBound ( double  factor)
inline

◆ capacity()

double helib::Ctxt::capacity ( ) const
inline

returns the "capacity" of a ciphertext, which is the log2 of the ratio of the modulus to the total noise bound

◆ cleanUp()

Ctxt & helib::Ctxt::cleanUp ( )

◆ clear()

void helib::Ctxt::clear ( )
inline

◆ complexConj()

void helib::Ctxt::complexConj ( )

◆ cube()

void helib::Ctxt::cube ( )
inline

◆ divideBy2()

void helib::Ctxt::divideBy2 ( )

◆ divideByP()

void helib::Ctxt::divideByP ( )

Divide a ciphertext by p, for plaintext space p^r, r>1. It is assumed that the ciphertext encrypts a polynomial which is zero mod p. If this is not the case then the result will not be a valid ciphertext anymore. As a side-effect, the plaintext space is reduced from p^r to p^{r-1}.

◆ dropSmallAndSpecialPrimes()

void helib::Ctxt::dropSmallAndSpecialPrimes ( )

the corresponding primeSet

drop all smallPrimes and specialPrimes, adding ctxtPrimes as necessary to ensure that the scaled noise is above the modulus-switching added noise term.

◆ DummyEncrypt()

void helib::Ctxt::DummyEncrypt ( const NTL::ZZX &  ptxt,
double  size = -1.0 
)

Dummy encryption, just encodes the plaintext in a Ctxt object If provided, size should be a high-probability bound on the L-infty norm of the canonical embedding

◆ effectiveR()

long helib::Ctxt::effectiveR ( ) const
inline

◆ equalizeRationalFactors()

void helib::Ctxt::equalizeRationalFactors ( Ctxt c1,
Ctxt c2 
)
static

◆ equalsTo()

bool helib::Ctxt::equalsTo ( const Ctxt other,
bool  comparePkeys = true 
) const

◆ errorBound()

double helib::Ctxt::errorBound ( ) const
inline

for CKKS, returns a bound on the absolute error (which is noiseBound/ratFactor); for BGV, returns 0.

◆ evalPoly()

void helib::Ctxt::evalPoly ( const NTL::ZZX &  poly)

compute the power X,X^2,...,X^n

Evaluate the cleartext poly on the encrypted ciphertext

◆ extractBits()

void helib::Ctxt::extractBits ( std::vector< Ctxt > &  bits,
long  nBits2extract = 0 
)
inline

◆ frobeniusAutomorph()

void helib::Ctxt::frobeniusAutomorph ( long  j)

applies the automorphism p^j using smartAutomorphism

◆ getContext()

const Context& helib::Ctxt::getContext ( ) const
inline

◆ getKeyID()

long helib::Ctxt::getKeyID ( ) const

◆ getNoiseBound()

const NTL::xdouble& helib::Ctxt::getNoiseBound ( ) const
inline

◆ getPrimeSet()

const IndexSet& helib::Ctxt::getPrimeSet ( ) const
inline

◆ getPtxtMag()

const NTL::xdouble& helib::Ctxt::getPtxtMag ( ) const
inline

◆ getPtxtSpace()

long helib::Ctxt::getPtxtSpace ( ) const
inline

◆ getPubKey()

const PubKey& helib::Ctxt::getPubKey ( ) const
inline

◆ getRatFactor()

const NTL::xdouble& helib::Ctxt::getRatFactor ( ) const
inline

◆ hackPtxtSpace()

void helib::Ctxt::hackPtxtSpace ( long  newPtxtSpace)
inline

◆ inCanonicalForm()

bool helib::Ctxt::inCanonicalForm ( long  keyID = 0) const
inline

A canonical ciphertext has (at most) handles pointing to (1,s)

◆ isCKKS()

bool helib::Ctxt::isCKKS ( ) const
inline

◆ isCorrect()

bool helib::Ctxt::isCorrect ( ) const

Would this ciphertext be decrypted without errors?

◆ isEmpty()

bool helib::Ctxt::isEmpty ( ) const
inline

Is this an empty ciphertext without any parts.

◆ log_of_ratio()

double helib::Ctxt::log_of_ratio ( ) const
inline

Returns log(noiseBound) - log(q)

Deprecated:
This is deprecated. Please use Ctxt::capacity() instead.

◆ logOfPrimeSet()

double helib::Ctxt::logOfPrimeSet ( ) const
inline

returns the log of the prime set

◆ modDownToSet()

void helib::Ctxt::modDownToSet ( const IndexSet s)

Modulus-switching down (to a smaller modulus). mod-switch down to primeSet \intersect s, after this call we have primeSet<=s. s must contain either all special primes or none of them.

◆ modSwitchAddedNoiseBound()

NTL::xdouble helib::Ctxt::modSwitchAddedNoiseBound ( ) const

Estimate the added noise.

◆ modUpToSet()

void helib::Ctxt::modUpToSet ( const IndexSet s)

Modulus-switching up (to a larger modulus). Must have primeSet <= s, and s must contain either all the special primes or none of them.

◆ multByConstant() [1/11]

void helib::Ctxt::multByConstant ( const DoubleCRT dcrt,
double  size = -1.0 
)

Multiply-by-constant. If the size is not given, for the DCRT variant, we use a high probability bound assuming "random" coefficients mod ptxtSpace, while for the other variants, we use explicitly computed bounds (if not CKKS).

◆ multByConstant() [2/11]

void helib::Ctxt::multByConstant ( const EncodedPtxt ptxt)

Multiply a Ctxt with a specified plaintext constant.

Parameters
ptxtThe constant to multiply as an EncodedPtxt object.
Note
EncodedPtxt is a plaintext object containing NTL::ZZX data.

◆ multByConstant() [3/11]

void helib::Ctxt::multByConstant ( const FatEncodedPtxt ptxt)

Multiply a Ctxt with a specified plaintext constant.

Parameters
ptxtThe constant to multiply as a FatEncodedPtxt object.
Note
FatEncodedPtxt is a plaintext object containing helib::DoubleCRT data.

◆ multByConstant() [4/11]

void helib::Ctxt::multByConstant ( const NTL::ZZ &  ptxt)

Multiply a Ctxt with an NTL::ZZ scalar.

Parameters
ptxtScalar to multiply.

◆ multByConstant() [5/11]

void helib::Ctxt::multByConstant ( const NTL::ZZX &  poly,
double  size = -1.0 
)

◆ multByConstant() [6/11]

template<typename Scheme >
void helib::Ctxt::multByConstant ( const Ptxt< Scheme > &  ptxt)
inline

Multiply a plaintext to this Ctxt.

Parameters
ptxtPlaintext Ptxt object with which to multiply.

◆ multByConstant() [7/11]

void helib::Ctxt::multByConstant ( const PtxtArray ptxt)

Multiply a Ctxt with a specified plaintext constant.

Parameters
ptxtThe constant to multiply as a PtxtArray object.

◆ multByConstant() [8/11]

void helib::Ctxt::multByConstant ( const zzX poly,
double  size = -1.0 
)

◆ multByConstant() [9/11]

void helib::Ctxt::multByConstant ( double  ptxt)

Multiply a Ctxt with a double scalar.

Parameters
ptxtScalar to multiply.

◆ multByConstant() [10/11]

void helib::Ctxt::multByConstant ( long  ptxt)

Multiply a Ctxt with a long scalar.

Parameters
ptxtScalar to multiply.

◆ multByConstant() [11/11]

void helib::Ctxt::multByConstant ( NTL::xdouble  ptxt)

Multiply a Ctxt with an NTL::xdouble scalar.

Parameters
ptxtScalar to multiply.

◆ multByConstantCKKS() [1/6]

void helib::Ctxt::multByConstantCKKS ( const DoubleCRT dcrt,
NTL::xdouble  size = NTL::xdouble(-1.0),
NTL::xdouble  factor = NTL::xdouble(-1.0),
double  roundingErr = -1.0 
)
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator*=(const FatEncodedPtxt& ptxt) instead.

◆ multByConstantCKKS() [2/6]

void helib::Ctxt::multByConstantCKKS ( const NTL::ZZX &  poly,
NTL::xdouble  size = NTL::xdouble(-1.0),
NTL::xdouble  factor = NTL::xdouble(-1.0),
double  roundingErr = -1.0 
)
inline
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator*=(const EncodedPtxt& ptxt) instead.

◆ multByConstantCKKS() [3/6]

void helib::Ctxt::multByConstantCKKS ( const Ptxt< CKKS > &  ptxt)

Multiply a CKKS plaintext to this Ctxt.

Parameters
ptxtPlaintext Ptxt object polynomial with which to multiply.
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator*=(const PtxtArray& ptxt) instead.

◆ multByConstantCKKS() [4/6]

void helib::Ctxt::multByConstantCKKS ( const std::vector< std::complex< double >> &  ptxt)
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator*=(const PtxtArray& ptxt) instead.

◆ multByConstantCKKS() [5/6]

void helib::Ctxt::multByConstantCKKS ( double  x)
inline

multiply by a rational number or floating point

Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator*=(double ptxt) instead.

◆ multByConstantCKKS() [6/6]

void helib::Ctxt::multByConstantCKKS ( std::pair< long, long >  num)
inline
Deprecated:
This function is deprecated in favor of a newer API. Please use Ctxt::operator*=(double ptxt) instead.

◆ multByP()

void helib::Ctxt::multByP ( long  e = 1)
inline

Multiply ciphertext by p^e, for plaintext space p^r. This also has the side-effect of increasing the plaintext space to p^{r+e}.

◆ multiplyBy()

void helib::Ctxt::multiplyBy ( const Ctxt other)

◆ multiplyBy2()

void helib::Ctxt::multiplyBy2 ( const Ctxt other1,
const Ctxt other2 
)

◆ multLowLvl()

void helib::Ctxt::multLowLvl ( const Ctxt other,
bool  destructive = false 
)

◆ naturalPrimeSet()

IndexSet helib::Ctxt::naturalPrimeSet ( ) const

"natural size" is size before squaring

◆ naturalSize()

double helib::Ctxt::naturalSize ( ) const

◆ negate()

void helib::Ctxt::negate ( )

◆ nxorConstant() [1/2]

void helib::Ctxt::nxorConstant ( const DoubleCRT poly,
UNUSED double  size = -1.0 
)
inline

◆ nxorConstant() [2/2]

void helib::Ctxt::nxorConstant ( const NTL::ZZX &  poly,
double  size = -1.0 
)
inline

◆ operator!=()

bool helib::Ctxt::operator!= ( const Ctxt other) const
inline

◆ operator*=() [1/10]

Ctxt& helib::Ctxt::operator*= ( const Ctxt other)
inline

◆ operator*=() [2/10]

Ctxt& helib::Ctxt::operator*= ( const EncodedPtxt ptxt)
inline

Times equals operator with a plaintext constant.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.
Note
EncodedPtxt is a plaintext object containing NTL::ZZX data.

◆ operator*=() [3/10]

Ctxt& helib::Ctxt::operator*= ( const FatEncodedPtxt ptxt)
inline

Times equals operator with a plaintext constant.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.
Note
FatEncodedPtxt is a plaintext object containing helib::DoubleCRT data.

◆ operator*=() [4/10]

Ctxt& helib::Ctxt::operator*= ( const NTL::ZZ &  ptxt)
inline

Times equals operator with an NTL::ZZ scalar.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.

◆ operator*=() [5/10]

Ctxt & helib::Ctxt::operator*= ( const NTL::ZZX &  poly)

Times equals operator with a ZZX.

Parameters
polyElement by which to multiply.
Returns
Reference to *this post multiplication.
Deprecated:
This function is deprecated in favor of a new EncodedPtxt-based API.
Please use Ctxt::operator*=(const EncodedPtxt& ptxt) instead.

◆ operator*=() [6/10]

template<typename Scheme >
Ctxt& helib::Ctxt::operator*= ( const Ptxt< Scheme > &  ptxt)
inline

◆ operator*=() [7/10]

Ctxt& helib::Ctxt::operator*= ( const PtxtArray ptxt)
inline

Times equals operator with a plaintext constant.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.

◆ operator*=() [8/10]

Ctxt& helib::Ctxt::operator*= ( double  ptxt)
inline

Times equals operator with a double scalar.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.

◆ operator*=() [9/10]

Ctxt& helib::Ctxt::operator*= ( long  ptxt)
inline

Times equals operator with a long scalar.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.

◆ operator*=() [10/10]

Ctxt& helib::Ctxt::operator*= ( NTL::xdouble  ptxt)
inline

Times equals operator with an NTL::xdouble scalar.

Parameters
ptxtRight hand side of multiplication.
Returns
Reference to *this post multiplication.

◆ operator+=() [1/9]

Ctxt& helib::Ctxt::operator+= ( const Ctxt other)
inline

◆ operator+=() [2/9]

Ctxt& helib::Ctxt::operator+= ( const EncodedPtxt ptxt)
inline

Plus equals operator with plaintext constant.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.
Note
EncodedPtxt is a plaintext object containing NTL::ZZX data.

◆ operator+=() [3/9]

Ctxt& helib::Ctxt::operator+= ( const FatEncodedPtxt ptxt)
inline

Plus equals operator with plaintext constant.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.
Note
FatEncodedPtxt is a plaintext object containing helib::DoubleCRT data.

◆ operator+=() [4/9]

Ctxt& helib::Ctxt::operator+= ( const NTL::ZZ &  ptxt)
inline

Plus equals operator with an NTL::ZZ scalar.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.

◆ operator+=() [5/9]

template<typename Scheme >
Ctxt& helib::Ctxt::operator+= ( const Ptxt< Scheme > &  ptxt)
inline

◆ operator+=() [6/9]

Ctxt& helib::Ctxt::operator+= ( const PtxtArray ptxt)
inline

Plus equals operator with plaintext constant.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.

◆ operator+=() [7/9]

Ctxt& helib::Ctxt::operator+= ( double  ptxt)
inline

Plus equals operator with a double scalar.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.

◆ operator+=() [8/9]

Ctxt& helib::Ctxt::operator+= ( long  ptxt)
inline

Plus equals operator with a long scalar.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.

◆ operator+=() [9/9]

Ctxt& helib::Ctxt::operator+= ( NTL::xdouble  ptxt)
inline

Plus equals operator with an NTL::xdouble scalar.

Parameters
ptxtRight hand side of addition.
Returns
Reference to *this post addition.

◆ operator-=() [1/9]

Ctxt& helib::Ctxt::operator-= ( const Ctxt other)
inline

◆ operator-=() [2/9]

Ctxt& helib::Ctxt::operator-= ( const EncodedPtxt ptxt)
inline

Minus equals operator with plaintext constant.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.
Note
EncodedPtxt is a plaintext object containing NTL::ZZX data.

◆ operator-=() [3/9]

Ctxt& helib::Ctxt::operator-= ( const FatEncodedPtxt ptxt)
inline

Minus equals operator with plaintext constant.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.
Note
FatEncodedPtxt is a plaintext object containing helib::DoubleCRT data.

◆ operator-=() [4/9]

Ctxt& helib::Ctxt::operator-= ( const NTL::ZZ &  ptxt)
inline

Minus equals operator with an NTL::ZZ scalar.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.

◆ operator-=() [5/9]

template<typename Scheme >
Ctxt& helib::Ctxt::operator-= ( const Ptxt< Scheme > &  ptxt)
inline

◆ operator-=() [6/9]

Ctxt& helib::Ctxt::operator-= ( const PtxtArray ptxt)
inline

Minus equals operator with plaintext constant.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.

◆ operator-=() [7/9]

Ctxt& helib::Ctxt::operator-= ( double  ptxt)
inline

Minus equals operator with a double scalar.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.

◆ operator-=() [8/9]

Ctxt& helib::Ctxt::operator-= ( long  ptxt)
inline

Minus equals operator with a long scalar.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.

◆ operator-=() [9/9]

Ctxt& helib::Ctxt::operator-= ( NTL::xdouble  ptxt)
inline

Minus equals operator with an NTL::xdouble scalar.

Parameters
ptxtRight hand side of subtraction.
Returns
Reference to *this post subtraction.

◆ operator=()

Ctxt& helib::Ctxt::operator= ( const Ctxt other)
inline

◆ operator==()

bool helib::Ctxt::operator== ( const Ctxt other) const
inline

◆ operator>>=()

Ctxt& helib::Ctxt::operator>>= ( long  k)
inline

◆ power()

void helib::Ctxt::power ( long  e)

raise ciphertext to some power

◆ rawModSwitch()

double helib::Ctxt::rawModSwitch ( std::vector< NTL::ZZX > &  zzParts,
long  toModulus 
) const

Special-purpose modulus-switching for bootstrapping.

Mod-switch to an externally-supplied modulus. The modulus need not be in the moduli-chain in the context, and does not even need to be a prime. The ciphertext *this is not affected, instead the result is returned in the zzParts std::vector, as a std::vector of ZZX'es. Returns an estimate for the scaled noise (not including the additive mod switching noise)

◆ read()

void helib::Ctxt::read ( std::istream &  str)

In-place read from the stream the serialized Ctxt object in binary format.

Parameters
strInput std::istream.

◆ readFrom()

Ctxt helib::Ctxt::readFrom ( std::istream &  str,
const PubKey pubKey 
)
static

Read from the stream the serialized Ctxt object in binary format.

Parameters
strInput std::istream.
Returns
The deserialized Ctxt object.

◆ readFromJSON() [1/2]

Ctxt helib::Ctxt::readFromJSON ( const JsonWrapper j,
const PubKey pubKey 
)
static

Read from the JsonWrapper the serialized ciphertext (Ctxt) object.

Parameters
jThe JsonWrapper containing the serialized Ctxt object.
pubKeyThe PubKey to be used.
Returns
The deserialized Ctxt object.

◆ readFromJSON() [2/2]

Ctxt helib::Ctxt::readFromJSON ( std::istream &  str,
const PubKey pubKey 
)
static

Read from the stream the serialized ciphertext (Ctxt) object using JSON format.

Parameters
strInput std::istream.
pubKeyThe PubKey to be used.
Returns
The deserialized Ctxt object.

◆ readJSON() [1/2]

void helib::Ctxt::readJSON ( const JsonWrapper j)

In-place read from the JsonWrapper the serialized ciphertext (Ctxt) object.

Parameters
jThe JsonWrapper containing the serialized Ctxt object.

◆ readJSON() [2/2]

void helib::Ctxt::readJSON ( std::istream &  str)

In-place read from the str std::istream the serialized ciphertext (Ctxt) object.

Parameters
jThe JsonWrapper containing the serialized Ctxt object.

◆ reducePtxtSpace()

void helib::Ctxt::reducePtxtSpace ( long  newPtxtSpace)

Reduce plaintext space to a divisor of the original plaintext space.

◆ relin_CKKS_adjust()

void helib::Ctxt::relin_CKKS_adjust ( )

◆ reLinearize()

void helib::Ctxt::reLinearize ( long  keyIdx = 0)

◆ setPtxtMag()

void helib::Ctxt::setPtxtMag ( const NTL::xdouble &  z)
inline

◆ smartAutomorph()

void helib::Ctxt::smartAutomorph ( long  k)

automorphism with re-linearization

◆ square()

void helib::Ctxt::square ( )
inline

◆ totalNoiseBound()

NTL::xdouble helib::Ctxt::totalNoiseBound ( ) const
inline

returns the total noise bound, which for CKKS is ptxtMag*ratFactor + noiseBound

◆ writeTo()

void helib::Ctxt::writeTo ( std::ostream &  str) const

Write out the Ctxt object in binary format.

Parameters
strOutput std::ostream.

◆ writeToJSON() [1/2]

JsonWrapper helib::Ctxt::writeToJSON ( ) const

Write out the ciphertext (Ctxt) object to a JsonWrapper.

Returns
The JsonWrapper.

◆ writeToJSON() [2/2]

void helib::Ctxt::writeToJSON ( std::ostream &  str) const

Write out the ciphertext (Ctxt) object to the output stream using JSON format.

Parameters
strOutput std::ostream.

◆ xorConstant() [1/2]

void helib::Ctxt::xorConstant ( const DoubleCRT poly,
UNUSED double  size = -1.0 
)
inline

Convenience method: XOR and nXOR with arbitrary plaintext space: a xor b = a+b-2ab = a + (1-2a)*b, a nxor b = 1-a-b+2ab = (b-1)(2a-1)+a

◆ xorConstant() [2/2]

void helib::Ctxt::xorConstant ( const NTL::ZZX &  poly,
double  size = -1.0 
)
inline

Friends And Related Function Documentation

◆ BasicAutomorphPrecon

friend class BasicAutomorphPrecon
friend

◆ operator<<

std::ostream& operator<< ( std::ostream &  str,
const Ctxt ctxt 
)
friend

◆ operator>>

std::istream& operator>> ( std::istream &  str,
Ctxt ctxt 
)
friend

◆ PubKey

friend class PubKey
friend

◆ SecKey

friend class SecKey
friend

Member Data Documentation

◆ typeName

constexpr std::string_view helib::Ctxt::typeName = "Ctxt"
staticconstexpr

Class label to be added to JSON serialization as object type information.