code wiki / (root) / nx_stun.nx

nx_stun.nx

buildroot/runtime/nx_stun.nx

4704 B89 linesdepth 4pulls 4 transitivereach 10 importersview sourcekind librarytopic stun
docsdependenciesstructsconstsfunctions

about

nx_stun.nx -- SOVEREIGN STUN (RFC 5389 / RFC 8489) message codec, NishiLang from the first byte up. This is the FIRST primitive of a Nishi-OS / Nishi-Browser peer-to-peer stack that INTEROPERATES with the real STUN protocol -- so a Nishi endpoint can discover its public reflexive address and NAT-traverse to ANY standard peer -- while using ZERO third-party code. No libjuice, no libwebrtc, no Google STUN client: every byte is ours, emitted in NishiLang, KAT'd byte-exact against the IETF's own RFC 5769 test vectors. Provides the four things a STUN Binding exchange needs: - the 20-byte message header (type, length, magic cookie 0x2112A442, 96-bit transaction id) - XOR-MAPPED-ADDRESS (RFC 5389 15.2) -- the reflexive IP:port a peer learns about itself - FINGERPRINT (15.5) = CRC-32(message) XOR 0x5354554E (integrity/demux; our own CRC-32) - MESSAGE-INTEGRITY (15.4) = HMAC-SHA1(key, message) (auth; composes the sovereign nx_hmac_sha1) KAT: nx_stun_gate proves decode+encode of the RFC 5769 2.2 sample response byte-exact (XOR-MAPPED-ADDRESS -> 192.0.2.1:32853, FINGERPRINT -> 0xB5BE215B, MESSAGE-INTEGRITY matches with the RFC's password), plus a CRC-32 check-value KAT (crc32("123456789")==0xCBF43926). license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_5389 + rfc_5769 (test vectors)

dependencies 2 imports · 4 importers

nx_syscalls.nx nx_hmac_sha1.nx nx_stun.nx nx_ice.nx nx_stun_client.nx nx_stun_gate.nx nx_stun_server.nx

imports: nx_syscalls.nxnx_hmac_sha1.nx

imported by: nx_ice.nxnx_stun_client.nxnx_stun_gate.nxnx_stun_server.nx

structs

none

consts

23const STUN_MAGIC: i64 = 0x2112A442
24const STUN_FP_XOR: i64 = 0x5354554E
25const STUN_BINDING_REQUEST: i64 = 0x0001
26const STUN_BINDING_RESPONSE: i64 = 0x0101
27const STUN_ATTR_XOR_MAPPED_ADDRESS: i64 = 0x0020
28const STUN_ATTR_MESSAGE_INTEGRITY: i64 = 0x0008
29const STUN_ATTR_FINGERPRINT: i64 = 0x8028

functions

32func st_put16(b: *u8, off: i64, v: i64) -> i64 { b[off]=((v>>8)&0xff) as u8; b[off+1]=(v&0xff) as u8; return off+2 }
33func st_put32(b: *u8, off: i64, v: i64) -> i64 { b[off]=((v>>24)&0xff) as u8; b[off+1]=((v>>16)&0xff) as u8; b[off+2]=((v>>8)&0xff) as u8; b[off+3]=(v&0xff) as u8; return off+4 }
34func st_get16(b: *u8, off: i64) -> i64 { return (((b[off] as i64) & 0xff)<<8) | ((b[off+1] as i64) & 0xff) }
35func st_get32(b: *u8, off: i64) -> i64
40func st_write_header(b: *u8, msg_type: i64, msg_len: i64, txid: *u8) -> i64
48func st_type(b: *u8) -> i64 { return st_get16(b, 0) }
49func st_len(b: *u8) -> i64 { return st_get16(b, 2) }
50func st_magic(b: *u8) -> i64 { return st_get32(b, 4) }
called by 4: mainmainss_handlemain calls 1: st_get32
53func st_xma_encode(out: *u8, port: i64, addr: i64) -> i64
62func st_xma_family(val: *u8) -> i64 { return (val[1] as i64) & 0xff }
called by 1: main
63func st_xma_port(val: *u8) -> i64 { return (st_get16(val,2) ^ ((STUN_MAGIC>>16)&0xffff)) & 0xffff }
called by 5: mainsc_querymainmainmain calls 1: st_get16
64func st_xma_addr(val: *u8) -> i64 { return (st_get32(val,4) ^ STUN_MAGIC) & 0xffffffff }
called by 5: mainsc_querymainmainmain calls 1: st_get32
67func nx_crc32(data: *u8, len: i64) -> i64
called by 2: st_fingerprintmain
83func st_fingerprint(msg: *u8, prefix_len: i64) -> i64 { return (nx_crc32(msg, prefix_len) ^ STUN_FP_XOR) & 0xffffffff }
87func st_message_integrity(key: *u8, klen: i64, msg: *u8, prefix_len: i64, out20: *u8) -> i64