mirror of
https://github.com/luxfi/fhe.git
synced 2026-09-24 00:27:17 +00:00
5140bfa588fc8583f9287cbf7b9f193246cdadba
- data-seal: Verifiable Data Integrity Seal (PIP-0010/LP-0535) FHE-encrypted tamper-proof sealing with Public/ZK/Private modes, batch sealing, homomorphic verification - content-provenance: AI & Media Content Provenance (PIP-0011/LP-7110) Model manifests, output attestation via homomorphic comparison, media derivation DAGs - encrypted-crdt: Encrypted CRDT (PIP-0013/LP-6500) LWW-Register with FHE values, OR-Set with tag-based add/remove, Lamport timestamp conflict resolution, deterministic merge - shadow-governance: Shadow Government Protocol (PIP-7010) Anonymous ministries, encrypted voting with homomorphic tallying, nullifier-based anti-fraud, quorum enforcement Each example includes Solidity contracts, Hardhat tests, CLI tasks, and README linking to corresponding PIP and LP specifications.
Lux FHE
Fully Homomorphic Encryption (FHE) library for the Lux Network.
Features
- TFHE - Fast Boolean operations on encrypted data
- CKKS - Approximate arithmetic on encrypted vectors
- GPU Acceleration - Metal and CUDA support via luxfi/gpu
- Lazy Carry Propagation - Efficient integer arithmetic
- Multi-Party Computation - Threshold decryption support
Installation
go get github.com/luxfi/fhe
Usage
TFHE Boolean Gates
import "github.com/luxfi/fhe"
// Generate keys
params := fhe.DefaultTFHEParams()
keys, _ := fhe.GenerateTFHEKeys(params)
// Encrypt bits
ct1, _ := fhe.TFHEEncrypt(keys, true)
ct2, _ := fhe.TFHEEncrypt(keys, false)
// Homomorphic operations
ctAnd, _ := fhe.TFHEAnd(keys, ct1, ct2)
ctOr, _ := fhe.TFHEOr(keys, ct1, ct2)
ctNot, _ := fhe.TFHENot(keys, ct1)
// Decrypt
result, _ := fhe.TFHEDecrypt(keys, ctAnd) // false
Integer Operations
import "github.com/luxfi/fhe"
// Encrypt integers
a, _ := fhe.EncryptInt(keys, 42, 8) // 8-bit integer
b, _ := fhe.EncryptInt(keys, 10, 8)
// Arithmetic
sum, _ := fhe.IntAdd(keys, a, b)
diff, _ := fhe.IntSub(keys, a, b)
prod, _ := fhe.IntMul(keys, a, b)
// Comparison
isGreater, _ := fhe.IntGreaterThan(keys, a, b)
CKKS Approximate Arithmetic
import "github.com/luxfi/fhe"
// Setup CKKS
params := fhe.DefaultCKKSParams()
keys, _ := fhe.GenerateCKKSKeys(params)
// Encrypt vectors
values := []float64{1.0, 2.0, 3.0, 4.0}
ct, _ := fhe.CKKSEncrypt(keys, values)
// Operations
scaled, _ := fhe.CKKSMulScalar(ct, 2.5)
rotated, _ := fhe.CKKSRotate(keys, ct, 1)
// Decrypt
result, _ := fhe.CKKSDecrypt(keys, scaled)
API Reference
Key Generation
| Function | Description |
|---|---|
GenerateTFHEKeys(params) |
Generate TFHE key set |
GenerateCKKSKeys(params) |
Generate CKKS key set |
TFHE Operations
| Function | Description |
|---|---|
TFHEEncrypt(keys, bit) |
Encrypt a bit |
TFHEDecrypt(keys, ct) |
Decrypt a ciphertext |
TFHEAnd(keys, a, b) |
Homomorphic AND |
TFHEOr(keys, a, b) |
Homomorphic OR |
TFHENot(keys, a) |
Homomorphic NOT |
TFHENand(keys, a, b) |
Homomorphic NAND |
TFHEXor(keys, a, b) |
Homomorphic XOR |
TFHEBootstrap(keys, ct) |
Refresh ciphertext noise |
Integer Operations
| Function | Description |
|---|---|
EncryptInt(keys, value, bits) |
Encrypt integer |
DecryptInt(keys, ct) |
Decrypt integer |
IntAdd(keys, a, b) |
Addition |
IntSub(keys, a, b) |
Subtraction |
IntMul(keys, a, b) |
Multiplication |
IntGreaterThan(keys, a, b) |
Comparison |
CKKS Operations
| Function | Description |
|---|---|
CKKSEncrypt(keys, values) |
Encrypt vector |
CKKSDecrypt(keys, ct) |
Decrypt vector |
CKKSAdd(a, b) |
Vector addition |
CKKSMul(keys, a, b) |
Vector multiplication |
CKKSRotate(keys, ct, steps) |
Rotate slots |
GPU Acceleration
Enable GPU acceleration via the luxfi/gpu package:
import (
"github.com/luxfi/fhe"
"github.com/luxfi/gpu"
)
// Initialize GPU session
sess, _ := gpu.DefaultSession()
// Use GPU-accelerated FHE
fheOps := sess.FHE()
result, _ := fheOps.NTTForward(poly, modulus)
Examples
See the examples/ directory for complete examples:
examples/tfhe_basic/- Basic TFHE operationsexamples/integer_ops/- Integer arithmeticexamples/ckks_ml/- Machine learning on encrypted dataexamples/multiparty/- Threshold decryption
Documentation
Testing
# Run all tests
go test ./...
# With GPU
CGO_ENABLED=1 go test ./...
# Benchmarks
go test -bench=. ./...
Performance
Performance varies by operation and key parameters:
| Operation | Time (128-bit security) |
|---|---|
| TFHE Gate | ~10ms |
| Bootstrap | ~50ms |
| CKKS Add | <1ms |
| CKKS Mul | ~5ms |
| NTT (N=2^16) | ~1ms (GPU) |
License
BSD 3-Clause. See LICENSE.
Links
Languages
Go
86.1%
eC
9.7%
C
2.7%
Makefile
0.8%
Shell
0.7%