nx_rsa2048_mont.nx
buildroot/runtime/nx_rsa2048_mont.nx
about
nx_rsa2048_mont.nx -- Montgomery modular multiplication + modexp for the
2048-bit RSA modulus. Replaces the O(bits*n) bit-by-bit reduction
(nx_rsa2048_mod.nx, "a few seconds per verify") with CIOS Montgomery
multiplication (O(n^2) limb ops), measured to cut TLS cert-verify from
~1.5s to a few ms (sovereign native perf timers in nx_https_get / _session_run).
32-bit limbs in 64-bit words make CIOS overflow-safe: the inner
accumulate t[j] + a[j]*b[i] + carry has max value (2^32-1)^2 + 2*(2^32-1)
= 2^64 - 1, which fits one unsigned 64-bit word exactly. Carry/low are
extracted with (x>>32)&MASK / x&MASK (correct under arithmetic shift+mask).
Side channels: this verifies PUBLIC server certificates (modulus, signature,
and exponent are all public), so constant-time is not required here.
Correctness is pinned by KAT equality against the bit-by-bit rsa2048_mod_exp
in nx_rsa2048_mont_gate.nx -- both must produce identical s^e mod n.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/ietf/rfc_8017 (Montgomery 1985; Koc CIOS)
lineage_id: nishi_rsa2048_mont_q10
dependencies 4 imports · 5 importers
imports: nx_syscalls.nxnx_u2048.nxnx_u2048_mul.nxnx_rsa2048_mod.nx
imported by: nx_rsa2048_mont_gate.nxnx_rsa_pkcs1_v1_5_sha256.nxnx_rsa_pkcs1_v1_5_sha384.nxnx_rsa_pkcs1_v1_5_sha512.nxnx_rsa_pss_sha256.nx
structs
| none |
consts
| 26 | const NX_MAGIC_2048: i64 = 2048 |
| 28 | const NX_RSA2048_MONT_OK: i64 = 1 |
| 29 | const NX_RSA2048_MONT_S_OUT_OF_RANGE: i64 = 2 |
functions
| 32 | func rsa2048_mont_highbit(e: i64) -> i64 called by 1: rsa2048_mod_exp_mont |
| 44 | func rsa2048_mont_n0inv(n0_full: i64) -> i64 called by 1: rsa2048_mod_exp_mont |
| 58 | func rsa2048_mont_mul(out: *i64, a: *i64, b: *i64, n: *i64, n0inv: i64) -> i64 |
| 108 | func rsa2048_mont_r2(out: *i64, n: *i64) -> i64 |
| 118 | func rsa2048_mod_exp_mont(out: *i64, s: *i64, e: i64, n: *i64) -> i64 |
| 148 | func main() -> i64 |