code wiki / (root) / nx_chacha20_wasm.nx

nx_chacha20_wasm.nx

buildroot/runtime/nx_chacha20_wasm.nx

6607 B191 linesdepth 0pulls 0 transitivereach 0 importersview sourcekind orphan librarytopic chacha20
docsdependenciesstructsconstsfunctions

about

nx_chacha20_wasm.nx -- ChaCha20 stream cipher (RFC 7539) for WAT target. State is a 4x4 matrix of 32-bit words: "expand 32-byte k" (constants 0..3) key words 0..7 (key bytes 0..31) counter (word 12) nonce words 13..15 (nonce bytes 0..11) 20 rounds of quarter-round operations, then add original state, produce 64 bytes of keystream per block. XOR keystream with plaintext byte-for-byte to encrypt; same operation decrypts. API for the embedder: nx_chacha20_xor(key_ptr, nonce_ptr, counter, in_ptr, in_len, scratch_ptr, out_ptr) -> i64 key_ptr -- 32 bytes (256-bit key) nonce_ptr -- 12 bytes (96-bit nonce per RFC 7539) counter -- starting block counter (1 for RFC 7539; 0 for some flows; caller's choice) in_ptr -- plaintext bytes in_len -- input length scratch_ptr -- >= 256 bytes; holds state + working matrix out_ptr -- ciphertext bytes (may alias in_ptr for in-place) Memory layout of scratch_ptr: bytes 0..63 : initial state (16 i32 words, little-endian packed) bytes 64..127 : working state during one block compute bytes 128..191 : keystream output bytes for one block bytes 192.. : unused Verified against RFC 7539 ยง2.4.2 test vector. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/ietf/rfc_7539 lineage_id: nishi_chacha20_wasm_q11

dependencies 0 imports · 0 importers

imports: none

imported by: nobody (leaf or entry point)

structs

none

consts

39const M32: i64 = 0xFFFFFFFF

functions

42func _le32_read(buf: *u8, off: i64) -> i64
called by 2: _qr_chacha20_block
50func _le32_write(buf: *u8, off: i64, v: i64) -> i64
59func _rotl32(x: i64, n: i64) -> i64
called by 1: _qr
74func _qr(state: *u8, ai: i64, bi: i64, ci: i64, di: i64) -> i64
95func _chacha20_block(init: *u8, work: *u8, keystream: *u8) -> i64
135func _chacha20_init_state(init: *u8, key: *u8, nonce: *u8, counter: i64) -> i64
called by 1: nx_chacha20_xor calls 1: _le32_write
160func nx_chacha20_xor(key_ptr: *u8, nonce_ptr: *u8, counter: i64,