A from-scratch TFHE (Threshold Fully Homomorphic Encryption) implementation in Go. Built directly on `luxfi/lattice` (RLWE, RGSW, blind rotation) with NTT SIMD acceleration written in Go. Native FHE — no external library dependency; the Lux stack is self-contained.
This library encrypts individual bits, bootstraps after every gate, and composes gates into arbitrary boolean circuits including full integer arithmetic. It supports encrypted integer types from 4-bit to 256-bit (including `euint160` for Ethereum addresses and `euint256` for uint256).
## Architecture
```
fhe.go Parameters, key generation, bootstrap key construction
Standard parameter sets: PN10QP27, PN11QP54, PN9QP28_STD128, PN9QP27_STD128Q
encryptor.go Bit and public-key encryption (LWE samples, Q/8 encoding)
decryptor.go Bit decryption (threshold extraction from LWE)
evaluator.go Boolean gate evaluation on encrypted bits
threshold_rng.go Threshold random number generation on encrypted data
```
### How It Works
1.**Encryption**: A plaintext bit is encoded as an LWE sample with noise: `(a, b = <a,s> + m*Q/8 + e)`. The `Q/8` encoding places TRUE at `+Q/8` and FALSE at `-Q/8`.
2.**Gate evaluation**: Two encrypted bits are added (producing a noisy result in `[-Q/4, Q/4]`), then a programmable blind rotation maps the result through a test polynomial that encodes the gate's truth table.
3.**Bootstrapping**: Every gate evaluation includes a full bootstrap (blind rotation + sample extraction + key switching), refreshing noise so gates can be composed indefinitely.
4.**Integer arithmetic**: Integers are radix-decomposed into encrypted bits. Addition uses a ripple-carry adder with lazy carry propagation. Multiplication uses shift-and-add. Comparison uses a cascaded bit-by-bit approach with the CMPCOMBINE gate.
| `FheUint4` | 4 | Short integer, nibble operations |
| `FheUint8` | 8 | Byte-level encrypted data |
| `FheUint16` | 16 | Short integers |
| `FheUint32` | 32 | Standard integers |
| `FheUint64` | 64 | Balances, timestamps |
| `FheUint128` | 128 | Large integers |
| `FheUint160` | 160 | Ethereum addresses |
| `FheUint256` | 256 | EVM uint256 |
## FFI Bindings
### C Shared Library
```bash
CGO_ENABLED=1 go build -buildmode=c-shared -o dist/libluxfhe.so ./bindings/cabi/
```
Produces `libluxfhe.{so,dylib,dll}` + `libluxfhe.h`. All Go objects are managed behind opaque `uint64` handles. Callable from Python (ctypes/cffi), TypeScript (N-API), or any C-compatible FFI.
### Rust
```bash
cd bindings/rust
cargo build --release
```
Rust bindings link against the C shared library via `build.rs`.