code wiki / (root) / nx_rsa2048_mod.nx

nx_rsa2048_mod.nx

buildroot/runtime/nx_rsa2048_mod.nx

2548 B74 linesdepth 4pulls 4 transitivereach 546 importersview sourcekind tooltopic rsa2048
docsdependenciesstructsconstsfunctions

about

nx_rsa2048_mod.nx -- bit-by-bit reduction mod 2048-bit modulus. Given a 4096-bit dividend (in a 128-limb wide buffer) and a 2048-bit modulus n (in a 64-limb u2048 buffer with the top bit set), compute the 2048-bit remainder. Algorithm (shift-and-subtract, MSB-first): rem = 0 (u2048; one extra "carry" bit kept separately) for i in 4095 down to 0: rem = (rem << 1) | bit_i(dividend) if (carry from shift) OR (rem >= n): rem -= n return rem O(4096 * 64) limb operations ~= O(262K) per reduction. Combined with 17 squarings/mul for RSA-2048 verify (e=65537), one verify is ~4-5M limb ops -- a few seconds in qemu-riscv64. API: rsa2048_mod(out_64, dividend_128, n_64) -- out_64 = dividend_128 mod n_64 license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_8017 lineage_id: nishi_rsa2048_mod_q10

dependencies 3 imports · 3 importers

nx_syscalls.nx nx_u2048.nx nx_u2048_mul.nx nx_rsa2048_mod.nx nx_rsa2048_mod_exp.nx nx_rsa2048_mont.nx nx_rsa2048_mont_gate.nx

imports: nx_syscalls.nxnx_u2048.nxnx_u2048_mul.nx

imported by: nx_rsa2048_mod_exp.nxnx_rsa2048_mont.nxnx_rsa2048_mont_gate.nx

structs

none

consts

34const K_MAGIC_2049: i64 = 2049

functions

36func rsa2048_mod(out: *i64, dividend_128: *i64, n: *i64) -> i64
65func rsa2048_mul_mod(out: *i64, a: *i64, b: *i64, n: *i64) -> i64
72func main() -> i64