code wiki / _hdl_build / nx_rsa2048_mod_exp_big.nx
nx_rsa2048_mod_exp_big.nx
buildroot/runtime/_hdl_build/nx_rsa2048_mod_exp_big.nx
about
nx_rsa2048_mod_exp_big.nx -- F103e RUNG 4: modular exponentiation with a FULL-WIDTH exponent.
THE GAP, found by reading the signature rather than the filename: the estate's
`rsa2048_mod_exp(out, s, e: i64, n)` takes the exponent as an **i64**, and its own header says so
plainly -- "e fits in i64 (true for all Web PKI: e is either 3, 17, 65537)". That is correct and
sufficient for VERIFICATION, where the public exponent is tiny. It is structurally unable to do
either of the two things F103e needs next:
* RSA SIGNING: s = m^d mod n, where the private exponent d is ~2048 bits.
* MILLER-RABIN: a^d mod n, where d = (n-1)/2^r is ~1024 bits -- i.e. RSA KEYGEN.
★★★★★★A LIBRARY NAMED FOR AN OPERATION MAY IMPLEMENT ONLY THE DIRECTION ITS AUTHOR NEEDED.
"The estate has RSA" was true and useless; it has RSA-verify. The symbol table said i64 and the
filename did not.
This is the same square-and-multiply as the incumbent, MSB-first, but walking the bits of a u2048
exponent instead of an i64. It deliberately does NOT re-implement the modular multiply -- it calls
the SAME `rsa2048_mul_mod` the incumbent calls, so there is exactly one modmul in the estate.
★THE ORACLE IS THE INCUMBENT: for every exponent that fits in an i64, this function must agree with
`rsa2048_mod_exp` BIT FOR BIT. The teeth check e = 3, 17, 65537 and 2^63-1 against it, then
exercise an exponent NO i64 can hold -- the case that motivated the organ and the one the
incumbent cannot answer, so it is reported as EXERCISED rather than cross-checked.
Usage: nx_rsa2048_mod_exp_big selftest
Exit: 0 GREEN | 1 RED. Log -> knowledge/status/nishi_os.log, verdict= LAST.
license_tier: ORIGINAL
dependencies 5 imports · 6 importers
imports: nx_syscalls.nxnx_u2048.nxnx_u2048_mul.nxnx_rsa2048_mod.nxnx_rsa2048_mod_exp.nx
imported by: nx_authenticode_sign.nxnx_efivars_enrol.nxnx_rsa_keygen.nxnx_rsa_pkcs1_sign.nxnx_u2048_millerrabin.nxnx_x509_emit.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 31 | const MEB_MAGIC_65537: i64 = 65537 |
| 32 | const MEB_MAGIC_9223372036854775807: i64 = 9223372036854775807 |
| 34 | const MEB_OK: i64 = 1 |
| 35 | const MEB_S_OUT_OF_RANGE: i64 = 2 |
| 36 | const MEB_BITS: i64 = 2048 |
functions
| 38 | func meb_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 39 | func meb_fp(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } |
| 40 | func meb_fn(fd: i64, v: i64) -> i64 |
| 53 | func meb_highbit(e: *i64) -> i64 |
| 63 | func rsa2048_mod_exp_big(out: *i64, s: *i64, e: *i64, n: *i64) -> i64 |
| 86 | func meb_set_i64(x: *i64, v: i64) -> i64 |
| 96 | func meb_selftest() -> i64 called by 1: main calls 17: u2048_allocsys_mmapu2048_load_bersa2048_mod_expmeb_set_i64rsa2048_mod_exp_big+11 |
| 211 | func main(argc: i64, argv: *i64) -> i64 calls 1: meb_selftest |