A class representing a ciphertext. More...
#include <CTile.h>
Public Member Functions | |
CTile (HeContext &he) | |
Constructs an empty object. More... | |
CTile (const CTile &src) | |
Copy constructor. More... | |
CTile & | operator= (const CTile &src) |
Copy from another object. More... | |
void | saveToFile (const std::string &fileName) const |
Saves this CTile to a file in binary form. More... | |
void | loadFromFile (const std::string &fileName) |
Loads this CTile from a file saved by saveToFile() More... | |
std::streamoff | save (std::ostream &stream) const |
Saves this CTile to a stream in binary form. More... | |
std::streamoff | load (std::istream &stream) |
Loads this CTile from a file saved by save() More... | |
void | conjugate () |
Conjugates contents of this CTile in place, elementwise. More... | |
void | conjugateRaw () |
See conjugate(). | |
void | rotate (int n) |
Rotate left. More... | |
void | add (const CTile &other) |
Add content of another ciphertext to this one, elementwise. More... | |
void | addRaw (const CTile &other) |
See add() | |
void | sub (const CTile &other) |
Subtract content of another ciphertext from this one, elementwise. More... | |
void | subRaw (const CTile &other) |
See sub() | |
void | multiply (const CTile &other) |
Multiply another ciphertext with this one, elementwise. More... | |
void | multiplyRaw (const CTile &other) |
see multiply() | |
void | addPlain (const PTile &plain) |
Add content of another PTile to this one, elementwise. More... | |
void | addPlainRaw (const PTile &plain) |
See addPlain() | |
void | subPlain (const PTile &plain) |
Subtract content of another PTile from this one, elementwise. More... | |
void | subPlainRaw (const PTile &plain) |
See subPlain() | |
void | multiplyPlain (const PTile &plain) |
Multiply a PTile with this CTile, elementwise. More... | |
void | multiplyPlainRaw (const PTile &plain) |
See multiplyPlain() | |
void | square () |
Square content of this ciphertext, elementwise. More... | |
void | squareRaw () |
See square() | |
void | multiplyByChangingScale (double factor) |
Multiply this ciphertext by a scalar double value, elementwise, by a light-weight scale changing. More... | |
void | addScalar (int scalar) |
Adds an int scalar value to all slots in this ciphertext. More... | |
void | addScalar (double scalar) |
Adds a double scalar value to all slots in this ciphertext. More... | |
void | multiplyScalar (int scalar) |
Multiplies all slots in this ciphertext with an int scalar value. More... | |
void | multiplyScalar (double scalar) |
Multiplies all slots in this ciphertext with a double scalar value. More... | |
void | relinearize () |
Performs a relinearize operation (reducing ciphertext size after multiplication) The non-raw version of multiplication takes care of this automatically when needed. More... | |
void | rescale () |
Performs a rescale operation (reducing ciphertext modulus bits and attached meta data scale). More... | |
void | rescaleRaw () |
See rescale() | |
void | negate () |
Negates content of this ciphertext. | |
void | setScale (double scale) |
Sets the attached meta data scale of the ciphertext. More... | |
double | getScale () const |
Returns the attached meta data scale of the ciphertext. | |
void | reduceChainIndex () |
Reduces the chain-index property of the ciphertext by 1. More... | |
void | setChainIndex (const CTile &other) |
Sets the chain-index property of this object to equal other object. More... | |
void | setChainIndex (int chainIndex) |
Sets the chain-index property of this object to equal the specified value. More... | |
int | getChainIndex () const |
Returns the value of the chain-index property of this object, which is a non-negative integer. More... | |
int | slotCount () const |
A CTile represents a ciphertext consisting of multuple slots. More... | |
void | innerSum (int rot1, int rot2, bool reverse=false) |
Computes the inner sum of some of the ciphertext's slots. More... | |
void | sumExpBySquaringLeftToRight (int n) |
Summarizes n slots of this ciphertext. More... | |
void | sumExpBySquaringRightToLeft (int n) |
Summarizes n slots of this ciphertext. More... | |
bool | isEmpty () const |
Returns true if this CTile does not include an encryption of any value, and false otherwise. | |
void | debugPrint (const std::string &title="", int maxElements=4, int verbose=0, std::ostream &out=std::cout) const |
Prints information regarding this object for debug purposes. More... | |
const AbstractCiphertext & | getImpl () const |
Reserved for debugging and internal use. | |
Friends | |
class | Encoder |
class | BitwiseEvaluator |
class | NativeFunctionEvaluator |
Detailed Description
A class representing a ciphertext.
It's called a CTile because from a high-level point of view we'll usually use several of these combined for holding a more complicated object such as a matrix. For a lower level documentation of different functionalities (such as the effect on chainIndex), see documentation of the underlying encryption scheme.
Constructor & Destructor Documentation
◆ CTile() [1/2]
helayers::CTile::CTile | ( | HeContext & | he | ) |
Constructs an empty object.
- Parameters
-
[in] he the underlying context.
◆ CTile() [2/2]
helayers::CTile::CTile | ( | const CTile & | src | ) |
Copy constructor.
- Parameters
-
[in] src Object to copy.
Member Function Documentation
◆ add()
void helayers::CTile::add | ( | const CTile & | other | ) |
Add content of another ciphertext to this one, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use addRaw() to get the scheme's raw addition operation.
- Parameters
-
[in] other other ciphertext to add.
◆ addPlain()
void helayers::CTile::addPlain | ( | const PTile & | plain | ) |
Add content of another PTile to this one, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use addPlainRaw() to get the scheme's raw addition operation.
- Parameters
-
[in] other PTile to add.
◆ addScalar() [1/2]
void helayers::CTile::addScalar | ( | double | scalar | ) |
Adds a double scalar value to all slots in this ciphertext.
- Parameters
-
[in] scalar value to add.
◆ addScalar() [2/2]
void helayers::CTile::addScalar | ( | int | scalar | ) |
Adds an int scalar value to all slots in this ciphertext.
- Parameters
-
[in] scalar value to add.
◆ conjugate()
void helayers::CTile::conjugate | ( | ) |
Conjugates contents of this CTile in place, elementwise.
For non-complex numbers this has no effect. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use conjugateRaw() to get the scheme's raw conjugate operation.
◆ debugPrint()
void helayers::CTile::debugPrint | ( | const std::string & | title = "" , |
int | maxElements = 4 , |
||
int | verbose = 0 , |
||
std::ostream & | out = std::cout |
||
) | const |
Prints information regarding this object for debug purposes.
- Parameters
-
[in] title A title to be included in the printing. [in] maxElements The number of elements/slots to be included in the printing. [in] verbose Level of vebosity. [in] out An output stream to print the information into.
◆ getChainIndex()
int helayers::CTile::getChainIndex | ( | ) | const |
Returns the value of the chain-index property of this object, which is a non-negative integer.
Returns a negative value if not supported.
◆ innerSum()
void helayers::CTile::innerSum | ( | int | rot1, |
int | rot2, | ||
bool | reverse = false |
||
) |
Computes the inner sum of some of the ciphertext's slots.
Performs the computation by repeated rotations and additions, with rotations rot1, 2*rot1, 4*rot2, up to rot2 (exclusive). Using this method properly is complicated, and is used by some higher level algorithms.
- Parameters
-
rot1 First rotation in the rotate-and-add loop rot2 Last rotation (exclusive) in the rotate-and-add loop reverse If true, flips all rotations (left to right and vice versa)
◆ load()
streamoff helayers::CTile::load | ( | std::istream & | stream | ) |
◆ loadFromFile()
void helayers::CTile::loadFromFile | ( | const std::string & | fileName | ) |
Loads this CTile from a file saved by saveToFile()
- Parameters
-
[in] fileName name of file to read from
◆ multiply()
void helayers::CTile::multiply | ( | const CTile & | other | ) |
Multiply another ciphertext with this one, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiplyRaw() to get the scheme's raw addition operation.
- Parameters
-
[in] other other ciphertext to multiply.
◆ multiplyByChangingScale()
void helayers::CTile::multiplyByChangingScale | ( | double | factor | ) |
Multiply this ciphertext by a scalar double value, elementwise, by a light-weight scale changing.
This multiplies every slot by the given factor. The operation is done by changing the scale meta-data combined with this ciphertext, and is therefore extermely fast. It is not available for all underlying schemes, and also may cause difficulties down the line due to mismatching scales.
- Parameters
-
[in] factor factor to multiply with.
- Exceptions
-
runtime_error If not supported
◆ multiplyPlain()
void helayers::CTile::multiplyPlain | ( | const PTile & | plain | ) |
Multiply a PTile with this CTile, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiplyPlainRaw() to get the scheme's raw multiplication operation.
- Parameters
-
[in] other PTile to multiply with.
◆ multiplyScalar() [1/2]
void helayers::CTile::multiplyScalar | ( | double | scalar | ) |
Multiplies all slots in this ciphertext with a double scalar value.
- Parameters
-
[in] scalar value to multiply.
◆ multiplyScalar() [2/2]
void helayers::CTile::multiplyScalar | ( | int | scalar | ) |
Multiplies all slots in this ciphertext with an int scalar value.
- Parameters
-
[in] scalar value to multiply.
◆ operator=()
Copy from another object.
- Parameters
-
[in] src Object to copy.
◆ reduceChainIndex()
void helayers::CTile::reduceChainIndex | ( | ) |
Reduces the chain-index property of the ciphertext by 1.
Ignored if not supported.
- Exceptions
-
runtime_error If chain index is already at lowest value
◆ relinearize()
void helayers::CTile::relinearize | ( | ) |
Performs a relinearize operation (reducing ciphertext size after multiplication) The non-raw version of multiplication takes care of this automatically when needed.
Ignored if not needed or not supported.
◆ rescale()
void helayers::CTile::rescale | ( | ) |
Performs a rescale operation (reducing ciphertext modulus bits and attached meta data scale).
The non-raw version of multiplication takes care of this automatically. Ignored if not needed or not supported. Note that depending on scheme, this method may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use rescaleRaw() to get the scheme's raw rescale operation.
◆ rotate()
void helayers::CTile::rotate | ( | int | n | ) |
Rotate left.
For an offset of n, the element at slots 10 will move to slot 10-n. The first n elements are rotated back to be last.
- Parameters
-
[in] n rotate offset
◆ save()
streamoff helayers::CTile::save | ( | std::ostream & | stream | ) | const |
Saves this CTile to a stream in binary form.
- Parameters
-
[in] stream output stream to write to
◆ saveToFile()
void helayers::CTile::saveToFile | ( | const std::string & | fileName | ) | const |
Saves this CTile to a file in binary form.
- Parameters
-
[in] fileName name of file to write to
◆ setChainIndex() [1/2]
void helayers::CTile::setChainIndex | ( | const CTile & | other | ) |
Sets the chain-index property of this object to equal other object.
Can only be used if other object's chain index is less than or equal to the chain index of this object. Ignored if not supported.
- Parameters
-
[in] other object to get chain index from
- Exceptions
-
runtime_error If chain index of other higher than this
◆ setChainIndex() [2/2]
void helayers::CTile::setChainIndex | ( | int | chainIndex | ) |
Sets the chain-index property of this object to equal the specified value.
Can only be used if the specified value is less than or equal to the chain index of this object. Ignored if not supported.
- Parameters
-
[in] chainIndex The terget value to set the chain index to
- Exceptions
-
runtime_error If the specified chain index is higher than this
◆ setScale()
void helayers::CTile::setScale | ( | double | scale | ) |
Sets the attached meta data scale of the ciphertext.
This may change the way its content are interpreted.
- Parameters
-
[in] scale the new scale
- Exceptions
-
runtime_error If not supported
◆ slotCount()
int helayers::CTile::slotCount | ( | ) | const |
A CTile represents a ciphertext consisting of multuple slots.
This method returns the number of slots in this object.
◆ square()
void helayers::CTile::square | ( | ) |
Square content of this ciphertext, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use squareRaw() to get the scheme's raw square operation.
◆ sub()
void helayers::CTile::sub | ( | const CTile & | other | ) |
Subtract content of another ciphertext from this one, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use subRaw() to get the scheme's raw subtraction operation.
- Parameters
-
[in] other other ciphertext to subtract.
◆ subPlain()
void helayers::CTile::subPlain | ( | const PTile & | plain | ) |
Subtract content of another PTile from this one, elementwise.
Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use subPlainRaw() to get the scheme's raw subtract operation.
- Parameters
-
[in] other PTile to subtract.
◆ sumExpBySquaringLeftToRight()
void helayers::CTile::sumExpBySquaringLeftToRight | ( | int | n | ) |
Summarizes n slots of this ciphertext.
After summing, slot i will contain the sum of slots i, i+1, i+2, . . ., i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to left-to-right repeated squaring algorithm.
- Parameters
-
[in] n number of elements to summarize
◆ sumExpBySquaringRightToLeft()
void helayers::CTile::sumExpBySquaringRightToLeft | ( | int | n | ) |
Summarizes n slots of this ciphertext.
After summing, slot i will contain the sum of slots i, i+1, i+2, . . ., i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to right-to-left repeated squaring algorithm.
- Parameters
-
[in] n number of elements to summarize
The documentation for this class was generated from the following files:
- /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/CTile.h
- /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/CTile.cpp