code wiki / (root) / nx_media_crypt_wasm.nx

nx_media_crypt_wasm.nx source

↩ module page · 14 lines · 1035 B

1// nx_media_crypt_wasm.nx -- WASM-target entry wrappers for the ChaCha20 cipher (nx_media_crypt). The WAT 2// backend auto-exports top-level funcs; these have <=5 args (wm_run/JS call limit) and use a FIXED linear- 3// memory scratch region (no sys_mmap in wasm). The browser client + nx_wasm_vm reserve MCW_SCR. license_tier: ORIGINAL 4import "nx_media_crypt.nx" 5 6const MCW_SCR: i64 = 0xE000 // fixed scratch offset in linear memory (>= MC_SCRATCH bytes reserved above app data) 7 8// encrypt/decrypt data[0..len) in place with ChaCha20 (key32, nonce12) from block ctr0. Symmetric. 9func mcw_xform(key32: *u8, nonce12: *u8, ctr0: i64, data: *u8, len: i64) -> i64 { 10 return mc_xform(key32, nonce12, ctr0, data, len, MCW_SCR as *u8) } 11// expand the #e= hex fragment (out32 needs 32 bytes) 12func mcw_key(hexk: *u8, hlen: i64, out32: *u8) -> i64 { return mc_key(hexk, hlen, out32) } 13// build the 12-byte nonce = sender(8) || le32(frame counter) 14func mcw_nonce(sender: *u8, fctr: i64, out: *u8) -> i64 { return mc_nonce(sender, fctr, out) }