code wiki / (root) / nx_tls13_record.nx

nx_tls13_record.nx

buildroot/runtime/nx_tls13_record.nx

15031 B380 linesdepth 6pulls 13 transitivereach 571 importersview sourcekind librarytopic tls13
docsdependenciesstructsconstsfunctions

about

nx_tls13_record.nx -- TLS 1.3 record-layer protection (RFC 8446 §5.2). Phase 0b §K of the Nishi TLS 1.3 stack per docs/NISHI_TLS13_GAP_AUDIT.md. The bridge between the shipped ChaCha20-Poly1305 AEAD primitive and the actual TLS wire format. Every encrypted record on a TLS 1.3 connection -- handshake or application data, in either direction -- flows through this. Record wire format (RFC 8446 §5.1, §5.2): struct { ContentType type = 23; // application_data wrapper ProtocolVersion legacy_version = 0x0303; uint16 length; // total of AEAD output opaque encrypted_record[length]; // AEAD output (CT || tag) } TLSCiphertext; Inner plaintext (what AEAD encrypts): struct { opaque content[TLSPlaintext.length]; ContentType type; // the REAL content type uint8 zeros[padding_length]; // optional padding } TLSInnerPlaintext; Nonce construction (RFC 8446 §5.3): nonce = pad_left(seq_num, iv_len) XOR static_iv where static_iv is the per-direction traffic_iv derived from nx_tls13_schedule. seq_num is a 64-bit counter; for IV length 12 (ChaCha20-Poly1305 + AES-GCM), the left-pad is 4 zero bytes. AAD construction (RFC 8446 §5.2): additional_data = TLSCiphertext header (the 5 bytes: type + legacy_version + length) What it does today: - encrypt: construct inner plaintext, derive nonce, encrypt+tag

dependencies 4 imports · 52 importers

nx_syscalls.nx nx_chacha20_poly1305.nx nx_aes128_gcm.nx nx_aes256_gcm.nx nx_tls13_record.nx nx_dev_api_build_probe.nx nx_edge_daemon.nx nx_edge_serve_static_test.nx nx_h2_client_over_tls.nx nx_https_get_complete.nx nx_https_get_happy_test.nx nx_https_get_spoof.nx nx_https_get_stream.nx nx_https_ka_probe.nx nx_https_loopback_test.nx

diagram shows first 10 each side; +0 more imports, +42 more importers in the complete lists below.

imports: nx_syscalls.nxnx_chacha20_poly1305.nxnx_aes128_gcm.nxnx_aes256_gcm.nx

imported by: nx_dev_api_build_probe.nxnx_edge_daemon.nxnx_edge_serve_static_test.nxnx_h2_client_over_tls.nxnx_https_get_complete.nxnx_https_get_happy_test.nxnx_https_get_spoof.nxnx_https_get_stream.nxnx_https_ka_probe.nxnx_https_loopback_test.nxnx_https_post_complete.nxnx_lib_fetch_cookie.nxnx_login_e2e_probe.nxnx_mcp_call.nxnx_mgmt_client.nxnx_pages_https_daemon.nxnx_porkbun_ping_probe.nxnx_research_ka.nxnx_sites_sni_cert_gate.nxnx_sovgit_push.nxnx_tls13_aead1302_gate.nxnx_tls13_aead_record_tcp_test.nxnx_tls13_app_send_fd.nxnx_tls13_client_h2run.nxnx_tls13_client_session_emit_finished.nxnx_tls13_client_session_recv_hs.nxnx_tls13_client_session_run.nxnx_tls13_client_test.nxnx_tls13_full_tcp_test.nxnx_tls13_handshake_io.nxnx_tls13_mtls_finished.nxnx_tls13_mtls_recv_cert.nxnx_tls13_read_record_from_fd.nxnx_tls13_record_test.nxnx_tls13_server_full_handshake_test.nxnx_tls13_server_recv_client_cert.nxnx_tls13_server_recv_client_cv.nxnx_tls13_server_session_app_data.nxnx_tls13_server_session_app_data_test.nxnx_tls13_server_session_emit_certificate.nxnx_tls13_server_session_emit_certreq.nxnx_tls13_server_session_emit_cv.nxnx_tls13_server_session_emit_ee.nxnx_tls13_server_session_emit_ee_alpn.nxnx_tls13_server_session_emit_sf.nxnx_tls13_server_session_recv_cf.nxnx_tls13_server_session_recv_cf_test.nxnx_tls13_server_session_run.nxnx_tls13_server_session_run_h2.nxnx_tls13_server_session_run_mtls.nxnx_tls13_sh_probe_test.nxnx_video_get.nx

structs

none

consts

88const NX_TLS13_RECORD_IV_LEN: i64 = 12
89const NX_TLS13_RECORD_TAG_LEN: i64 = 16
90const NX_TLS13_RECORD_HEADER_LEN: i64 = 5 // TLSCiphertext header
96const NX_TLS13_MAX_INNER_PLAINTEXT: i64 = 16385 // 2^14 + 1
97const NX_TLS13_MAX_RECORD_PAYLOAD: i64 = 16640 // 2^14 + 256
100const NX_TLS13_CT_INVALID: i64 = 0
101const NX_TLS13_CT_CHANGE_CIPHER_SPEC: i64 = 20
102const NX_TLS13_CT_ALERT: i64 = 21
103const NX_TLS13_CT_HANDSHAKE: i64 = 22
104const NX_TLS13_CT_APPLICATION_DATA: i64 = 23
106const NX_TLS13_LEGACY_VERSION: i64 = 0x0303
109const NX_TLS13_REC_VERDICT_OK: i64 = 1
110const NX_TLS13_REC_VERDICT_TAG_MISMATCH: i64 = 2
111const NX_TLS13_REC_VERDICT_BAD_PADDING: i64 = 3
112const NX_TLS13_REC_VERDICT_EMPTY_INNER: i64 = 4
113const NX_TLS13_REC_VERDICT_TOO_LONG: i64 = 5
114const NX_TLS13_REC_VERDICT_TOO_SHORT: i64 = 6
115const NX_TLS13_REC_VERDICT_N: i64 = 7

functions

123func tls13_record_build_nonce(static_iv: *u8, seq: i64, nonce_out: *u8) -> i64
142func tls13_record_write_header(header_out: *u8, total_len: i64) -> i64
172func tls13_record_aead_seal(cipher_suite: i64,
205func tls13_record_aead_open(cipher_suite: i64,
236func nx_tls13_record_encrypt_v2(
277func nx_tls13_record_encrypt(
308func nx_tls13_record_decrypt_v2(
359func nx_tls13_record_decrypt(
376func nx_tls13_rec_verdict_is_valid(v: i64) -> i64
called by 1: main