|
ComputeFHE 1.0
General-Purpose Privacy-Preserving Computation Library for TFHE
|
Abstract base class for FHE-based Arithmetic Logic Units. More...
#include <BaseALU.h>


Public Member Functions | |
| BaseALU (ComputeFHE *cfhe) | |
| Construct a new BaseALU object. | |
| virtual | ~BaseALU () |
| Destroy the BaseALU object. | |
| virtual BinaryDigit | GetCarry () |
| Returns the current internal carry state. | |
| virtual void | SetCarry (BinaryDigit value) |
| Manually sets the internal carry to a specific value. | |
| virtual void | SetCarry () |
| Sets the internal carry to an encrypted 'True' value. | |
| virtual void | ResetCarry () |
| Resets the internal carry to an encrypted 'False' value. | |
FHE-Level Gates | |
These methods provide logical abstractions. | |
| virtual BinaryDigit | FHE_False () |
| virtual BinaryDigit | FHE_True () |
| virtual BinaryDigit | FHE_AND (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | FHE_NAND (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | FHE_OR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | FHE_NOR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | FHE_XOR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | FHE_XNOR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | FHE_NOT (const BinaryDigit &a) |
| virtual BinaryDigit | FHE_MUX (const BinaryDigit &s, const BinaryDigit &a, const BinaryDigit &b) |
Base Logic Gates | |
Fundamental cryptographic gate implementations. | |
| virtual BinaryDigit | Constant0 () |
| Returns encrypted constant 0 (false). | |
| virtual BinaryDigit | Constant1 () |
| Returns encrypted constant 1 (true). | |
| virtual BinaryDigit | Gate_AND (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | Gate_NAND (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | Gate_OR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | Gate_NOR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | Gate_XOR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | Gate_XNOR (const BinaryDigit &a, const BinaryDigit &b) |
| virtual BinaryDigit | Gate_NOT (const BinaryDigit &a) |
| virtual BinaryDigit | Gate_MUX (const BinaryDigit &s, const BinaryDigit &a, const BinaryDigit &b) |
Abstract Specialized Gates | |
Pure virtual methods that must be implemented by optimized or standard ALU logic. | |
| virtual BinaryDigit | Gate_MAJ (const BinaryDigit &a, const BinaryDigit &b, const BinaryDigit &c)=0 |
| Majority gate: returns true if at least two inputs are true. | |
| virtual BinaryDigit | Gate_XOR3 (const BinaryDigit &a, const BinaryDigit &b, const BinaryDigit &c)=0 |
| 3-input XOR gate. | |
| virtual BinaryDigit | Gate_MulAdd (const BinaryDigit &m, const BinaryDigit &a, const BinaryDigit &b, BinaryDigit *carry_out=nullptr)=0 |
| Multiplies two digits and adds a third, optionally returning carry out. | |
| virtual BinaryDigit | Gate_DigitSum (const BinaryDigit &e1, const BinaryDigit &e0, const BinaryDigit &s0)=0 |
| Performs bitwise digit summation logic. | |
Word-Level Interface | |
Operations acting on multi-bit FixedPoint objects. | |
| virtual FixedPoint | Mux (const BinaryDigit &s, const FixedPoint &a, const FixedPoint &b)=0 |
| Multiplexer for FixedPoint values: returns 'a' if 's' is true, else 'b'. | |
| virtual FixedPoint | ToggleMSB (const FixedPoint &a)=0 |
| Toggles the Most Significant Bit (useful for sign manipulation). | |
| virtual FixedPoint | ShiftLeft (const FixedPoint &a, size_t shift)=0 |
| Logical shift left. | |
| virtual FixedPoint | ShiftRight (const FixedPoint &a, size_t shift, bool is_arithmetic=false)=0 |
| Shift right (supports both logical and arithmetic/signed shifts). | |
| virtual void | Swap_if (const BinaryDigit &cond, BinaryDigit &a, BinaryDigit &b)=0 |
| Conditional swap of two bits if 'cond' is true. | |
| virtual void | Swap_if (const BinaryDigit &cond, FixedPoint &a, FixedPoint &b)=0 |
| Conditional swap of two FixedPoint values if 'cond' is true. | |
| virtual void | HalfAdder (const BinaryDigit &a, const BinaryDigit &b, BinaryDigit &sum, BinaryDigit &carry_out)=0 |
| 1-bit half adder. | |
| virtual void | HalfSubtractor (const BinaryDigit &a, const BinaryDigit &b, BinaryDigit &sum, BinaryDigit &carry_out)=0 |
| 1-bit half subtractor. | |
| virtual void | FullAdder (const BinaryDigit &a, const BinaryDigit &b, const BinaryDigit &c, BinaryDigit &sum, BinaryDigit &carry_out)=0 |
| 1-bit full adder with explicit carry-in. | |
Ciphertext-Ciphertext Arithmetic | |
Standard arithmetic between two encrypted FixedPoint values. | |
| virtual FixedPoint | Add (const FixedPoint &a, const FixedPoint &b)=0 |
| Addition: result = a + b. | |
| virtual FixedPoint | AddC (const FixedPoint &a, const FixedPoint &b)=0 |
| Addition with Carry: result = a + b + carry. | |
| virtual FixedPoint | AddNC (const FixedPoint &a, const FixedPoint &b)=0 |
| Addition without updating internal carry. | |
| virtual FixedPoint | AddCNC (const FixedPoint &a, const FixedPoint &b)=0 |
| Addition with Carry, but without updating internal carry. | |
| virtual FixedPoint | Sub (const FixedPoint &a, const FixedPoint &b)=0 |
| Subtraction: result = a - b. | |
| virtual FixedPoint | SubC (const FixedPoint &a, const FixedPoint &b)=0 |
| Subtraction with Borrow (!Carry): result = a - b - !carry. | |
| virtual FixedPoint | SubNC (const FixedPoint &a, const FixedPoint &b)=0 |
| Subtraction without updating internal carry. | |
| virtual FixedPoint | SubCNC (const FixedPoint &a, const FixedPoint &b)=0 |
| Subtraction with Carry, but without updating internal carry. | |
| virtual FixedPoint | Neg (const FixedPoint &a)=0 |
| Arithmetic negation: result = -a. | |
| virtual FixedPoint | Not (const FixedPoint &a)=0 |
| Bitwise NOT. | |
Comparisons | |
Logical comparisons returning encrypted boolean bits. | |
| virtual BinaryDigit | CmpNotEq (const FixedPoint &a, const FixedPoint &b)=0 |
| Not-Equal. | |
| virtual BinaryDigit | CmpEq (const FixedPoint &a, const FixedPoint &b)=0 |
| Equal. | |
| virtual BinaryDigit | CmpLTEq_U (const FixedPoint &a, const FixedPoint &b)=0 |
| Unsigned Less-Than or Equal. | |
| virtual BinaryDigit | CmpGT_U (const FixedPoint &a, const FixedPoint &b)=0 |
| Unsigned Greater-Than. | |
| virtual BinaryDigit | CmpGTEq_U (const FixedPoint &a, const FixedPoint &b)=0 |
| Unsigned Greater-Than or Equal. | |
| virtual BinaryDigit | CmpLT_U (const FixedPoint &a, const FixedPoint &b)=0 |
| Unsigned Less-Than. | |
| virtual BinaryDigit | CmpLTEq (const FixedPoint &a, const FixedPoint &b)=0 |
| Signed Less-Than or Equal. | |
| virtual BinaryDigit | CmpGT (const FixedPoint &a, const FixedPoint &b)=0 |
| Signed Greater-Than. | |
| virtual BinaryDigit | CmpGTEq (const FixedPoint &a, const FixedPoint &b)=0 |
| Signed Greater-Than or Equal. | |
| virtual BinaryDigit | CmpLT (const FixedPoint &a, const FixedPoint &b)=0 |
| Signed Less-Than. | |
Multi-Word Arithmetic | |
Complex arithmetic operations. | |
| virtual FixedPoint | FullMul (const FixedPoint &a, const FixedPoint &b)=0 |
| Performs full multiplication resulting in potentially larger bit-width. | |
| virtual FixedPoint | Mul (const FixedPoint &a, const FixedPoint &b)=0 |
| Standard multiplication (truncated to input width). | |
| virtual void | DivU (const FixedPoint &a, const FixedPoint &b, FixedPoint &q, FixedPoint &r)=0 |
| Unsigned division, calculating quotient (q) and remainder (r). | |
Ciphertext-Plaintext Arithmetic | |
Optimized operations where one operand is a known plaintext constant (pb/pa). | |
| virtual FixedPoint | PAdd (const FixedPoint &a, const FixedPoint &pb)=0 |
| Plaintext addition: result = a + pb. | |
| virtual FixedPoint | PAddC (const FixedPoint &a, const FixedPoint &pb)=0 |
| Plaintext addition with carry. | |
| virtual FixedPoint | PAddNC (const FixedPoint &a, const FixedPoint &pb)=0 |
| Plaintext addition without updating internal carry. | |
| virtual FixedPoint | PAddCNC (const FixedPoint &a, const FixedPoint &pb)=0 |
| Plaintext addition with carry, but no update to internal state. | |
| virtual FixedPoint | PSub (const FixedPoint &pa, const FixedPoint &b)=0 |
| Plaintext subtraction: result = pa - b. | |
| virtual FixedPoint | PSubC (const FixedPoint &pa, const FixedPoint &b)=0 |
| Plaintext subtraction with carry. | |
| virtual FixedPoint | PSubNC (const FixedPoint &pa, const FixedPoint &b)=0 |
| Plaintext subtraction without updating internal carry. | |
| virtual FixedPoint | PSubCNC (const FixedPoint &pa, const FixedPoint &b)=0 |
| Plaintext subtraction with carry, but no update to internal state. | |
| virtual FixedPoint | CPSub (const FixedPoint &a, const FixedPoint &pb)=0 |
| Ciphertext-Plaintext subtraction: result = a - pb. | |
| virtual FixedPoint | CPSubC (const FixedPoint &a, const FixedPoint &pb)=0 |
| Ciphertext-Plaintext subtraction with carry. | |
| virtual FixedPoint | CPSubNC (const FixedPoint &a, const FixedPoint &pb)=0 |
| Ciphertext-Plaintext subtraction without updating internal carry. | |
| virtual FixedPoint | CPSubCNC (const FixedPoint &a, const FixedPoint &pb)=0 |
| Ciphertext-Plaintext subtraction with carry, no update. | |
| virtual FixedPoint | PFullMul (const FixedPoint &a, const FixedPoint &pb)=0 |
| Full multiplication by a plaintext constant. | |
| virtual FixedPoint | PFullMulFast (const FixedPoint &a, const FixedPoint &pb)=0 |
| Optimized full multiplication by a plaintext constant. | |
| virtual FixedPoint | PBoothsMul (const FixedPoint &a, const FixedPoint &pb)=0 |
| Multiplication using Booth's algorithm with a plaintext constant. | |
| virtual FixedPoint | PMul (const FixedPoint &a, const FixedPoint &pb)=0 |
| Standard multiplication by a plaintext constant. | |
| virtual FixedPoint | PMulFast (const FixedPoint &a, const FixedPoint &pb)=0 |
| Optimized standard multiplication by a plaintext constant. | |
Protected Attributes | |
| BinaryDigit | carry |
| ComputeFHE * | cfhe_base |
Abstract base class for FHE-based Arithmetic Logic Units.
This class defines the interface for all logic and arithmetic operations performed on encrypted data (FixedPoint and BinaryDigit). It manages internal state such as carry flags and provides gate-level operations.
| computefhe::BaseALU::BaseALU | ( | ComputeFHE * | cfhe | ) |
Construct a new BaseALU object.
| cfhe | Pointer to the ComputeFHE instance providing the crypto context. |
|
pure virtual |
Addition: result = a + b.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Addition with Carry: result = a + b + carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Addition with Carry, but without updating internal carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Addition without updating internal carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Equal.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Signed Greater-Than.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Unsigned Greater-Than.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Signed Greater-Than or Equal.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Unsigned Greater-Than or Equal.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Signed Less-Than.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Unsigned Less-Than.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Signed Less-Than or Equal.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Unsigned Less-Than or Equal.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Not-Equal.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Ciphertext-Plaintext subtraction: result = a - pb.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Ciphertext-Plaintext subtraction with carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Ciphertext-Plaintext subtraction with carry, no update.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Ciphertext-Plaintext subtraction without updating internal carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Unsigned division, calculating quotient (q) and remainder (r).
Implemented in computefhe::ALUStandard.
|
pure virtual |
1-bit full adder with explicit carry-in.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Performs full multiplication resulting in potentially larger bit-width.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Performs bitwise digit summation logic.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Majority gate: returns true if at least two inputs are true.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Multiplies two digits and adds a third, optionally returning carry out.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
3-input XOR gate.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
1-bit half adder.
Implemented in computefhe::ALUStandard.
|
pure virtual |
1-bit half subtractor.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Standard multiplication (truncated to input width).
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Multiplexer for FixedPoint values: returns 'a' if 's' is true, else 'b'.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Arithmetic negation: result = -a.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Bitwise NOT.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Plaintext addition: result = a + pb.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Plaintext addition with carry.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Plaintext addition with carry, but no update to internal state.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Plaintext addition without updating internal carry.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Multiplication using Booth's algorithm with a plaintext constant.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Full multiplication by a plaintext constant.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Optimized full multiplication by a plaintext constant.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Standard multiplication by a plaintext constant.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Optimized standard multiplication by a plaintext constant.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Plaintext subtraction: result = pa - b.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Plaintext subtraction with carry.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Plaintext subtraction with carry, but no update to internal state.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Plaintext subtraction without updating internal carry.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Logical shift left.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Shift right (supports both logical and arithmetic/signed shifts).
Implemented in computefhe::ALUStandard.
|
pure virtual |
Subtraction: result = a - b.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Subtraction with Borrow (!Carry): result = a - b - !carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Subtraction with Carry, but without updating internal carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Subtraction without updating internal carry.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Conditional swap of two bits if 'cond' is true.
Implemented in computefhe::ALUOptimized, and computefhe::ALUStandard.
|
pure virtual |
Conditional swap of two FixedPoint values if 'cond' is true.
Implemented in computefhe::ALUStandard.
|
pure virtual |
Toggles the Most Significant Bit (useful for sign manipulation).
Implemented in computefhe::ALUStandard.