@digitaldefiance/node-fhe-accelerate
v0.1.4
Published
NOT YET IMPLEMENTED. Apple Silicon hardware detection and modular-arithmetic primitives. No FHE operations exist: createEngine() rejects. Do not use for encryption.
Maintainers
Readme
@digitaldefiance/node-fhe-accelerate
Hardware-accelerated NTT and modular arithmetic primitives for Apple Silicon. The foundation for an FHE library, not yet a complete one.
Status
What works today:
NttProcessor— negacyclic Number Theoretic Transform over Z_q[X]/(X^N + 1). Cooley-Tukey with NEON butterflies when available. Verified with the convolution identity gate (not a round-trip — round-trips cannot catch the defect class this library was built to remove). 0.096ms at N=1024 on M4 Max.ModularArithmetic— Montgomery multiplication, modular add/sub, to/from Montgomery form.detectHardware()— reports SME, Metal, NEON availability on this machine.
What does not exist:
- Polynomial ring multiplication (the orchestration layer over NTT — see roadmap)
- Key generation, encryption, decryption
- Homomorphic operations (add, multiply, relinearize, bootstrap)
- Noise sampling
- Any complete FHE scheme (TFHE, BFV, CKKS)
createEngine() rejects with "Not yet implemented." The ZK proof entry points throw. Do not use this for encryption or for zero-knowledge proofs.
Install
npm install @digitaldefiance/apple-silicon-capsRequires macOS arm64 and Xcode Command Line Tools (for the native build).
Usage
const { NttProcessor, ModularArithmetic, detectHardware } = require('@digitaldefiance/node-fhe-accelerate');
// Hardware detection
const hw = detectHardware();
console.log(hw); // { hasSme: true, hasMetal: true, hasNeon: true, ... }
// NTT: negacyclic polynomial multiplication
const N = 1024;
const q = 132120577; // NTT-friendly prime, q ≡ 1 (mod 2N)
const ntt = new NttProcessor(N, q);
const a = new Array(N).fill(0); a[0] = 1; a[1] = 2;
const b = new Array(N).fill(0); b[0] = 3; b[1] = 4;
const aNtt = ntt.forward(a);
const bNtt = ntt.forward(b);
// Pointwise multiply in NTT domain (use ModularArithmetic or BigInt)
const mulmod = (x, y) => Number(BigInt(x) * BigInt(y) % BigInt(q));
const cNtt = aNtt.map((v, i) => mulmod(v, bNtt[i]));
const c = ntt.inverse(cNtt);
// c = a * b in Z_q[X]/(X^N + 1)
// Modular arithmetic
const ma = new ModularArithmetic(q);
console.log(ma.montgomeryMul(ma.toMontgomery(7), ma.toMontgomery(9)));Roadmap
What FHE needs, in dependency order. Checked items exist; unchecked items do not.
- [x] Modular arithmetic — Montgomery multiplication, add, sub
- [x] NTT — negacyclic Cooley-Tukey, forward and inverse, NEON path
- [x] Hardware detection — SME, Metal, NEON, topology
- [ ] Polynomial ring — multiply/add/sub over Z_q[X]/(X^N+1) via NTT. Next step. The NTT does the heavy lifting; this is the forward/pointwise/inverse orchestration.
- [ ] Noise sampling — discrete Gaussian or centered binomial distribution
- [ ] Key generation — LWE/GLWE secret keys, public keys
- [ ] Encryption / Decryption — RLWE samples, rounding
- [ ] Homomorphic addition — coefficient-wise add on ciphertexts
- [ ] Key switching — gadget decomposition, external product
- [ ] Homomorphic multiplication — tensor product + relinearization
- [ ] Bootstrapping — blind rotation, sample extraction. The research frontier of FHE.
Each layer builds on the ones above it. The polynomial ring is achievable in a session; bootstrapping is a research project.
Correctness methodology
This library uses the negacyclic convolution identity as its correctness gate, not round-trip tests. The reason: the Cooley-Tukey / Gentleman-Sande butterfly pair is 2·I for any nonzero twiddle, so a forward-then-inverse round-trip passes even with completely wrong twiddle tables. The convolution identity — sparse operands with X^(N-1) populated so the X^N = -1 sign flip is exercised — catches the defect because it requires the psi twist to be a genuine 2N-th root of unity.
This methodology is documented in detail in the companion paper at fhe-evolve, §6.6 "Round-Trip Verification Is Insufficient."
History
Versions 0.1.0 and 0.1.1 are deprecated. 0.1.0 could not be imported (extensionless ESM re-exports). Its ZK proof subsystem simulated verification by sleeping via setTimeout and returning valid: true for any proof input, including for ballot validity and voter eligibility. That code now throws.
Platform
macOS arm64 only. Requires Xcode Command Line Tools for the native build at install time.
License
MIT. Copyright (c) 2025 Digital Defiance, Jessica Mulein.
