code wiki / _hdl_build / nx_tor_cell.nx
nx_tor_cell.nx
buildroot/runtime/_hdl_build/nx_tor_cell.nx
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
imports: nx_syscalls.nx
imported by: nx_tor_cell_gate.nxnx_tor_relay.nxnx_tor_relay_gate.nx
structs
| none |
consts
| 18 | const TCELL_PADDING: i64 = 0 |
| 19 | const TCELL_CREATE: i64 = 1 |
| 20 | const TCELL_CREATED: i64 = 2 |
| 21 | const TCELL_RELAY: i64 = 3 |
| 22 | const TCELL_DESTROY: i64 = 4 |
| 23 | const TCELL_CREATE_FAST: i64 = 5 |
| 24 | const TCELL_CREATED_FAST: i64 = 6 |
| 25 | const TCELL_VERSIONS: i64 = 7 // variable-length; CircID always 2 bytes |
| 26 | const TCELL_NETINFO: i64 = 8 // fixed-length |
| 27 | const TCELL_RELAY_EARLY: i64 = 9 |
| 28 | const TCELL_CREATE2: i64 = 10 // ntor onion skin rides here (Phase 3) |
| 29 | const TCELL_CREATED2: i64 = 11 |
| 30 | const TCELL_VPADDING: i64 = 128 // variable-length |
| 31 | const TCELL_CERTS: i64 = 129 // variable-length |
| 32 | const TCELL_AUTH_CHALLENGE: i64 = 130 // variable-length |
| 33 | const TCELL_AUTHENTICATE: i64 = 131 // variable-length |
| 35 | const TCELL_PAYLOAD_LEN: i64 = 509 // fixed-cell payload is always 509 bytes (tor-spec sec.3) |
| 36 | const TCELL_NETINFO_ATYPE_IPV4: i64 = 4 |
| 37 | const TCELL_NETINFO_ATYPE_IPV6: i64 = 6 |
| 39 | const TCELL_E_SHORT: i64 = 0 - 1 // buffer shorter than the declared/required length |
| 40 | const TCELL_E_CMD: i64 = 0 - 2 // unexpected command |
| 41 | const TCELL_E_FORMAT: i64 = 0 - 3 // malformed field (odd length, overrun, ...) |
functions
| 44 | func 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 } |
| 45 | func 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 } |
| 46 | func tc_get_u16(buf: *u8, off: i64) -> i64 { return ((buf[off] as i64)<<8) | (buf[off+1] as i64) } |
| 47 | func 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 |
| 50 | func tc_circid_len(link_version: i64) -> i64 { if link_version >= 4 { return 4 } return 2 } |
| 55 | func tc_build_fixed(circid: i64, cmd: i64, payload: *u8, paylen: i64, circid_len: i64, out: *u8) -> i64 |
| 66 | func tc_build_var(circid: i64, cmd: i64, payload: *u8, paylen: i64, circid_len: i64, out: *u8) -> i64 |
| 78 | func tc_parse_var(buf: *u8, buflen: i64, circid_len: i64, out_cmd: *i64, out_ploff: *i64, out_plen: *i64) -> i64 |
| 91 | func tc_build_versions(vers: *i64, n: i64, out: *u8) -> i64 |
| 99 | func tc_parse_versions(buf: *u8, buflen: i64, out_vers: *i64, max: i64) -> i64 |
| 112 | func tc_negotiate_version(a: *i64, na: i64, b: *i64, nb: i64) -> i64 called by 1: main |
| 120 | func tc_build_netinfo(circid_len: i64, timestamp: i64, other_ip4: *u8, out: *u8) -> i64 |
| 132 | func tc_parse_netinfo(pl: *u8, pllen: i64, out_ts: *i64, out_atype: *i64, out_addr: *u8, out_alen: *i64) -> i64 |
| 146 | func tc_parse_certs(pl: *u8, pllen: i64, out_types: *i64, out_lens: *i64, max: i64) -> i64 |
| 163 | func tc_parse_auth_challenge(pl: *u8, pllen: i64, out_chal32: *u8, out_methods: *i64, max: i64) -> i64 |