Search Results

Used to perform operations on bitwise CTiles. More...

#include <BitwiseEvaluator.h>

Public Member Functions

 BitwiseEvaluator (HeContext &he)
Constructs a ready to use object. More...
 
CTile getMSB (const CTile &c) const
Returns the MSB of c. More...
 
CTile getFlippedMSB (const CTile &c) const
Returns The NOT of the MSB of c. More...
 
void setIsSigned (CTile &c, bool val) const
Sets c to be signed if val is true, and unsigned otherwise. More...
 
bool getIsSigned (const CTile &c) const
Returns true if c is signed and false otherwise. More...
 
CTile hamming (const CTile &c, int from=0, int to=-1) const
 
std::vector< CTilesplit (const CTile &c) const
Returns a vector of the bits of "c". More...
 
CTile combine (const std::vector< CTile > cs, int from=0, int to=-1, int bitsPerElement=1) const
Combines the given bitwise CTiles into one. More...
 
CTile isEqual (const CTile &c1, const CTile &c2) const
Checks whether c1 == c2. More...
 
CTile multiply (const CTile &c1, const CTile &c2, int targetBits=-1) const
Returns first "targetBits" LSBs of c1*c2. More...
 
CTile add (const CTile &c1, const CTile &c2, int targetBits=-1) const
Returns the first "targetBits" LSBs of c1 + c2. More...
 
CTile sub (const CTile &c1, const CTile &c2, int targetBits=-1) const
Returns the first "targetBits" LSBs of c1 - c2. More...
 
CTile multiplyBit (const CTile &c, const CTile &bit) const
Returns the result of multiplying all bits of c by the given "bit". More...
 
CTile bitwiseXor (const CTile &c1, const CTile &c2) const
Bitwise xor between c1 and c2. More...
 
int getNumBits (const CTile &c) const
Returns the number of bits of c. More...
 
void setNumBits (CTile &c, int bits) const
Updates c to contain "bits" bits. More...
 
int getDefaultNumBits () const
Returns the default number of bits to a CTile. More...
 
void debugPrintWithBinary (const CTile &c, const std::string &title, int maxElements=4, int verbose=0, std::ostream &out=std::cout) const
Prints debug info. More...
 
double getScale (const CTile &c) const
Returns the scale of c. More...
 
CTile max (const CTile &c1, const CTile &c2) const
Returns max(c1, c2). More...
 
CTile min (const CTile &c1, const CTile &c2) const
Returns min(c1, c2). More...
 
CTile isGreater (const CTile &c1, const CTile &c2) const
Checks whether c1 < c2. More...
 
CTile isLess (const CTile &c1, const CTile &c2) const
Checks whether c1 > c2. More...
 
CTile isGreaterEqual (const CTile &c1, const CTile &c2) const
Checks whether c1 >= c2. More...
 
CTile isLessEqual (const CTile &c1, const CTile &c2) const
Checks whether c1 <= c2. More...
 

Detailed Description

Used to perform operations on bitwise CTiles.

Can only be constructed by bitwise HeContext.

Constructor & Destructor Documentation

◆ BitwiseEvaluator()

helayers::BitwiseEvaluator::BitwiseEvaluator ( HeContext he)

Constructs a ready to use object.

Parameters
[in]hethe underlying context.

Member Function Documentation

◆ add()

CTile helayers::BitwiseEvaluator::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
[in]c1,c2To add
[in]targetBitsThe number of the bits of the result. If -1, the result will contain. max(getNumBits(c1) + getNumBits(c2) + 1) bits.
Exceptions
runtime_errorIf the scales of c1 and c2 are different.

◆ bitwiseXor()

CTile helayers::BitwiseEvaluator::bitwiseXor ( const CTile c1,
const CTile c2 
) const

Bitwise xor between c1 and c2.

I c1 is signed, the result will be signed. Otherwise, the result will be unsigned.

Parameters
[in]c1,c2To perform bitwise xor between.

◆ combine()

CTile helayers::BitwiseEvaluator::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
[in]csThe bitwise CTiles to combine
[in]fromThe index to start combining from.
[in]outThe index to combine until.
[in]bitsPerElementHow many bits to take from each CTile in "cs".

◆ debugPrintWithBinary()

void helayers::BitwiseEvaluator::debugPrintWithBinary ( const CTile c,
const std::string &  title,
int  maxElements = 4,
int  verbose = 0,
std::ostream &  out = std::cout 
) const

Prints debug info.

Parameters
[in]cThe CTile to print debug info about.
[in]titleThe title used to display the debug message.
[in]maxElementsMaximal number of slots to debug-print.
[in]verboseVerbose used while printing.
[in,out]outThe ostream to print to.

◆ getDefaultNumBits()

int helayers::BitwiseEvaluator::getDefaultNumBits ( ) const

Returns the default number of bits to a CTile.

This default number is taken from the HeContext this BitwiseEvaluator was initialized with.

◆ getFlippedMSB()

CTile helayers::BitwiseEvaluator::getFlippedMSB ( const CTile c) const

Returns The NOT of the MSB of c.

/// The result is returned as one-bit, unsigned bitwise CTile.

Parameters
[in]cThe CTile to get its flipped MSB.

◆ getIsSigned()

bool helayers::BitwiseEvaluator::getIsSigned ( const CTile c) const

Returns true if c is signed and false otherwise.

Parameters
[in]cTo check whether it is signed.

◆ getMSB()

CTile helayers::BitwiseEvaluator::getMSB ( const CTile c) const

Returns the MSB of c.

The result is returned is one-bit, unsigned bitwise CTile.

Parameters
[in]cThe CTile to get its MSB.

◆ getNumBits()

int helayers::BitwiseEvaluator::getNumBits ( const CTile c) const

Returns the number of bits of c.

Parameters
[in]cTo check its number of bits.

◆ getScale()

double helayers::BitwiseEvaluator::getScale ( const CTile c) const

Returns the scale of c.

Parameters
[in]cTo get its scale.

◆ isEqual()

CTile helayers::BitwiseEvaluator::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
[in]c1,c2To evaluate c1 == c2 on.

◆ isGreater()

CTile helayers::BitwiseEvaluator::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
[in]c1,c2To evaluate c1 < c2 on.

◆ isGreaterEqual()

CTile helayers::BitwiseEvaluator::isGreaterEqual ( 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
[in]c1,c2To evaluate c1 >= c2 on.

◆ isLess()

CTile helayers::BitwiseEvaluator::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
[in]c1,c2To evaluate c1 > c2 on.

◆ isLessEqual()

CTile helayers::BitwiseEvaluator::isLessEqual ( 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
[in]c1,c2To evaluate c1 <= c2 on.

◆ max()

CTile helayers::BitwiseEvaluator::max ( const CTile c1,
const CTile c2 
) const

Returns max(c1, c2).

Parameters
[in]c1,c2To compute their maximum.

◆ min()

CTile helayers::BitwiseEvaluator::min ( const CTile c1,
const CTile c2 
) const

Returns min(c1, c2).

Parameters
[in]c1,c2To compute their maximum.

◆ multiply()

CTile helayers::BitwiseEvaluator::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
[in]c1,c2To multiply.
[in]targetBitsThe number of the bits of the result. If -1, the result will contain getNumBits(c1) + getNumBits(c2) bits.

◆ multiplyBit()

CTile helayers::BitwiseEvaluator::multiplyBit ( const CTile c,
const CTile bit 
) const

Returns the result of multiplying all bits of c by the given "bit".

Parameters
[in]cTo multiply its bits by the given bit.
[in]bitTo multiply c by.

◆ setIsSigned()

void helayers::BitwiseEvaluator::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
[in]cTo set to signed/unsigned.
[in]valWhether to set c to signed or unsigned.

◆ setNumBits()

void helayers::BitwiseEvaluator::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
[in,out]cThe CTile to update to contain "bits" bit.
[in]bitsThe number of bits c will contain.

◆ split()

vector< CTile > helayers::BitwiseEvaluator::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
[in]cThe CTile to split.

◆ sub()

CTile helayers::BitwiseEvaluator::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
[in]c1,c2To subtract.
[in]targetBitsThe number of the bits of the result. If -1, the result will contain getNumBits(c1) bits.
Exceptions
runtime_errorIf the scales of c1 and c2 are different.

The documentation for this class was generated from the following files:
  • /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/BitwiseEvaluator.h
  • /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/BitwiseEvaluator.cpp