ComputeFHE 1.0
General-Purpose Privacy-Preserving Computation Library for TFHE
Loading...
Searching...
No Matches
FixedPoint.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Faris Serdar Taşel <fst@cankaya.edu.tr>
3 * SPDX-FileCopyrightText: 2026 Efe Çiftci <efeciftci@cankaya.edu.tr>
4 *
5 * SPDX-License-Identifier: MIT
6 */
7
14#pragma once
15#include <openfhe/binfhe/binfhecontext.h>
16#include <vector>
17
18using namespace lbcrypto;
19using namespace std;
20
21#define COPY_CT(x) std::make_shared<LWECiphertextImpl>(*x)
22
23namespace computefhe {
24
35 struct BinaryDigit : public Serializable {
36 static uint
38 uint id = 0;
41 bool is_ct;
42
56 bool is_ct = false);
57
66
68 bool operator==(const BinaryDigit &other) const;
70 bool operator!=(const BinaryDigit &other) const;
71
73 operator LWECiphertext &();
75 operator const LWECiphertext &() const;
77 operator ConstLWECiphertext() const;
79 operator LWEPlaintext() const;
80
81 // Serialization support
82 template <class Archive>
83 void save(Archive &ar, std::uint32_t const version) const {
84 ar(cereal::make_nvp("c", c));
85 ar(cereal::make_nvp("p", p));
86 ar(cereal::make_nvp("is_ct", is_ct));
87 }
88
89 template <class Archive>
90 void load(Archive &ar, std::uint32_t const version) {
91 if (version > SerializedVersion()) {
92 OPENFHE_THROW("serialized object version " +
93 std::to_string(version) +
94 " is from a later version of the library");
95 }
96 ar(cereal::make_nvp("c", c));
97 ar(cereal::make_nvp("p", p));
98 ar(cereal::make_nvp("is_ct", is_ct));
99 this->id = new_id++;
100 }
101
102 std::string SerializedObjectName() const override {
103 return "BinaryDigit";
104 }
105
106 static uint32_t SerializedVersion() { return 1; }
107 };
108
118 struct FixedPoint : public vector<BinaryDigit> {
122 FixedPoint(size_t n);
125 FixedPoint(vector<BinaryDigit>::const_iterator begin,
126 vector<BinaryDigit>::const_iterator end);
128 FixedPoint(std::initializer_list<BinaryDigit> list);
135
140 bool is_ct() const;
141 };
142} // namespace computefhe
Proxy object for accessing and modifying elements in an Evector using encrypted indices.
Definition Evector.h:45
A proxy-object representing a single bit that can behave as either a ciphertext or a plaintext.
Definition FixedPoint.h:35
BinaryDigit(const BinaryDigit &other)
Copy constructor.
BinaryDigit & operator=(LWEPlaintext pt)
Assigns a plaintext bit to the proxy and sets is_ct to false.
BinaryDigit(const LWECiphertext &ct)
Constructs a proxy from a ciphertext object.
BinaryDigit()
Default constructor.
bool is_ct
True if the object is currently acting as a ciphertext.
Definition FixedPoint.h:41
static uint new_id
Global static counter used to assign unique IDs.
Definition FixedPoint.h:37
BinaryDigit & operator=(const BinaryDigit &other)
Assignment from another BinaryDigit proxy.
LWECiphertext c
The underlying LWE ciphertext bit.
Definition FixedPoint.h:39
BinaryDigit(LWEPlaintext pt)
Constructs a proxy from a plaintext bit.
LWEPlaintext p
The underlying LWE plaintext bit.
Definition FixedPoint.h:40
bool operator==(const BinaryDigit &other) const
Compares two proxy bits for equality.
BinaryDigit(ConstLWECiphertext &ct)
Constructs a proxy from a constant ciphertext reference.
BinaryDigit(const ConstLWECiphertext &ct, LWEPlaintext pt, bool is_ct=false)
Constructs a proxy with specific ciphertext and plaintext values.
bool operator!=(const BinaryDigit &other) const
Compares two proxy bits for inequality.
BinaryDigit & operator=(const LWECiphertext &other)
Assigns a ciphertext bit to the proxy and sets is_ct to true.
A bit-vector representation of an encrypted or plaintext word.
Definition FixedPoint.h:118
FixedPoint(const vector< BinaryDigit > &other)
Constructs from an existing vector of BinaryDigit proxies.
bool is_ct() const
Determines if the bit-vector represents encrypted data.
FixedPoint()
Default constructor.
FixedPoint(const vector< LWEPlaintext > &other)
Constructs from a vector of plaintext bits.
FixedPoint(vector< BinaryDigit >::const_iterator begin, vector< BinaryDigit >::const_iterator end)
Constructs a bit-vector from a range of BinaryDigit proxies.
FixedPoint(std::initializer_list< BinaryDigit > list)
Constructs a bit-vector from an initializer list of bits.
FixedPoint(size_t n)
Constructs a bit-vector of size n.
FixedPoint(const vector< LWECiphertext > &other)
Constructs from a vector of LWE ciphertexts.