code wiki / (root) / nx_rsa4096_mont.nx

nx_rsa4096_mont.nx

buildroot/runtime/nx_rsa4096_mont.nx

5791 B138 linesdepth 5pulls 5 transitivereach 529 importersview sourcekind tooltopic rsa4096
docsdependenciesstructsconstsfunctions

about

nx_rsa4096_mont.nx -- CIOS Montgomery modular multiplication + modexp for the 4096-bit RSA modulus. THE FIX (operator 2026-06-23, found by the apm->conductor->drill loop): RSA-2048 got Montgomery (nx_rsa2048_mont, ~1.5s->few ms), but RSA-4096 NEVER DID -- it still used the slow bit-by-bit rsa4096_mod_exp (rsa4096_mul_mod = u4096_mul + rsa4096_mod reduction, ~18x per verify). Real Web PKI chains terminate at an RSA-4096 ROOT (e.g. Let's Encrypt's ISRG Root X1), so the intermediate-under-root link paid ~242ms (the apm "cert link alg=3" certloop hotspot). This is the 128-limb CIOS Montgomery, byte-identical to rsa4096_mod_exp (KAT-gated in nx_rsa4096_mont_gate), cutting that link to a few ms. Adapts nx_rsa2048_mont 64->128 limbs verbatim (CIOS is limb-parametric). Side-channels: verifies PUBLIC certs, constant-time not required. license_tier: INDEPENDENT_REDERIVE

dependencies 3 imports · 2 importers

nx_syscalls.nx nx_u4096.nx nx_rsa4096_mod.nx nx_rsa4096_mont.nx nx_rsa4096_mont_gate.nx nx_rsa_pkcs1_v1_5_sha256_4096.nx

imports: nx_syscalls.nxnx_u4096.nxnx_rsa4096_mod.nx

imported by: nx_rsa4096_mont_gate.nxnx_rsa_pkcs1_v1_5_sha256_4096.nx

structs

none

consts

14const NX_MAGIC_4096: i64 = 4096
16const NX_RSA4096_MONT_OK: i64 = 1
17const NX_RSA4096_MONT_S_OUT_OF_RANGE: i64 = 2

functions

19func rsa4096_mont_highbit(e: i64) -> i64
26func rsa4096_mont_n0inv(n0_full: i64) -> i64
40func rsa4096_mont_mul(out: *i64, a: *i64, b: *i64, n: *i64, n0inv: i64) -> i64
90func rsa4096_mont_r2(out: *i64, n: *i64) -> i64
104func rsa4096_mod_exp_mont(out: *i64, s: *i64, e: i64, n: *i64) -> i64
138func main() -> i64 { return 0 }