code wiki / (root) / nx_hmac_sha256_wasm.nx

nx_hmac_sha256_wasm.nx

buildroot/runtime/nx_hmac_sha256_wasm.nx

14934 B383 linesdepth 0pulls 0 transitivereach 0 importersview sourcekind orphan librarytopic hmac
docsdependenciesstructsconstsfunctions

about

nx_hmac_sha256_wasm.nx -- HMAC-SHA-256 (RFC 2104) for WAT target. HMAC(K, M) = H( (K' XOR opad) || H( (K' XOR ipad) || M ) ) K' = K when len(K) <= B (= 64 for SHA-256) H(K) padded with zeros to B otherwise ipad = 0x36 repeated B times opad = 0x5c repeated B times Built on top of nx_sha256_wasm.nx -- the SHA-256 helper functions are pasted in directly (NishiLang doesn't yet have multi-file imports for the WAT target, and the import would drag in the nx_syscalls atomics IR that the WAT backend doesn't lower). API for the embedder: nx_hmac_sha256_one_shot(key_ptr, key_len, msg_ptr, msg_len, scratch_ptr, out_ptr) -> i64 key_ptr -- HMAC key bytes key_len -- key byte count msg_ptr -- message bytes msg_len -- message byte count scratch_ptr -- 1024-byte scratch area (caller-allocated) out_ptr -- 32-byte HMAC output destination Memory layout of scratch_ptr (caller need not zero): bytes 0.. 63 : K' (block-sized key) buffer bytes 64.. 127 : K' XOR ipad buffer bytes 128.. 191 : K' XOR opad buffer bytes 192.. 223 : H(K' XOR ipad || M) inner hash output bytes 256.. 767 : SHA-256 ctx scratch (512 bytes, see nx_sha256_wasm) bytes 768.. 832 : 64-byte buffer used to concat K' XOR opad || inner_hash (64 + 32 = 96 bytes total, so reserve 96) Verified against RFC 4231 test vectors -- see bench/wasm_hmac_smoke.js. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_2104 + rfc_4231 lineage_id: nishi_hmac_sha256_wasm_q11

dependencies 0 imports · 0 importers

imports: none

imported by: nobody (leaf or entry point)

structs

none

consts

39const M32: i64 = 0xFFFFFFFF
40const HMAC_B: i64 = 64 // SHA-256 block size in bytes

functions

45func _rotr32(x: i64, n: i64) -> i64
called by 1: _sha256_compress
52func _sha256_k(i: i64) -> i64
called by 1: _sha256_compress
88func _blk_word_be(ctx_ptr: *u8, off: i64) -> i64
called by 1: _sha256_compress
96func _h_get(ctx_ptr: *u8, i: i64) -> i64
104func _h_set(ctx_ptr: *u8, i: i64, v: i64) -> i64
113func _sha256_compress(ctx_ptr: *u8) -> i64
187func _sha256_one_shot(in_ptr: *u8, in_len: i64, ctx_ptr: *u8, out_ptr: *u8) -> i64
251func nx_hmac_sha256_one_shot(key_ptr: *u8, key_len: i64,