code wiki / _hdl_build / nx_u2048_millerrabin.nx
nx_u2048_millerrabin.nx
buildroot/runtime/_hdl_build/nx_u2048_millerrabin.nx
about
nx_u2048_millerrabin.nx -- F103e RUNG 5: probabilistic primality over u2048.
The gate for RSA KEYGEN, which is the gate for signing, which is the gate for enrolling our own
Secure Boot key (debt 1786237435: real EDK2 with MS keys refuses our unsigned .efi; the SAME
secboot firmware in SETUP mode runs it, so the blocker is the enrolled key set).
Unblocked by nx_rsa2048_mod_exp_big: Miller-Rabin needs a^d mod n with d ~1024 bits, and the
estate's incumbent modexp takes the exponent as an i64 -- it structurally could not do this.
★NO RECALLED CONSTANTS. Every fixture's primality is established IN-TEST by independent i64 trial
division; the u2048 Miller-Rabin path is then required to agree. Two methods, one answer. An RSA
modulus recited from memory would be a fabricated constant, which is exactly what the estate's
rules forbid -- so the key gets GENERATED (next rung), never quoted.
★THE ANTI-VACUITY TOOTH IS THE CARMICHAEL FAMILY. 561 = 3*11*17, 1105 = 5*13*17, 1729 = 7*13*19 --
built here AS PRODUCTS, so their compositeness is proven by construction rather than remembered.
They satisfy the FERMAT test for every coprime base, so an implementation that computed
a^(n-1) mod n instead of doing the square-root descent passes every other test in this file and
fails only these. ★★★★★★A WEAKER ALGORITHM WEARING THE RIGHT NAME PASSES EVERY TEST EXCEPT THE
ONE THAT WAS DESIGNED TO SEPARATE THEM.
★AND ONE TOOTH PROVES THE BASE LOOP MATTERS: 23*89 = 2047 is a strong pseudoprime to base 2, so
MR with bases {2} must report PROBABLY-PRIME (wrong, and expected) while {2,3} reports COMPOSITE.
Without this, a single-base implementation would look perfect.
Usage: nx_u2048_millerrabin selftest
Exit: 0 GREEN | 1 RED. Log -> knowledge/status/nishi_os.log, verdict= LAST.
license_tier: ORIGINAL
dependencies 6 imports · 5 importers
imports: nx_syscalls.nxnx_u2048.nxnx_u2048_mul.nxnx_rsa2048_mod.nxnx_rsa2048_mod_exp.nxnx_rsa2048_mod_exp_big.nx
imported by: nx_authenticode_sign.nxnx_efivars_enrol.nxnx_rsa_keygen.nxnx_rsa_pkcs1_sign.nxnx_x509_emit.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 34 | const MR_MAGIC_2048: i64 = 2048 |
| 35 | const MR_MAGIC_1105: i64 = 1105 |
| 36 | const MR_MAGIC_1729: i64 = 1729 |
| 37 | const MR_MAGIC_2465: i64 = 2465 |
| 38 | const MR_MAGIC_2821: i64 = 2821 |
| 39 | const MR_MAGIC_2147483647: i64 = 2147483647 |
| 40 | const MR_MAGIC_65521: i64 = 65521 |
| 41 | const MR_MAGIC_65519: i64 = 65519 |
| 43 | const MR_SWEEP_HI: i64 = 512 // EXHAUSTIVE over [2, MR_SWEEP_HI]; traps beyond are named |
functions
| 45 | func mr_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 46 | func mr_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 } |
| 47 | func mr_fn(fd: i64, v: i64) -> i64 |
| 58 | func mr_set_i64(x: *i64, v: i64) -> i64 |
| 69 | func mr_i64_is_prime(v: i64) -> i64 called by 1: mr_selftest |
| 82 | func u2048_is_probable_prime(n: *i64, bases: *i64, nbases: i64) -> i64 |
| 135 | func mr_selftest() -> i64 called by 1: main calls 11: u2048_allocsys_mmapmr_set_i64u2048_is_probable_primemr_i64_is_primemr_p+5 |
| 247 | func main(argc: i64, argv: *i64) -> i64 calls 1: mr_selftest |