code wiki / _hdl_build / nx_quic_tls_schedule_test.nx
nx_quic_tls_schedule_test.nx source
↩ module page · 45 lines · 2889 B
1// nx_quic_tls_schedule_test.nx -- RUNG 6c gate: TLS 1.3 key schedule byte-exact vs the RFC 8448 trace
2// (early -> derived -> handshake secret). This is the schedule QUIC reuses to make the 1-RTT keys that
3// protect DATAGRAM-carrying packets. Native, sovereign, on our own HKDF. Prints computed values for audit.
4// license_tier: ORIGINAL
5import "nx_quic_tls_schedule.nx"
6import "nx_g_pn_lite_lib.nx"
7import "nx_g_check_lib.nx"
8import "nx_g_puts_lib.nx"
9
10func hexnib(c: i64) -> i64 { if c>=48 { if c<=57 { return c-48 } } if c>=97 { if c<=102 { return c-87 } } return 0 }
11func set_hex(out: *u8, hex: *u8, nbytes: i64) -> i64 { var i: i64=0; while i<nbytes { out[i]=((hexnib(hex[i*2] as i64)<<4)|hexnib(hex[i*2+1] as i64)) as u8; i=i+1 } return 0 }
12func eq(a: *u8, b: *u8, n: i64) -> i64 { var i: i64=0; while i<n { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
13func phex(label: *u8, b: *u8, n: i64) -> i64 {
14 let h: *u8 = "0123456789abcdef" as *u8
15 g_puts(" "); g_puts(label); g_puts(" = ")
16 var i: i64=0
17 while i<n { let o: *u8=sys_mmap(2); o[0]=h[(b[i] as i64 >> 4) & 0xf]; o[1]=h[(b[i] as i64) & 0xf]; sys_write(1,o,2); i=i+1 }
18 g_puts("\n"); return 0
19}
20
21func main() -> i64 {
22 g_puts("nx_quic_tls_schedule gate -- TLS 1.3 key schedule vs RFC 8448 trace\n" as *u8)
23 var pass: i64=0; var total: i64=0
24
25 let es: *u8 = sys_mmap(32); tls13_early_secret(es)
26 let exp_es: *u8 = sys_mmap(32); set_hex(exp_es, "33ad0a1c607ec03b09e6cd9893680ce210adf300aa1f2660e1b22e10f170f92a" as *u8, 32)
27 phex("early_secret " as *u8, es, 32)
28 pass = pass + g_check("Early Secret = HKDF-Extract(0,0^32) == 33ad0a1c... (RFC 8448)" as *u8, eq(es, exp_es, 32)); total=total+1
29
30 let dv: *u8 = sys_mmap(32); tls13_derived_secret(es, dv)
31 let exp_dv: *u8 = sys_mmap(32); set_hex(exp_dv, "6f2615a108c702c5678f54fc9dbab69716c076189c48250cebeac3576c3611ba" as *u8, 32)
32 phex("derived " as *u8, dv, 32)
33 pass = pass + g_check("Derive-Secret(early,'derived','') == 6f2615a1... (RFC 8448)" as *u8, eq(dv, exp_dv, 32)); total=total+1
34
35 let ecdhe: *u8 = sys_mmap(32); set_hex(ecdhe, "8bd4054fb55b9d63fdfbacf9f04b9f0d35e6d63f537563efd46272900f89492d" as *u8, 32)
36 let hs: *u8 = sys_mmap(32); tls13_handshake_secret(dv, ecdhe, 32, hs)
37 let exp_hs: *u8 = sys_mmap(32); set_hex(exp_hs, "1dc826e93606aa6fdc0aadc12f741b01046aa6b99f691ed221a9f0ca043fbeac" as *u8, 32)
38 phex("handshake_sec " as *u8, hs, 32)
39 pass = pass + g_check("Handshake Secret = HKDF-Extract(derived,ECDHE) == 1dc826e9... (RFC 8448)" as *u8, eq(hs, exp_hs, 32)); total=total+1
40
41 g_puts("---- quic_tls_schedule gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
42 if pass == total { g_puts("VERDICT: GREEN (TLS 1.3 key schedule, RFC 8448 byte-exact, sovereign HKDF)\n" as *u8); return 0 }
43 g_puts("VERDICT: RED\n" as *u8)
44 return 1
45}