ComputeFHE 1.0
General-Purpose Privacy-Preserving Computation Library for TFHE
Loading...
Searching...
No Matches
ComputeFHE.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
13#pragma once
16#include <computefhe/BaseALU.h>
21#include <computefhe/Einteger.h>
22#include <computefhe/Evector.h>
26#include <openfhe/binfhe/binfhecontext.h>
27#include <vector>
28
29using namespace lbcrypto;
30using namespace std;
31
32namespace computefhe {
33 extern ComputeFHE *cfhe_base;
34 extern bool CLIENT_MODE;
35
47 void Init(CryptoContextParam cc_param = CCPARAM_STD128_3,
48 ALUType alu_type = ALU_OPTIMIZED, bool client_mode = false,
49 bool simulation_mode = false);
50
58 void Finalize();
59
68 class ComputeFHE {
69 private:
70 CryptoContextParam cc_param;
71 ALUType alu_type;
72 BinFHEContext cc;
73 LWEPrivateKey sk;
74 BaseALU *alu;
75 bool sim_mode;
76 bool auto_encrypt_mode;
77
78 void createCC();
79 void createALU();
80
81 public:
86 ComputeFHE(bool simulation_mode = false);
87
93 ComputeFHE(CryptoContextParam param, bool simulation_mode = false);
94
104 bool simulation_mode = false);
105
111 ComputeFHE(ALUType alu_type, bool simulation_mode = false);
112
115
117 BinFHEContext &GetBinFHEContext();
118
121
127
130
133
136 const LWEPrivateKey &GetLWEPrivateKey();
137
140 void SetLWEPrivateKey(const LWEPrivateKey &sk);
141
145
154 FixedPoint EncryptInt(uint64_t pt, size_t n_digits = 8,
155 bool fresh = true);
156
164 uint64_t DecryptInt(const FixedPoint &ct, size_t n_digits = 0);
165
172 BinaryDigit EncryptBool(bool pt, bool fresh = true);
173
179 bool DecryptBool(const BinaryDigit &ct);
180
193 FixedPoint GetConstantInt(uint64_t pt, size_t n_digits = 8);
194
201 uint64_t ConvertConstantInt(const FixedPoint &pt);
202
209 double extractNoise(ConstLWECiphertext &ct);
210
214
217 void PrintLWECiphertextParams(ConstLWECiphertext &ct);
218
223
235 void setAutoEncryptMode(bool mode = true);
236 };
237} // namespace computefhe
Defines the optimized ALU implementation using specialized multi-input FHE gates.
Defines the standard ALU implementation using fundamental FHE logic gates.
Defines the abstract base class for functional ALU simulators.
Defines the abstract base class for FHE-based Arithmetic Logic Units.
Defines core enumerations and helper functions for ComputeFHE configuration.
ALUType
Specifies the logic gate implementation strategy.
Definition CFHETypes.h:94
CryptoContextParam
Supported cryptographic context parameters for OpenFHE.
Definition CFHETypes.h:32
void Finalize()
Shuts down the ComputeFHE environment and releases global resources.
void Init(CryptoContextParam cc_param=CCPARAM_STD128_3, ALUType alu_type=ALU_OPTIMIZED, bool client_mode=false, bool simulation_mode=false)
Initializes the global ComputeFHE environment and cryptographic context.
Manages conditional execution state and branch tracking for encrypted operations.
Defines the encrypted fixed-point number representation and operations.
Defines the encrypted integer representation and operations.
Provides vector containers with support for oblivious, encrypted indexing.
Defines the fundamental bit-level and bit-vector data structures for FHE operations.
Simulator implementation for optimized ALU operations.
Simulator implementation for standard ALU operations.
Abstract base class for functional ALU simulators.
Definition BaseALUSimulator.h:29
Abstract base class for FHE-based Arithmetic Logic Units.
Definition BaseALU.h:30
The core manager class for the ComputeFHE library.
Definition ComputeFHE.h:68
void SetLWEPrivateKey(const LWEPrivateKey &sk)
Sets the LWE Private Key.
~ComputeFHE()
Destructor. Cleans up ALU and context resources.
FixedPoint GetConstantInt(uint64_t pt, size_t n_digits=8)
Creates an unencrypted FixedPoint representation of an integer.
double extractNoise(ConstLWECiphertext &ct)
Estimates the noise magnitude within a specific bit.
BaseALU * GetALU()
Returns the active ALU implementation.
void PrintCryptoContextParams()
Prints the current cryptographic context settings to stdout.
void generateKeys()
Generates the secret key and switching keys for the context.
FixedPoint EncryptInt(uint64_t pt, size_t n_digits=8, bool fresh=true)
Encrypts a 64-bit integer into a FixedPoint bit-vector.
bool isAutoEncryptMode()
Checks if Auto-Encrypt mode is enabled.
ComputeFHE(CryptoContextParam param, ALUType alu_type, bool simulation_mode=false)
Constructs a ComputeFHE instance with specific parameters and ALU type.
BinaryDigit EncryptBool(bool pt, bool fresh=true)
Encrypts a single boolean value.
ComputeFHE(bool simulation_mode=false)
Constructs a ComputeFHE instance.
const LWEPrivateKey & GetLWEPrivateKey()
Returns the LWE Private Key. Requires CLIENT_MODE to be true.
ALUType GetALUType()
Returns the current ALU type (STANDARD or OPTIMIZED).
CryptoContextParam GetCryptoContextParam()
Returns the current cryptographic context parameters.
bool DecryptBool(const BinaryDigit &ct)
Decrypts a single BinaryDigit bit.
BinFHEContext & GetBinFHEContext()
Returns the underlying OpenFHE BinFHEContext.
uint64_t ConvertConstantInt(const FixedPoint &pt)
Converts a constant (unencrypted) FixedPoint back to a 64-bit integer.
BaseALUSimulator * GetSimulator()
Returns the simulator instance. Only valid in simulation mode. Returns nullptr if simulation mode is ...
uint64_t DecryptInt(const FixedPoint &ct, size_t n_digits=0)
Decrypts a FixedPoint bit-vector back into a 64-bit integer.
void PrintLWECiphertextParams(ConstLWECiphertext &ct)
Prints technical details about a specific LWE ciphertext to stdout.
ComputeFHE(ALUType alu_type, bool simulation_mode=false)
Constructs a ComputeFHE instance with a specific ALU type.
void setAutoEncryptMode(bool mode=true)
Sets the Auto-Encrypt mode.
ComputeFHE(CryptoContextParam param, bool simulation_mode=false)
Constructs a ComputeFHE instance with specific parameters.
A proxy-object representing a single bit that can behave as either a ciphertext or a plaintext.
Definition FixedPoint.h:35
A bit-vector representation of an encrypted or plaintext word.
Definition FixedPoint.h:118