Template Class CiphertextImpl

Inheritance Relationships

Base Type

Template Parameter Order

  1. class Element

Class Documentation

template<class Element>
class lbcrypto::CiphertextImpl : public lbcrypto::CryptoObject<Element>

Inheritence diagram for lbcrypto::CiphertextImpl:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="lbcrypto::CryptoObject< Element >" tooltip="lbcrypto::CryptoObject< Element >"]
    "1" [label="lbcrypto::CiphertextImpl< Element >" tooltip="lbcrypto::CiphertextImpl< Element >" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Collaboration diagram for lbcrypto::CiphertextImpl:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="lbcrypto::CryptoObject< Element >" tooltip="lbcrypto::CryptoObject< Element >"]
    "1" [label="lbcrypto::CiphertextImpl< Element >" tooltip="lbcrypto::CiphertextImpl< Element >" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

CiphertextImpl.

The CiphertextImpl object is used to contain encrypted text in the OpenFHE library

Template Parameters

Element – a ring element.

Public Functions

CiphertextImpl() = default

Default constructor

inline explicit CiphertextImpl(const CryptoContext<Element> &cc, const std::string &id = "", PlaintextEncodings encType = INVALID_ENCODING)

Construct a new ciphertext in the given context

Parameters
  • cc – the crypto context the ciphertext belongs to

  • id – key tag of the key used to encrypt the ciphertext

  • encType – encoding type of the plaintext the ciphertext was created from

inline explicit CiphertextImpl(const std::shared_ptr<Key<Element>> &k)

Construct a new ciphertext from the parameters of a given public key

Parameters

k – key whose CryptoObject parameters will get cloned

CiphertextImpl(const CiphertextImpl<Element> &ct) = default

Copy constructor

Parameters

ct – the ciphertext to copy from

inline explicit CiphertextImpl(const Ciphertext<Element> &ct)

Copy constructor from a shared pointer: copies all elements and metadata of the pointed-to ciphertext.

Parameters

ct – shared pointer to the ciphertext to copy from

CiphertextImpl(CiphertextImpl<Element> &&ct) noexcept = default

Move constructor

Parameters

ct – the ciphertext to move from

inline explicit CiphertextImpl(Ciphertext<Element> &&ct) noexcept

Move constructor from a shared pointer: moves all elements and metadata out of the pointed-to ciphertext, leaving that ciphertext in an unspecified state.

Parameters

ct – shared pointer to the ciphertext to move from

virtual ~CiphertextImpl() = default

Destructor

CiphertextImpl<Element> &operator=(const CiphertextImpl<Element> &rhs) = default

Assignment Operator.

Parameters

rhs – the CiphertextImpl to assign from

Returns

this CiphertextImpl

CiphertextImpl<Element> &operator=(CiphertextImpl<Element> &&rhs) noexcept = default

Move Assignment Operator.

Parameters

rhs – the CiphertextImpl to move from

Returns

this CiphertextImpl

inline const Element &GetElement() const

GetElement - get the ring element for the cases that use only one element in the vector this method will throw an exception if it’s ever called in cases with other than 1 element

Returns

the first (and only!) ring element

inline Element &GetElement()

GetElement - get the ring element for the cases that use only one element in the vector this method will throw an exception if it’s ever called in cases with other than 1 element

Returns

the first (and only!) ring element

inline const std::vector<Element> &GetElements() const

GetElements: get all of the ring elements in the CiphertextImpl

Returns

vector of ring elements

inline std::vector<Element> &GetElements()

GetElements: get all of the ring elements in the CiphertextImpl

Returns

vector of ring elements

inline size_t NumberCiphertextElements() const

Returns the number of ring elements (polynomials) in the ciphertext, e.g. 2 for a fresh encryption and 3 after a multiplication without relinearization.

Returns

the number of ring elements

inline void SetElement(const Element &element)

SetElement - sets the ring element for the cases that use only one element in the vector this method will throw an exception if it’s ever called in cases with other than 1 element

Parameters

element – is a polynomial ring element.

inline void SetElement(Element &&element)

Sets the data element by std::move.

Parameters

element – is a polynomial ring element.

inline void SetElements(const std::vector<Element> &elements)

Sets the data elements.

Parameters

elements – is a vector of polynomial ring elements.

inline void SetElements(std::vector<Element> &&elements) noexcept

Sets the data elements by std::move.

Parameters

elements – is a vector of polynomial ring elements.

inline size_t GetNoiseScaleDeg() const

Get the degree of the scaling factor for the encrypted message.

Returns

the degree of the scaling factor (1 for a fresh ciphertext, 2 after a multiplication)

inline void SetNoiseScaleDeg(size_t noiseScaleDeg)

Set the degree of the scaling factor for the encrypted message.

Parameters

noiseScaleDeg – the degree of the scaling factor

inline size_t GetLevel() const

Get the number of scalings performed

Returns

the level (number of RNS limbs dropped so far) of the ciphertext

inline void SetLevel(size_t level)

Set the number of scalings. This generic version performs no validation. The DCRTPoly specialization additionally checks, for CKKS, that the ciphertext still has at least as many RNS limbs as its noise scale degree and throws an exception asking for a larger multiplicative depth otherwise.

Parameters

level – the number of scalings (level) of the ciphertext

inline size_t GetHopLevel() const

Get the re-encryption level of the ciphertext.

Returns

the number of times the ciphertext has been re-encrypted (proxy re-encryption hops)

inline void SetHopLevel(size_t hoplevel)

Set the re-encryption level of the ciphertext.

Parameters

hoplevel – the re-encryption (hop) level

inline double GetScalingFactor() const

Get the scaling factor of the ciphertext.

Returns

the (approximate, double-precision) scaling factor of the encrypted message

inline void SetScalingFactor(double sf)

Set the scaling factor of the ciphertext.

Parameters

sf – the scaling factor

inline NativeInteger GetScalingFactorInt() const

Get the integer scaling factor of the ciphertext.

Returns

the exact integer scaling factor of the encrypted message (used by BGV)

inline void SetScalingFactorInt(NativeInteger sf)

Set the integer scaling factor of the ciphertext.

Parameters

sf – the integer scaling factor

inline uint32_t GetSlots() const

Get the number of slots of the ciphertext.

Returns

the number of plaintext slots the ciphertext encrypts

inline void SetSlots(uint32_t slots)

Set the number of slots of the ciphertext.

Parameters

slots – the number of slots

inline PlaintextEncodings GetEncodingType() const

GetEncodingType

Returns

how the Plaintext that this CiphertextImpl was created from was encoded

inline void SetEncodingType(PlaintextEncodings et)

SetEncodingType - after Encrypt, remember the CiphertextImpl’s encoding type

Parameters

et – the encoding type of the plaintext the ciphertext was created from

inline MetadataMap GetMetadataMap() const

Get the Metadata map of the ciphertext.

Returns

shared pointer to the map of metadata objects keyed by name

inline void SetMetadataMap(const MetadataMap &mdata)

Set the Metadata map of the ciphertext.

Parameters

mdata – the metadata map

inline std::map<std::string, std::shared_ptr<Metadata>>::iterator FindMetadataByKey(std::string key) const

This method searches the metadata map for metadata of a specific key.

Parameters

key – the string value which serves as a key in the metadata map

Returns

an iterator pointing at the position in the map where the key was found (or the map.end() if not found).

inline bool MetadataFound(std::map<std::string, std::shared_ptr<Metadata>>::iterator it) const

This method checks whether an iterator return from FindMetadataByKey corresponds to whether the key was found or not.

Parameters

it – iterator pointing at the position in the map where the key was found (or the map.end() if not found).

Returns

a boolean value indicating whether the key was found or not.

inline std::shared_ptr<Metadata> &GetMetadata(std::map<std::string, std::shared_ptr<Metadata>>::iterator it) const

This method returns the Metadata object stored in the iterator position returned by FindMetadataByKey.

Parameters

it – iterator pointing at the position in the map where the key was found (or the map.end() if not found).

Returns

a shared pointer pointing to the Metadata object in the map.

inline std::shared_ptr<Metadata> GetMetadataByKey(const std::string &key) const

Get a copy of a Metadata element from the Metadata map of the ciphertext.

Parameters

key – the string key of the metadata element

Returns

a new shared pointer to a copy of the metadata element; throws an exception if the key is not found

inline void SetMetadataByKey(const std::string &key, const std::shared_ptr<Metadata> &value)

Set a Metadata element in the Metadata map of the ciphertext.

Parameters
  • key – the string key of the metadata element

  • value – the metadata element to store

inline virtual Ciphertext<Element> CloneEmpty() const

This method creates a copy of this, skipping the actual encrypted elements. This means it copies parameters, key tags, encoding type, and metadata.

Returns

a new ciphertext with the same context, key tag, level/scaling data and metadata but no elements

inline virtual Ciphertext<Element> Clone() const

Creates a deep copy of this ciphertext, including the encrypted elements.

Returns

a new ciphertext equal to this one

inline bool operator==(const CiphertextImpl<Element> &rhs) const

Equality: same crypto context (by pointer) and key tag, equal slots, level, hop level, noise scale degree, scaling factors, encoding type, metadata entries and ring elements.

Parameters

rhs – the ciphertext to compare with

Returns

true if the ciphertexts are equal

inline bool operator!=(const CiphertextImpl<Element> &rhs) const

Inequality: negation of operator==.

Parameters

rhs – the ciphertext to compare with

Returns

true if the ciphertexts differ

template<class Archive>
inline void save(Archive &ar, std::uint32_t const version) const
template<class Archive>
inline void load(Archive &ar, std::uint32_t const version)
inline std::string SerializedObjectName() const
void SetLevel(size_t level)

DCRTPoly specialization of SetLevel(): stores the level and, for CKKS, checks that the ciphertext still has at least as many RNS limbs as its noise scale degree, throwing an exception that asks for a larger multiplicative depth otherwise.

Parameters

level – the number of scalings (level) of the ciphertext

void SetLevel(size_t level)

Public Static Functions

static inline uint32_t SerializedVersion()

Friends

inline friend std::ostream &operator<<(std::ostream &out, const CiphertextImpl<Element> &c)

Prints the encoding type, noise scale degree, metadata entries and every ring element of the ciphertext.

Parameters
  • out – the output stream

  • c – the ciphertext to print

Returns

the output stream

inline friend std::ostream &operator<<(std::ostream &out, Ciphertext<Element> c)

Prints the ciphertext a shared pointer refers to (see the reference overload).

Parameters
  • out – the output stream

  • c – shared pointer to the ciphertext to print

Returns

the output stream