nx_quic_tls_schedule.nx source
↩ module page · 57 lines · 2584 B
1// nx_quic_tls_schedule.nx -- RUNG 6c of the sovereign QUIC transport: the TLS 1.3 key schedule
2// (RFC 8446 sec 7.1) that turns the (EC)DHE shared secret into the handshake + 1-RTT traffic secrets.
3// QUIC reuses TLS 1.3's schedule unchanged; the 1-RTT app secret then feeds R5a's quic key/iv/hp
4// derivation to protect DATAGRAM-carrying packets. Built on the sovereign HKDF (R5a). Gated byte-exact
5// against the RFC 8448 trace. No float. license_tier: ORIGINAL
6import "nx_quic_keys.nx"
7
8// SHA-256 of the empty string (the transcript for Derive-Secret with empty context).
9func tls13_empty_hash(out: *u8) -> i64 {
10 let hex: *u8 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" as *u8
11 var i: i64 = 0
12 while i < 32 {
13 let c1: i64 = hex[i*2] as i64; let c2: i64 = hex[i*2+1] as i64
14 var h1: i64 = 0; if c1 >= 97 { h1 = c1 - 87 } else { h1 = c1 - 48 }
15 var h2: i64 = 0; if c2 >= 97 { h2 = c2 - 87 } else { h2 = c2 - 48 }
16 out[i] = ((h1 << 4) | h2) as u8
17 i = i + 1
18 }
19 return 0
20}
21
22// Early Secret = HKDF-Extract(0, 0^32) (no PSK).
23func tls13_early_secret(out: *u8) -> i64 {
24 let zeros: *u8 = sys_mmap(32)
25 var i: i64 = 0; while i < 32 { zeros[i] = 0; i = i + 1 }
26 hkdf_extract(0 as *u8, 0, zeros, 32, out)
27 return 0
28}
29
30// Derive-Secret(Secret, "derived", "") = HKDF-Expand-Label(Secret, "derived", SHA-256(""), 32).
31func tls13_derived_secret(secret: *u8, out: *u8) -> i64 {
32 let eh: *u8 = sys_mmap(32); tls13_empty_hash(eh)
33 hkdf_expand_label(secret, "derived" as *u8, 7, eh, 32, 32, out)
34 return 0
35}
36
37// Handshake Secret = HKDF-Extract(Derive-Secret(Early,"derived",""), (EC)DHE).
38func tls13_handshake_secret(derived_from_early: *u8, ecdhe: *u8, ecdhe_len: i64, out: *u8) -> i64 {
39 hkdf_extract(derived_from_early, 32, ecdhe, ecdhe_len, out)
40 return 0
41}
42
43// Master Secret = HKDF-Extract(Derive-Secret(Handshake,"derived",""), 0^32).
44func tls13_master_secret(handshake_secret: *u8, out: *u8) -> i64 {
45 let derived: *u8 = sys_mmap(32); tls13_derived_secret(handshake_secret, derived)
46 let zeros: *u8 = sys_mmap(32); var i: i64 = 0; while i < 32 { zeros[i] = 0; i = i + 1 }
47 hkdf_extract(derived, 32, zeros, 32, out)
48 return 0
49}
50
51// a traffic secret: Derive-Secret(secret, label, transcript_hash) = HKDF-Expand-Label(secret, label, th, 32).
52func tls13_traffic_secret(secret: *u8, label: *u8, label_len: i64, transcript_hash: *u8, out: *u8) -> i64 {
53 hkdf_expand_label(secret, label, label_len, transcript_hash, 32, 32, out)
54 return 0
55}
56
57func main() -> i64 { return 0 }