code wiki / _hdl_build / nx_tor_cell.nx

nx_tor_cell.nx

buildroot/runtime/_hdl_build/nx_tor_cell.nx

8791 B172 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind librarytopic tor
docsdependenciesstructsconstsfunctions

about

nx_tor_cell.nx -- SOVEREIGN Tor link-protocol CELL codec (tor-spec.txt sec.3 + sec.4 handshake cells). Phase 2 of the anonymizing-transport arc: the byte framing that carries the Tor link handshake (VERSIONS / CERTS / AUTH_CHALLENGE / NETINFO) over the ALREADY-BUILT sovereign TLS 1.3 client (nx_tls13_client_session_run gives the encrypted app-data channel; these cells are its plaintext). Cell shapes (tor-spec sec.3): FIXED-length cell: CircID[CIRCID_LEN] | Command[1] | Payload[509] (512B if CircID=2 [link v<=3], 514B if CircID=4 [link v4+]) VARIABLE-length cell: CircID[CIRCID_LEN] | Command[1] | Length[2] | Payload[Length] VERSIONS (cmd 7) is variable-length and ALWAYS uses a 2-byte CircID (sent before version negotiation). HONEST SCOPE: this is the CELL FRAMING (encode/decode), gated byte-exact vs the spec layout. It is NOT a live Tor connection (no relay reachable; zero external calls). anon_is_anonymizing() stays 0. Sovereign: nx_syscalls only (pure byte codec). license_tier: ORIGINAL

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_tor_cell.nx nx_tor_cell_gate.nx nx_tor_relay.nx nx_tor_relay_gate.nx

imports: nx_syscalls.nx

imported by: nx_tor_cell_gate.nxnx_tor_relay.nxnx_tor_relay_gate.nx

structs

none

consts

18const TCELL_PADDING: i64 = 0
19const TCELL_CREATE: i64 = 1
20const TCELL_CREATED: i64 = 2
21const TCELL_RELAY: i64 = 3
22const TCELL_DESTROY: i64 = 4
23const TCELL_CREATE_FAST: i64 = 5
24const TCELL_CREATED_FAST: i64 = 6
25const TCELL_VERSIONS: i64 = 7 // variable-length; CircID always 2 bytes
26const TCELL_NETINFO: i64 = 8 // fixed-length
27const TCELL_RELAY_EARLY: i64 = 9
28const TCELL_CREATE2: i64 = 10 // ntor onion skin rides here (Phase 3)
29const TCELL_CREATED2: i64 = 11
30const TCELL_VPADDING: i64 = 128 // variable-length
31const TCELL_CERTS: i64 = 129 // variable-length
32const TCELL_AUTH_CHALLENGE: i64 = 130 // variable-length
33const TCELL_AUTHENTICATE: i64 = 131 // variable-length
35const TCELL_PAYLOAD_LEN: i64 = 509 // fixed-cell payload is always 509 bytes (tor-spec sec.3)
36const TCELL_NETINFO_ATYPE_IPV4: i64 = 4
37const TCELL_NETINFO_ATYPE_IPV6: i64 = 6
39const TCELL_E_SHORT: i64 = 0 - 1 // buffer shorter than the declared/required length
40const TCELL_E_CMD: i64 = 0 - 2 // unexpected command
41const TCELL_E_FORMAT: i64 = 0 - 3 // malformed field (odd length, overrun, ...)

functions

44func tc_put_u16(buf: *u8, off: i64, v: i64) -> i64 { buf[off]=((v>>8)&0xff) as u8; buf[off+1]=(v&0xff) as u8; return off+2 }
45func tc_put_u32(buf: *u8, off: i64, v: i64) -> i64 { buf[off]=((v>>24)&0xff) as u8; buf[off+1]=((v>>16)&0xff) as u8; buf[off+2]=((v>>8)&0xff) as u8; buf[off+3]=(v&0xff) as u8; return off+4 }
46func tc_get_u16(buf: *u8, off: i64) -> i64 { return ((buf[off] as i64)<<8) | (buf[off+1] as i64) }
47func tc_get_u32(buf: *u8, off: i64) -> i64 { return ((buf[off] as i64)<<24)|((buf[off+1] as i64)<<16)|((buf[off+2] as i64)<<8)|(buf[off+3] as i64) }
called by 1: tc_parse_netinfo
50func tc_circid_len(link_version: i64) -> i64 { if link_version >= 4 { return 4 } return 2 }
55func tc_build_fixed(circid: i64, cmd: i64, payload: *u8, paylen: i64, circid_len: i64, out: *u8) -> i64
66func tc_build_var(circid: i64, cmd: i64, payload: *u8, paylen: i64, circid_len: i64, out: *u8) -> i64
78func tc_parse_var(buf: *u8, buflen: i64, circid_len: i64, out_cmd: *i64, out_ploff: *i64, out_plen: *i64) -> i64
called by 1: main calls 1: tc_get_u16
91func tc_build_versions(vers: *i64, n: i64, out: *u8) -> i64
called by 1: main calls 3: sys_mmaptc_put_u16tc_build_var
99func tc_parse_versions(buf: *u8, buflen: i64, out_vers: *i64, max: i64) -> i64
called by 1: main calls 1: tc_get_u16
112func tc_negotiate_version(a: *i64, na: i64, b: *i64, nb: i64) -> i64
called by 1: main
120func tc_build_netinfo(circid_len: i64, timestamp: i64, other_ip4: *u8, out: *u8) -> i64
132func tc_parse_netinfo(pl: *u8, pllen: i64, out_ts: *i64, out_atype: *i64, out_addr: *u8, out_alen: *i64) -> i64
called by 1: main calls 1: tc_get_u32
146func tc_parse_certs(pl: *u8, pllen: i64, out_types: *i64, out_lens: *i64, max: i64) -> i64
called by 1: main calls 1: tc_get_u16
163func tc_parse_auth_challenge(pl: *u8, pllen: i64, out_chal32: *u8, out_methods: *i64, max: i64) -> i64
called by 1: main calls 1: tc_get_u16