BitwiseEvaluator#
Currently, this API is unsupported in Python
-
class BitwiseEvaluator#
Used to perform operations on bitwise CTiles.
Can only be constructed by bitwise HeContext.
Public Functions
-
BitwiseEvaluator(const HeContext &he)#
Constructs a ready to use object.
- Parameters:
he – [in] the underlying context.
-
inline ~BitwiseEvaluator()#
-
CTile getMSB(const CTile &c) const#
Returns the MSB of c.
The result is returned is one-bit, unsigned bitwise CTile.
- Parameters:
c – [in] The CTile to get its MSB.
-
CTile getFlippedMSB(const CTile &c) const#
Returns The NOT of the MSB of c.
/// The result is returned as one-bit, unsigned bitwise CTile.
- Parameters:
c – [in] The CTile to get its flipped MSB.
-
void setIsSigned(CTile &c, bool val) const#
Sets c to be signed if val is true, and unsigned otherwise.
Note that changing c from signed to unsigned (or converse) will cause its value to change accordingly. The value of a signed CTile is interpreted using 2’s complement method, and the value of an unsigned CTile is interpreted as an ordinary binary number.
- Parameters:
c – [in] To set to signed/unsigned.
val – [in] Whether to set c to signed or unsigned.
-
bool getIsSigned(const CTile &c) const#
Returns true if c is signed and false otherwise.
- Parameters:
c – [in] To check whether it is signed.
-
CTile hamming(const CTile &c, int from = 0, int to = -1) const#
Returns the hamming weight of c, considering the specified bits only.
- Parameters:
c – The CTile to calculate its hamming weight.
from – The first bit index in the range of bits to calculate hamming weight for.
to – The one after the last bit in the range of bits to calculate hamming weights for. If -1, all of the bits starting from “from” will be taken.
-
std::vector<CTile> split(const CTile &c) const#
Returns a vector of the bits of “c”.
Each bit is returned as a one-bit, unsigned bitwise CTile.
- Parameters:
c – [in] The CTile to split.
-
CTile combine(const std::vector<CTile> &cs, int from = 0, int to = -1, int bitsPerElement = 1) const#
Combines the given bitwise CTiles into one.
Combines all the bitwise CTiles in cs[from] until cs[to] (inclusive) into one bitwise CTile containing the first “bitsPerElement” LSB bits of each ciphertext. The LSB of the result is the first bit of cs[from]. If “to” is -1, then all the ciphertexts in cs[from] until cs.end() are taken.
- Parameters:
cs – [in] The bitwise CTiles to combine
from – [in] The index to start combining from.
to – [in] The index to combine until.
bitsPerElement – [in] How many bits to take from each CTile in “cs”.
-
CTile isEqual(const CTile &c1, const CTile &c2) const#
Checks whether c1 == c2.
Returns (an encryption of) 1 if c1 == c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters:
c1, c2 – [in] To evaluate c1 == c2 on.
-
CTile multiply(const CTile &c1, const CTile &c2, int targetBits = -1) const#
Returns first “targetBits” LSBs of c1*c2.
If one of c1 or c2 is signed, the returned CTile will be signed. Otherwise, the returned CTile will be unsigned. The scale of the result is set to the product of c1’s and c2’s scales.
- Parameters:
c1, c2 – [in] To multiply.
targetBits – [in] The number of the bits of the result. If -1, the result will contain getNumBits(c1) + getNumBits(c2) bits.
-
CTile add(const CTile &c1, const CTile &c2, int targetBits = -1) const#
Returns the first “targetBits” LSBs of c1 + c2.
If one of c1 or c2 is signed, the returned CTile will be signed. Otherwise, the returned CTile will be unsigned.
- Parameters:
c1, c2 – [in] To add
targetBits – [in] The number of the bits of the result. If -1, the result will contain. max(getNumBits(c1) + getNumBits(c2) + 1) bits.
- Throws:
runtime_error – If the scales of c1 and c2 are different.
-
CTile sub(const CTile &c1, const CTile &c2, int targetBits = -1) const#
Returns the first “targetBits” LSBs of c1 - c2.
If one of c1 or c2 is signed, the returned CTile will be signed. Otherwise, the returned CTile will be unsigned.
- Parameters:
c1, c2 – [in] To subtract.
targetBits – [in] The number of the bits of the result. If -1, the result will contain getNumBits(c1) bits.
- Throws:
runtime_error – If the scales of c1 and c2 are different.
-
CTile multiplyBit(const CTile &c, const CTile &bit) const#
Returns the result of multiplying all bits of c by the given “bit”.
- Parameters:
c – [in] To multiply its bits by the given bit.
bit – [in] To multiply c by.
-
CTile bitwiseXor(const CTile &c1, const CTile &c2) const#
Bitwise xor between c1 and c2.
If c1 is signed, the result will be signed. Otherwise, the result will be unsigned.
- Parameters:
c1, c2 – [in] To perform bitwise xor between.
-
CTile bitwiseXnor(const CTile &c1, const CTile &c2) const#
Bitwise xnor between c1 and c2.
- Parameters:
c1, c2 – [in] To perform bitwise xnor between.
-
int getNumBits(const CTile &c) const#
Returns the number of bits of c.
- Parameters:
c – [in] To check its number of bits.
-
void setNumBits(CTile &c, int bits) const#
Updates c to contain “bits” bits.
If getNumBits(c) > bits, then MSBs of c are removed until it contains only “bits” bits. If getNumBits(c) < bits and c is signed, then the MSB of c is added to c until it contains “bits” bits. If getNumBits(c) < bits and c is unsigned, then 0 is added to c until it contains “bits” bits.
- Parameters:
c – [inout] The CTile to update to contain “bits” bit.
bits – [in] The number of bits c will contain.
-
int getDefaultNumBits() const#
Returns the default number of bits to a CTile.
This default number is taken from the HeContext this BitwiseEvaluator was initialized with.
-
void debugPrintWithBinary(const CTile &c, const std::string &title, Verbosity verbosity = VERBOSITY_REGULAR, std::ostream &out = std::cout) const#
Prints debug info.
- Parameters:
c – [in] The CTile to print debug info about.
title – [in] The title used to display the debug message.
verbosity – [in] Verbose used while printing.
out – [inout] The ostream to print to.
-
double getScale(const CTile &c) const#
Returns the scale of c.
- Parameters:
c – [in] To get its scale.
-
CTile max(const CTile &c1, const CTile &c2) const#
Returns max(c1, c2).
- Parameters:
c1, c2 – [in] To compute their maximum.
-
CTile min(const CTile &c1, const CTile &c2) const#
Returns min(c1, c2).
- Parameters:
c1, c2 – [in] To compute their maximum.
-
CTile isGreater(const CTile &c1, const CTile &c2) const#
Checks whether c1 < c2.
Returns (an encryption of) 1 if c1 < c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters:
c1, c2 – [in] To evaluate c1 < c2 on.
-
CTile isLess(const CTile &c1, const CTile &c2) const#
Checks whether c1 > c2.
Returns (an encryption of) 1 if c1 > c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters:
c1, c2 – [in] To evaluate c1 > c2 on.
-
BitwiseEvaluator(const HeContext &he)#