nx_rsa4096_mod.nx
buildroot/runtime/nx_rsa4096_mod.nx
about
nx_rsa4096_mod.nx -- bit-by-bit reduction mod 4096-bit modulus.
Given an 8192-bit dividend (in a 256-limb wide buffer) and a
4096-bit modulus n (in a 128-limb u4096 buffer with the top bit
set), compute the 4096-bit remainder.
Mirrors nx_rsa2048_mod with bit-width doubled (8191 iterations
instead of 4095; reduction takes ~4x more limb operations).
Algorithm (shift-and-subtract, MSB-first):
rem = 0 (u4096; one extra "carry" bit kept separately)
for i in 8191 down to 0:
rem = (rem << 1) | bit_i(dividend)
if (carry from shift) OR (rem >= n): rem -= n
return rem
O(8192 * 128) limb operations ~= O(1M) per reduction. Combined
with 17 squarings/mul for RSA verify (e=65537), one verify is
~17M limb ops -- ~10-20 seconds in qemu-riscv64.
API:
rsa4096_mod(out_128, dividend_256, n_128) -- out = dividend mod n
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/ietf/rfc_8017
lineage_id: nishi_rsa4096_mod_q1
dependencies 3 imports · 3 importers
imports: nx_syscalls.nxnx_u4096.nxnx_u4096_mul.nx
imported by: nx_rsa4096_mod_exp.nxnx_rsa4096_mod_test.nxnx_rsa4096_mont.nx
structs
| none |
consts
| 31 | const K_MAGIC_4097: i64 = 4097 |
functions
| 33 | func rsa4096_mod(out: *i64, dividend_256: *i64, n: *i64) -> i64 |
| 62 | func rsa4096_mul_mod(out: *i64, a: *i64, b: *i64, n: *i64) -> i64 |
| 69 | func main() -> i64 |