code wiki / _hdl_build / nx_u2048_millerrabin.nx

nx_u2048_millerrabin.nx

buildroot/runtime/_hdl_build/nx_u2048_millerrabin.nx

11421 B249 linesdepth 7pulls 7 transitivereach 5 importersview sourcekind tooltopic u2048
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_u2048.nx nx_u2048_mul.nx nx_rsa2048_mod.nx nx_rsa2048_mod_exp.nx nx_rsa2048_mod_exp_big.nx nx_u2048_millerrabin.nx nx_authenticode_sign.nx nx_efivars_enrol.nx nx_rsa_keygen.nx nx_rsa_pkcs1_sign.nx nx_x509_emit.nx

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

main mr_selftest u2048_alloc sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_mmap ↻ mr_set_i64 sys_mmap ↻ u2048_load_be u2048_is_probable_prime u2048_alloc ↻ mr_set_i64 ↻ u2048_cmp u2048_get_bit u2048_one u2048_zero u2048_sub_with_borrow u2048_copy u2048_shr1 rsa2048_mod_exp_big u2048_cmp ↻ meb_highbit u2048_get_bit ↻ u2048_one ↻ u2048_alloc ↻ u2048_copy ↻ rsa2048_mul_mod

structs

none

consts

34const MR_MAGIC_2048: i64 = 2048
35const MR_MAGIC_1105: i64 = 1105
36const MR_MAGIC_1729: i64 = 1729
37const MR_MAGIC_2465: i64 = 2465
38const MR_MAGIC_2821: i64 = 2821
39const MR_MAGIC_2147483647: i64 = 2147483647
40const MR_MAGIC_65521: i64 = 65521
41const MR_MAGIC_65519: i64 = 65519
43const MR_SWEEP_HI: i64 = 512 // EXHAUSTIVE over [2, MR_SWEEP_HI]; traps beyond are named

functions

45func 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 }
called by 1: mr_selftest calls 1: sys_write
46func 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 }
called by 1: mr_selftest calls 1: sys_write
47func mr_fn(fd: i64, v: i64) -> i64
called by 1: mr_selftest calls 2: sys_mmapsys_write
58func mr_set_i64(x: *i64, v: i64) -> i64
69func mr_i64_is_prime(v: i64) -> i64
called by 1: mr_selftest
82func u2048_is_probable_prime(n: *i64, bases: *i64, nbases: i64) -> i64
135func mr_selftest() -> i64
247func main(argc: i64, argv: *i64) -> i64
calls 1: mr_selftest