fhe.nx
buildroot/runtime/fhe.nx
about
fhe.nx -- fully homomorphic encryption scaffold.
EFFICIENCY_ROADMAP ยง6.1. Compute on ciphertext; the party
holding the key never sees plaintext, yet gets the right
answer. Targets privacy-preserving analytics, untrusted
compute substrates (cloud as "hostile arithmetic factory").
Schemes available today:
BFV / BGV -- exact integer arithmetic, SIMD-friendly
CKKS -- approximate real arithmetic, batching
TFHE -- binary / bit-level, fast bootstrapping
Each has its own complexity tradeoffs. Our scaffold exposes
a uniform API (`fhe_add`, `fhe_mul`, `fhe_rotate`) + a
scheme-selector enum; dispatchable backends land later.
Full implementations are ENORMOUS: OpenFHE is ~200k LoC C++,
SEAL is ~100k. Phase A here is API-locking + noise-budget
accounting so library code that wants to "maybe run FHE
someday" can be written in terms of the right abstractions
now.
Invariants:
FHE1 All ciphertext operations are CONSTANT time in the
plaintext (leaking neither value nor sign).
FHE2 Every op consumes "noise budget"; fhe_budget_left
reports remaining. Bootstrap refreshes (expensive).
FHE3 Decrypt with the wrong key produces random garbage,
NOT an error indication -- semantic security.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 44 | struct FHECtx { |
| 51 | struct FHECipher { |
consts
| 33 | const FHE_SCHEME_BFV: i64 = 1 |
| 34 | const FHE_SCHEME_BGV: i64 = 2 |
| 35 | const FHE_SCHEME_CKKS: i64 = 3 |
| 36 | const FHE_SCHEME_TFHE: i64 = 4 |
| 38 | const FHE_ERR_PENDING: i64 = -1 |
| 39 | const FHE_ERR_BUDGET: i64 = -2 |
functions
| 59 | func fhe_ctx_new(scheme: i64, plain_mod: i64, poly_n: i64) -> *FHECtx {
called by 1: main |
| 72 | func fhe_encrypt(c: *FHECtx, pt: i64) -> *FHECipher {
called by 1: main |
| 86 | func fhe_decrypt(c: *FHECtx, ct: *FHECipher) -> i64 {
called by 1: main |
| 92 | func fhe_add(a: *FHECipher, b: *FHECipher) -> *FHECipher {
called by 1: main |
| 113 | func fhe_mul(a: *FHECipher, b: *FHECipher) -> *FHECipher {
called by 1: main |
| 132 | func fhe_budget_left(ct: *FHECipher) -> i64 {
called by 1: main |
| 138 | func fhe_bootstrap(ct: *FHECipher) -> i64 {
called by 1: main |
| 144 | func main() -> i64 { |