Ctxt.h
Pre-computation to speed many automorphism on the same ciphertext.
Definition: matmul.cpp:61
double logOfProduct(const IndexSet &s) const
Calculate the natural logarithm of productOfPrimes(s) for a given set of primes s.
Definition: Context.h:840
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
bool isCKKS() const
Return whether this is a CKKS context or not Context.
Definition: Context.h:379
void xorConstant(const NTL::ZZX &poly, double size=-1.0)
Definition: Ctxt.h:1181
void blindCtxt(const NTL::ZZX &poly)
Add a high-noise encryption of the given constant.
Definition: Ctxt.cpp:550
Ctxt & operator-=(long ptxt)
Minus equals operator with a long scalar.
Definition: Ctxt.h:1036
void multByConstantCKKS(const NTL::ZZX &poly, NTL::xdouble size=NTL::xdouble(-1.0), NTL::xdouble factor=NTL::xdouble(-1.0), double roundingErr=-1.0)
Definition: Ctxt.h:1143
Ctxt & operator-=(const NTL::ZZ &ptxt)
Minus equals operator with an NTL::ZZ scalar.
Definition: Ctxt.h:1025
bool isEmpty() const
Is this an empty ciphertext without any parts.
Definition: Ctxt.h:1350
void multByConstant(const Ptxt< Scheme > &ptxt)
Multiply a plaintext to this Ctxt.
Definition: Ctxt.h:1078
void addedNoiseForCKKSDecryption(const SecKey &sk, double eps, NTL::ZZX &noise) const
Definition: Ctxt.cpp:3026
void writeTo(std::ostream &str) const
Write out the Ctxt object in binary format.
Definition: Ctxt.cpp:2559
void addConstantCKKS(std::pair< long, long >)
add a rational number in the form a/b, a,b are long
Definition: Ctxt.cpp:1107
Ctxt & operator-=(const FatEncodedPtxt &ptxt)
Minus equals operator with plaintext constant.
Definition: Ctxt.h:1014
void readJSON(std::istream &str)
In-place read from the str std::istream the serialized ciphertext (Ctxt) object.
Definition: Ctxt.cpp:2655
Ctxt & operator+=(NTL::xdouble ptxt)
Plus equals operator with an NTL::xdouble scalar.
Definition: Ctxt.h:978
NTL::xdouble modSwitchAddedNoiseBound() const
Estimate the added noise.
Definition: Ctxt.cpp:2535
void DummyEncrypt(const NTL::ZZX &ptxt, double size=-1.0)
Definition: Ctxt.cpp:119
Ctxt & operator+=(const FatEncodedPtxt &ptxt)
Plus equals operator with plaintext constant.
Definition: Ctxt.h:934
Ctxt & operator-=(NTL::xdouble ptxt)
Minus equals operator with an NTL::xdouble scalar.
Definition: Ctxt.h:1058
void modDownToSet(const IndexSet &s)
Modulus-switching down (to a smaller modulus). mod-switch down to primeSet \intersect s,...
Definition: Ctxt.cpp:379
void multByConstant(const DoubleCRT &dcrt, double size=-1.0)
Definition: Ctxt.cpp:1811
void dropSmallAndSpecialPrimes()
the corresponding primeSet
Definition: Ctxt.cpp:575
double log_of_ratio() const
Returns log(noiseBound) - log(q)
Definition: Ctxt.h:1398
void xorConstant(const DoubleCRT &poly, UNUSED double size=-1.0)
Definition: Ctxt.h:1172
void extractBits(std::vector< Ctxt > &bits, long nBits2extract=0)
Definition: Ctxt.h:1590
static void equalizeRationalFactors(Ctxt &c1, Ctxt &c2)
Definition: Ctxt.cpp:1191
long bitCapacity() const
the capacity in bits, returned as an integer
Definition: Ctxt.h:1318
Ctxt & operator+=(double ptxt)
Plus equals operator with a double scalar.
Definition: Ctxt.h:967
double logOfPrimeSet() const
returns the log of the prime set
Definition: Ctxt.h:1315
void nxorConstant(const DoubleCRT &poly, UNUSED double size=-1.0)
Definition: Ctxt.h:1186
void multiplyBy2(const Ctxt &other1, const Ctxt &other2)
Definition: Ctxt.cpp:1755
double errorBound() const
for CKKS, returns a bound on the absolute error (which is noiseBound/ratFactor); for BGV,...
Definition: Ctxt.h:1296
Ctxt & operator*=(const EncodedPtxt &ptxt)
Times equals operator with a plaintext constant.
Definition: Ctxt.h:780
NTL::xdouble totalNoiseBound() const
returns the total noise bound, which for CKKS is ptxtMag*ratFactor + noiseBound
Definition: Ctxt.h:1286
Ctxt & operator*=(double ptxt)
Times equals operator with a double scalar.
Definition: Ctxt.h:826
JsonWrapper writeToJSON() const
Write out the ciphertext (Ctxt) object to a JsonWrapper.
Definition: Ctxt.cpp:2623
Ctxt & operator-=(const PtxtArray &ptxt)
Minus equals operator with plaintext constant.
Definition: Ctxt.h:989
void modUpToSet(const IndexSet &s)
Modulus-switching up (to a larger modulus). Must have primeSet <= s, and s must contain either all th...
Definition: Ctxt.cpp:332
void reducePtxtSpace(long newPtxtSpace)
Reduce plaintext space to a divisor of the original plaintext space.
Definition: Ctxt.cpp:562
Ctxt & operator+=(const EncodedPtxt &ptxt)
Plus equals operator with plaintext constant.
Definition: Ctxt.h:921
void read(std::istream &str)
In-place read from the stream the serialized Ctxt object in binary format.
Definition: Ctxt.cpp:2590
static constexpr std::string_view typeName
Class label to be added to JSON serialization as object type information.
Definition: Ctxt.h:508
IndexSet naturalPrimeSet() const
"natural size" is size before squaring
Definition: Ctxt.cpp:1652
bool inCanonicalForm(long keyID=0) const
A canonical ciphertext has (at most) handles pointing to (1,s)
Definition: Ctxt.h:1353
void multByConstantCKKS(std::pair< long, long > num)
Definition: Ctxt.h:1123
friend std::istream & operator>>(std::istream &str, Ctxt &ctxt)
Definition: Ctxt.cpp:2774
Ctxt(const Ctxt &other)=default
static Ctxt readFromJSON(std::istream &str, const PubKey &pubKey)
Read from the stream the serialized ciphertext (Ctxt) object using JSON format.
Definition: Ctxt.cpp:2639
double capacity() const
returns the "capacity" of a ciphertext, which is the log2 of the ratio of the modulus to the total no...
Definition: Ctxt.h:1307
void nxorConstant(const NTL::ZZX &poly, double size=-1.0)
Definition: Ctxt.h:1196
bool isCorrect() const
Would this ciphertext be decrypted without errors?
Definition: Ctxt.cpp:102
Ctxt & operator*=(long ptxt)
Times equals operator with a long scalar.
Definition: Ctxt.h:815
double rawModSwitch(std::vector< NTL::ZZX > &zzParts, long toModulus) const
Special-purpose modulus-switching for bootstrapping.
Definition: Ctxt.cpp:2924
friend std::ostream & operator<<(std::ostream &str, const Ctxt &ctxt)
Definition: Ctxt.cpp:2768
Ctxt & operator*=(const PtxtArray &ptxt)
Times equals operator with a plaintext constant.
Definition: Ctxt.h:768
bool equalsTo(const Ctxt &other, bool comparePkeys=true) const
Definition: Ctxt.cpp:228
Ctxt & operator+=(long ptxt)
Plus equals operator with a long scalar.
Definition: Ctxt.h:956
Ctxt & operator+=(const PtxtArray &ptxt)
Plus equals operator with plaintext constant.
Definition: Ctxt.h:909
void addConstant(const DoubleCRT &dcrt, double size=-1.0)
Definition: Ctxt.cpp:882
void multByConstantCKKS(double x)
multiply by a rational number or floating point
Definition: Ctxt.h:1098
void smartAutomorph(long k)
automorphism with re-linearization
Definition: Ctxt.cpp:2437
Ctxt & operator*=(const FatEncodedPtxt &ptxt)
Times equals operator with a plaintext constant.
Definition: Ctxt.h:793
Ctxt & operator-=(double ptxt)
Minus equals operator with a double scalar.
Definition: Ctxt.h:1047
Ctxt & operator*=(NTL::xdouble ptxt)
Times equals operator with an NTL::xdouble scalar.
Definition: Ctxt.h:837
Ctxt & operator*=(const NTL::ZZ &ptxt)
Times equals operator with an NTL::ZZ scalar.
Definition: Ctxt.h:804
Ctxt & operator-=(const EncodedPtxt &ptxt)
Minus equals operator with plaintext constant.
Definition: Ctxt.h:1001
void bringToSet(const IndexSet &s)
make the primeSet equal to newPrimeSet, via modUpToSet and modDownToSet
Definition: Ctxt.cpp:359
static Ctxt readFrom(std::istream &str, const PubKey &pubKey)
Read from the stream the serialized Ctxt object in binary format.
Definition: Ctxt.cpp:2582
void frobeniusAutomorph(long j)
applies the automorphism p^j using smartAutomorphism
Definition: Ctxt.cpp:2501
void addConstant(const Ptxt< Scheme > &ptxt, bool neg=false)
Add a plaintext to this Ctxt.
Definition: Ctxt.h:632
void multLowLvl(const Ctxt &other, bool destructive=false)
Definition: Ctxt.cpp:1660
Ctxt & operator+=(const NTL::ZZ &ptxt)
Plus equals operator with an NTL::ZZ scalar.
Definition: Ctxt.h:945
JsonWrapper writeToJSON() const
Write out the ciphertext part (CtxtPart) object to a JsonWrapper.
Definition: Ctxt.cpp:2714
void readJSON(std::istream &str)
Read from the stream the serialized ciphertext part (CtxtPart) object using JSON format.
Definition: Ctxt.cpp:2735
CtxtPart(const DoubleCRT &other, const SKHandle &otherHandle)
Definition: Ctxt.h:290
static CtxtPart readFrom(std::istream &str, const Context &context)
Read from the stream the serialized CtxtPart object in binary format.
Definition: Ctxt.cpp:2696
static CtxtPart readFromJSON(std::istream &str, const Context &context)
Read from the stream the serialized ciphertext part (CtxtPart) object using JSON format.
Definition: Ctxt.cpp:2721
void read(std::istream &str)
In-place read from the stream the serialized CtxtPart object in binary format.
Definition: Ctxt.cpp:2703
void writeTo(std::ostream &str) const
Write out the CtxtPart object in binary format.
Definition: Ctxt.cpp:2690
CtxtPart(const Context &_context, const IndexSet &s, const SKHandle &otherHandle)
Definition: Ctxt.h:278
Implementing polynomials (elements in the ring R_Q) in double-CRT form.
Definition: DoubleCRT.h:76
Definition: EncodedPtxt.h:21
Definition: EncodedPtxt.h:143
Definition: EncodedPtxt.h:186
Definition: EncodedPtxt.h:212
Definition: EncodedPtxt.h:313
Definition: EncryptedArray.h:2167
An object that mimics the functionality of the Ctxt object, and acts as a convenient entry point for ...
Definition: Ptxt.h:188
void encode(EncodedPtxt &eptxt, double mag=-1, OptLong prec=OptLong()) const
Converts the slot data in this to a corresponding EncodedPtxt object. mag,prec must be defaulted for ...
A handle, describing the secret-key element that "matches" a part, of the form s^r(X^t).
Definition: Ctxt.h:81
void writeToJSON(std::ostream &str) const
Write out the secret key handle (SKHandle) object to the output stream using JSON format.
Definition: Ctxt.cpp:55
static SKHandle readFromJSON(std::istream &str)
Read from the stream the serialized secret key handle (SKHandle) object using JSON format.
Definition: Ctxt.cpp:69
bool mul(const SKHandle &a, const SKHandle &b)
Computes the "product" of two handles.
Definition: Ctxt.h:153
SKHandle(long newPowerOfS=0, long newPowerOfX=1, long newSecretKeyID=0)
Definition: Ctxt.h:87
friend std::istream & operator>>(std::istream &s, SKHandle &handle)
Definition: Ctxt.cpp:2750
JsonWrapper writeToJSON() const
Write out the secret key handle (SKHandle) object to a JsonWrapper.
Definition: Ctxt.cpp:60
void setBase(long newSecretKeyID=-1)
Set powerOfS=powerOfX=1.
Definition: Ctxt.h:95
void writeTo(std::ostream &str) const
Write out the SKHandle object in binary format.
Definition: Ctxt.cpp:48
void setOne(long newSecretKeyID=-1)
Set powerOfS=0, powerOfX=1.
Definition: Ctxt.h:113
static SKHandle readFrom(std::istream &str)
Read from the stream the serialized SKHandle object in binary format.
Definition: Ctxt.cpp:40
void readJSON(std::istream &str)
Read from the stream the serialized secret key handle (SKHandle) object using JSON format.
Definition: Ctxt.cpp:83
bool isBase(long ofKeyID=0) const
Is powerOfS==powerOfX==1?
Definition: Ctxt.h:104
Definition: apiAttributes.h:21
std::pair< long, long > rationalApprox(double x, long denomBound=0)
Definition: NumbTh.cpp:1598
void innerProduct(Ctxt &result, const CtPtrs &v1, const CtPtrs &v2)
Definition: Ctxt.cpp:2853
void extendExtractDigits(std::vector< Ctxt > &digits, const Ctxt &c, long r, long e)
Definition: extractDigits.cpp:225
void negate(Ctxt &ctxt)
negate: free function version of negate method
Definition: Ctxt.h:1551
void conjugate(Ctxt &ctxt)
conjugate: free function that is equivalent to frobeniusAutomorph(ctxt, 1)
Definition: Ctxt.h:1539
void CheckCtxt(const Ctxt &c, const char *label)
print to cerr some info about ciphertext
Definition: debugging.cpp:158
void totalProduct(Ctxt &out, const std::vector< Ctxt > &v)
Definition: Ctxt.cpp:2844
void extractDigits(std::vector< Ctxt > &digits, const Ctxt &c, long r=0)
Extract the mod-p digits of a mod-p^r ciphertext.
Definition: extractDigits.cpp:70
void frobeniusAutomorph(Ctxt &ctxt, long j)
frobeniusAutomorph: free function version of frobeniusAutomorph method
Definition: Ctxt.h:1533
std::ostream & operator<<(std::ostream &os, const ContextBuilder< SCHEME > &cb)
ostream operator for serializing the ContextBuilder object.
void power(Ctxt &ctxt, long e)
power: free function version of power method
Definition: Ctxt.h:1548
void assertEq(const T &a, const T &b, const std::string &message)
Definition: assertions.h:108
Definition: JsonWrapper.h:9