code wiki / (root) / nx_sha256_wasm.nx

nx_sha256_wasm.nx

buildroot/runtime/nx_sha256_wasm.nx

13423 B307 linesdepth 0pulls 0 transitivereach 40 importersview sourcekind tooltopic sha256
docsdependenciesstructsconstsfunctions

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 · 38 importers

nx_sha256_wasm.nx nx_aead_extvec_gate.nx nx_aescbc_extvec_gate.nx nx_base16_extvec_gate.nx nx_base16alt_extvec_gate.nx nx_base32_extvec_gate.nx nx_base32hex_extvec_gate.nx nx_base64_extvec_gate.nx nx_base64alt_extvec_gate.nx nx_blake2b_extvec_gate.nx nx_chacha20_extvec_gate.nx

diagram shows first 10 each side; +0 more imports, +28 more importers in the complete lists below.

imports: none

imported by: nx_aead_extvec_gate.nxnx_aescbc_extvec_gate.nxnx_base16_extvec_gate.nxnx_base16alt_extvec_gate.nxnx_base32_extvec_gate.nxnx_base32hex_extvec_gate.nxnx_base64_extvec_gate.nxnx_base64alt_extvec_gate.nxnx_blake2b_extvec_gate.nxnx_chacha20_extvec_gate.nxnx_chacha20enc_extvec_gate.nxnx_ed25519_extvec_gate.nxnx_evoracle_attest.nxnx_evoracle_sweep.nxnx_extvec_authentic_gate.nxnx_hkdf_extvec_gate.nxnx_hmac384_extvec_gate.nxnx_hmac512_extvec_gate.nxnx_hmac_extvec_gate.nxnx_hmacalt_extvec_gate.nxnx_hmaccounter_extvec_gate.nxnx_hmacmd5_extvec_gate.nxnx_hmacmd5alt_extvec_gate.nxnx_hmacsha1_extvec_gate.nxnx_hmacsha1fix_extvec_gate.nxnx_hotp_extvec_gate.nxnx_lib_pmc_pow.nxnx_md5_extvec_gate.nxnx_netscope_dissect.nxnx_otk_extvec_gate.nxnx_pbkdf2_extvec_gate.nxnx_pbkdf2sha1_extvec_gate.nxnx_poly1305_extvec_gate.nxnx_sha1_extvec_gate.nxnx_sha256_native_kat_gate.nxnx_totp_extvec_gate.nxnx_vecfetch.nxnx_x25519_extvec_gate.nx

structs

none

consts

63const M32: i64 = 0xFFFFFFFF

functions

65func _rotr32(x: i64, n: i64) -> i64
called by 1: _sha256_compress
73func _sha256_k(i: i64) -> i64
called by 1: _sha256_compress
110func _blk_word_be(ctx_ptr: *u8, off: i64) -> i64
called by 1: _sha256_compress
119func _h_get(ctx_ptr: *u8, i: i64) -> i64
127func _h_set(ctx_ptr: *u8, i: i64, v: i64) -> i64
137func _sha256_compress(ctx_ptr: *u8) -> i64
230func nx_sha256_one_shot(in_ptr: *u8, in_len: i64, ctx_ptr: *u8, out_ptr: *u8) -> i64
296func main() -> i64