code wiki / (root) / nx_media_crypt.nx

nx_media_crypt.nx

buildroot/runtime/nx_media_crypt.nx

5108 B97 linesdepth 2pulls 2 transitivereach 4 importersview sourcekind librarytopic media
docsdependenciesstructsconstsfunctions

about

nx_media_crypt.nx -- SOVEREIGN E2EE media cipher = ChaCha20 (RFC 8439), pure Nishi. Chosen over a hash-CTR construction because ChaCha20 is (a) a NAMED SOTA stream cipher (TLS 1.3, WireGuard, SFrame- adjacent), (b) KAT-verifiable against RFC 8439 test vectors, and (c) WASM-VIABLE by construction -- flat 16 x u32 state, only add/xor/rotate, NO sha256, NO struct-pointer alloca (the pattern the WAT backend can't yet lower; see nx_sha256_wasm.nx). Same SSOT compiles native (this gate) + into the client. E2EE role: block counter + nonce make each frame's keystream unique WITHOUT reusing the wire seq (which the SFU rewrites). LENGTH-PRESERVING (XOR) -> the relay's dominant-speaker byte-energy still works and the wire is unchanged. The 32-byte key is the invite link's #e= fragment (hash = never sent to a server; relay has room_secret but not e2ee_secret -> cannot derive it -> genuinely relay-blind). license_tier: ORIGINAL

dependencies 1 imports · 4 importers

nx_syscalls.nx nx_media_crypt.nx nx_connect_e2e_proof.nx nx_media_crypt_gate.nx nx_media_crypt_wasm.nx nx_media_crypt_wasm_gate.nx

imports: nx_syscalls.nx

imported by: nx_connect_e2e_proof.nxnx_media_crypt_gate.nxnx_media_crypt_wasm.nxnx_media_crypt_wasm_gate.nx

structs

none

consts

13const MC_SCRATCH: i64 = 320 // mc_xform working set: s(128) + w(128) + keystream(64)

functions

15func mc_rotl(x: i64, n: i64) -> i64 { return ((x << n) | (x >> (32 - n))) & 0xffffffff }
called by 1: mc_qr
16func mc_u32le(b: *u8, o: i64) -> i64
called by 1: mc_block
18func mc_wr32le(b: *u8, o: i64, v: i64) -> i64
called by 1: mc_block
25func mc_qr(w: *i64, a: i64, b: i64, c: i64, d: i64) -> i64
called by 1: mc_block calls 1: mc_rotl
32func mc_block(key32: *u8, nonce12: *u8, counter: i64, out64: *u8, s: *i64, w: *i64) -> i64
called by 2: mc_xformmain calls 3: mc_u32lemc_qrmc_wr32le
53func mc_xform(key32: *u8, nonce12: *u8, ctr0: i64, data: *u8, len: i64, scratch: *u8) -> i64
called by 3: mainmainmcw_xform calls 1: mc_block
71func mc_hexval(c: i64) -> i64
76func mc_key(hexk: *u8, hlen: i64, out32: *u8) -> i64
called by 3: mainmainmcw_key calls 1: mc_hexval
90func mc_nonce(sender: *u8, fctr: i64, out: *u8) -> i64
called by 3: mainmainmcw_nonce