code wiki / (root) / fhe.nx

fhe.nx

buildroot/runtime/fhe.nx

5485 B158 linesdepth 3pulls 3 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

syscalls.nx fhe.nx

imports: 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 fhe_encrypt fhe_add fhe_mul fhe_decrypt fhe_budget_left fhe_bootstrap

structs

44struct FHECtx {
51struct FHECipher {

consts

33const FHE_SCHEME_BFV: i64 = 1
34const FHE_SCHEME_BGV: i64 = 2
35const FHE_SCHEME_CKKS: i64 = 3
36const FHE_SCHEME_TFHE: i64 = 4
38const FHE_ERR_PENDING: i64 = -1
39const FHE_ERR_BUDGET: i64 = -2

functions

59func fhe_ctx_new(scheme: i64, plain_mod: i64, poly_n: i64) -> *FHECtx {
called by 1: main
72func fhe_encrypt(c: *FHECtx, pt: i64) -> *FHECipher {
called by 1: main
86func fhe_decrypt(c: *FHECtx, ct: *FHECipher) -> i64 {
called by 1: main
92func fhe_add(a: *FHECipher, b: *FHECipher) -> *FHECipher {
called by 1: main
113func fhe_mul(a: *FHECipher, b: *FHECipher) -> *FHECipher {
called by 1: main
132func fhe_budget_left(ct: *FHECipher) -> i64 {
called by 1: main
138func fhe_bootstrap(ct: *FHECipher) -> i64 {
called by 1: main
144func main() -> i64 {