code wiki / (root) / nx_p256_solinas_difftest.nx

nx_p256_solinas_difftest.nx

buildroot/runtime/nx_p256_solinas_difftest.nx

14053 B456 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tooltopic p256
docsdependenciesstructsconstsfunctions

about

nx_p256_solinas_difftest.nx -- DIFFERENTIAL correctness gate for the NIST P-256 Solinas fast reduction used by TLS ECDSA certificate verify. It proves the FAST Solinas reduction (_p256_solinas_reduce, reached via the public p256_field_reduce_solinas) is BIT-IDENTICAL, in every one of the 8 output limbs, to a trivially-correct bit-serial long-division reduction mod p -- over the FULL 512-bit product domain: * >= 2000 deterministic LCG-random 512-bit products (seeded from the loop index; NO Date.now/random -- the .nx runtime forbids them), and * the exact reduction boundary values: 0, p-1, p, p+1, 2p-1, 2p, 2p+1, 3p, 2^256-1, 2^256, (p-1)^2, p^2, p<<256, 2^512-1, 2^512-2, 2^512-1-p. Plus an end-to-end cross-check: p256_field_mul (fast) == p256_field_mul_slow (the retained bit-serial oracle) over random a,b. WHY THIS MATTERS: this reduction is on the cert-verify hot path (p256_field_mul -> point add/double -> scalar mul -> ECDSA verify). A single wrong reduction could let a FORGED signature verify. The test exits 0 ONLY if EVERY input is bit-identical; any mismatch exits 1. ORACLE INDEPENDENCE: the bit-serial oracle here (_dt_oracle_reduce) shares ZERO code with _p256_solinas_reduce except the prime-constant loader p256_field_load_p (both must reduce mod the same p). It is the SAME algorithm p256_field_mul_slow uses for its reduction step; the end-to-end section cross-checks it against p256_field_mul_slow so a faithful transcription is proven, not assumed. NOTE ON PREMISE: the Solinas reduction ALREADY existed and was ALREADY wired into p256_field_mul before this test (commit "ECDSA-P256 ยง1c"). This organ ADDS a far stronger correctness proof (>= 2000 random + full boundary set) than the pre-existing 606-case oracle test; it modifies no production logic. expect_exit: 0 license_tier: ORIGINAL

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_u256.nx nx_u256_mul.nx nx_p256_field.nx nx_p256_field_mul.nx nx_p256_solinas_difftest.nx

imports: nx_syscalls.nxnx_u256.nxnx_u256_mul.nxnx_p256_field.nxnx_p256_field_mul.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_scratch_save nx_scratch_init sys_mmap u256_alloc nx_scratch nx_scratch_init ↻ nx_scratch_oom sys_write sys_exit sys_mmap ↻ p256_field_load_p u256_wide_alloc nx_scratch ↻ _dt_check_c p256_field_reduce_solinas nx_scratch_save ↻ _p256_solinas_reduce u256_alloc ↻ p256_field_load_p ↻ nx_scratch ↻ _r_reduce9 _r_cmp8 nx_scratch_restore _dt_oracle_reduce nx_scratch_save ↻ u256_wide_alloc ↻ u256_alloc ↻ p256_field_load_p ↻ u256_wide_cmp u256_wide_sub u256_wide_shr_1 nx_scratch_restore ↻ _dt_eq8 _dt_zero16 _dt_copy16 _dt_sub_small _dt_add_small _dt_add16 u256_wide_sub ↻

structs

none

consts

41const K_MAGIC_2500: i64 = 2500
42const K_MAGIC_2654435761: i64 = 2654435761
43const K_MAGIC_1013904223: i64 = 1013904223
44const K_MAGIC_1103515245: i64 = 1103515245
45const K_MAGIC_12345: i64 = 12345
46const K_MAGIC_40503: i64 = 40503

functions

49func _dt_print_dec(n: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
80func _dt_oracle_reduce(out8: *i64, c16: *i64) -> i64
119func _dt_eq8(a: *i64, b: *i64) -> i64
called by 2: _dt_check_cmain
131func _dt_check_c(c16: *i64, fast: *i64, oracle: *i64) -> i64
141func _dt_zero16(c: *i64) -> i64
called by 1: main
150func _dt_copy16(dst: *i64, src: *i64) -> i64
called by 1: main
161func _dt_add16(dst: *i64, src: *i64) -> i64
called by 1: main
174func _dt_add_small(c: *i64, val: i64) -> i64
called by 1: main
192func _dt_sub_small(c: *i64, val: i64) -> i64
called by 1: main
216func main() -> i64