nx_p256_solinas_difftest.nx
buildroot/runtime/nx_p256_solinas_difftest.nx
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
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
structs
| none |
consts
| 41 | const K_MAGIC_2500: i64 = 2500 |
| 42 | const K_MAGIC_2654435761: i64 = 2654435761 |
| 43 | const K_MAGIC_1013904223: i64 = 1013904223 |
| 44 | const K_MAGIC_1103515245: i64 = 1103515245 |
| 45 | const K_MAGIC_12345: i64 = 12345 |
| 46 | const K_MAGIC_40503: i64 = 40503 |
functions
| 49 | func _dt_print_dec(n: i64) -> i64 |
| 80 | func _dt_oracle_reduce(out8: *i64, c16: *i64) -> i64 called by 2: _dt_check_cmain calls 8: nx_scratch_saveu256_wide_allocu256_allocp256_field_load_pu256_wide_cmpu256_wide_sub+2 |
| 119 | func _dt_eq8(a: *i64, b: *i64) -> i64 |
| 131 | func _dt_check_c(c16: *i64, fast: *i64, oracle: *i64) -> i64 |
| 141 | func _dt_zero16(c: *i64) -> i64 called by 1: main |
| 150 | func _dt_copy16(dst: *i64, src: *i64) -> i64 called by 1: main |
| 161 | func _dt_add16(dst: *i64, src: *i64) -> i64 called by 1: main |
| 174 | func _dt_add_small(c: *i64, val: i64) -> i64 called by 1: main |
| 192 | func _dt_sub_small(c: *i64, val: i64) -> i64 called by 1: main |
| 216 | func main() -> i64 |