nx_sha256_wasm.nx
buildroot/runtime/nx_sha256_wasm.nx
about
nx_sha256_wasm.nx -- SHA-256 (FIPS 180-4) self-contained for WAT target.
Per NISHI_ANTI_AUTHORITARIAN_DOCTRINE §6, browser crypto primitives
(crypto.subtle.*) are untrusted -- the substrate must ship its own
SHA-256 that runs in the browser via WASM, not call out to the
browser engine's implementation.
This file deliberately imports NOTHING. The full nx_sha256.nx pulls
in nx_syscalls (for sys_mmap) which transitively drags atomic-op IR
the WAT backend does not yet lower. Here we work in caller-supplied
linear-memory regions and never touch syscalls.
**BLOCKED on nxc2 WAT backend codegen bug (named 2026-05-16):**
The current `wasm.c` only declares `$slot_v<n>` locals for values
produced by OP_ALLOCA (see wasm.c:349-355). Pointer arithmetic via
OP_GEP (every `ctx_ptr[offset]` reads/writes through a GEP-derived
pointer) emits OP_LOAD / OP_STORE addressing through `$slot_v<n>`
without the corresponding declaration. Result: emitted WAT
references undeclared locals; wat2wasm rejects with
"error: undefined local variable $slot_v295".
Fix path (substrate compiler work, queued):
1. WAT backend recognizes the "addr is from non-alloca SSA value"
case and emits real (memory $mem) ops (i64.load/i64.store etc.)
against linear memory, using the GEP-emitted offset directly.
2. Function gets `(memory (export "memory") 16)` declared so the
caller (JS) can access linear memory.
3. Caller passes pointers as i32 offsets into that linear memory;
substrate code does `i32.add` (current emission uses i64).
4. ALTERNATE: have WAT backend pre-scan the function for any
OP_LOAD/STORE addr operand and pre-declare a `$slot_v<n>` for
every such addr value. Cheaper one-line fix but allocates
unnecessary locals for pointer-arithmetic intermediates.
**Until that compiler work lands, the L82 chat-history hash chain
uses crypto.subtle.digest in the browser (sovereignty debt named
in NISHI_ANTI_AUTHORITARIAN_DOCTRINE §6 with this primitive as the
queued replacement).**
dependencies 0 imports · 5 importers
imports: none
imported by: nx_evoracle_sweep.nxnx_lib_pmc_pow.nxnx_netscope_dissect.nxnx_sha256_native_kat_gate.nxnx_x25519_extvec_gate.nx
structs
| none |
consts
| 63 | const M32: i64 = 0xFFFFFFFF |
functions
| 65 | func _rotr32(x: i64, n: i64) -> i64 called by 1: _sha256_compress |
| 73 | func _sha256_k(i: i64) -> i64 called by 1: _sha256_compress |
| 110 | func _blk_word_be(ctx_ptr: *u8, off: i64) -> i64 called by 1: _sha256_compress |
| 119 | func _h_get(ctx_ptr: *u8, i: i64) -> i64 |
| 127 | func _h_set(ctx_ptr: *u8, i: i64, v: i64) -> i64 |
| 137 | func _sha256_compress(ctx_ptr: *u8) -> i64 |
| 230 | func nx_sha256_one_shot(in_ptr: *u8, in_len: i64, ctx_ptr: *u8, out_ptr: *u8) -> i64 |
| 296 | func main() -> i64 |