nx_media_crypt.nx
buildroot/runtime/nx_media_crypt.nx
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
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
| 13 | const MC_SCRATCH: i64 = 320 // mc_xform working set: s(128) + w(128) + keystream(64) |
functions
| 15 | func mc_rotl(x: i64, n: i64) -> i64 { return ((x << n) | (x >> (32 - n))) & 0xffffffff } called by 1: mc_qr |
| 16 | func mc_u32le(b: *u8, o: i64) -> i64 called by 1: mc_block |
| 18 | func mc_wr32le(b: *u8, o: i64, v: i64) -> i64 called by 1: mc_block |
| 25 | func mc_qr(w: *i64, a: i64, b: i64, c: i64, d: i64) -> i64 |
| 32 | func mc_block(key32: *u8, nonce12: *u8, counter: i64, out64: *u8, s: *i64, w: *i64) -> i64 |
| 53 | func mc_xform(key32: *u8, nonce12: *u8, ctr0: i64, data: *u8, len: i64, scratch: *u8) -> i64 |
| 71 | func mc_hexval(c: i64) -> i64 |
| 76 | func mc_key(hexk: *u8, hlen: i64, out32: *u8) -> i64 |
| 90 | func mc_nonce(sender: *u8, fctr: i64, out: *u8) -> i64 |