code wiki / (root) / nx_fhe.nx

nx_fhe.nx

buildroot/runtime/nx_fhe.nx

5669 B166 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_fhe.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main fhe_ctx_new sys_mmap fhe_encrypt sys_mmap ↻ fhe_add sys_mmap ↻ fhe_mul sys_mmap ↻ fhe_decrypt fhe_budget_left fhe_bootstrap

structs

52struct FHECtx
59struct FHECipher

consts

38const FHE_MAGIC_65537: i64 = 65537
39const FHE_MAGIC_4096: i64 = 4096
41const FHE_SCHEME_BFV: i64 = 1
42const FHE_SCHEME_BGV: i64 = 2
43const FHE_SCHEME_CKKS: i64 = 3
44const FHE_SCHEME_TFHE: i64 = 4
46const FHE_ERR_PENDING: i64 = -1
47const FHE_ERR_BUDGET: i64 = -2

functions

67func fhe_ctx_new(scheme: i64, plain_mod: i64, poly_n: i64) -> *FHECtx
called by 1: main calls 1: sys_mmap
80func fhe_encrypt(c: *FHECtx, pt: i64) -> *FHECipher
called by 1: main calls 1: sys_mmap
94func fhe_decrypt(c: *FHECtx, ct: *FHECipher) -> i64
called by 1: main
100func fhe_add(a: *FHECipher, b: *FHECipher) -> *FHECipher
called by 1: main calls 1: sys_mmap
121func fhe_mul(a: *FHECipher, b: *FHECipher) -> *FHECipher
called by 1: main calls 1: sys_mmap
140func fhe_budget_left(ct: *FHECipher) -> i64
called by 1: main
146func fhe_bootstrap(ct: *FHECipher) -> i64
called by 1: main
152func main() -> i64