nx_chacha20_poly1305_wasm.nx
buildroot/runtime/nx_chacha20_poly1305_wasm.nx
about
nx_chacha20_poly1305_wasm.nx -- ChaCha20-Poly1305 AEAD (RFC 7539 §2.8).
AEAD construction:
otk = chacha20_block(key, counter=0, nonce)[:32]
ciphertext = chacha20_xor(key, counter=1, nonce, plaintext)
mac_data = aad || pad16(aad) || ct || pad16(ct) ||
le64(aad_len) || le64(ct_len)
tag = poly1305(otk, mac_data)
return ciphertext || tag
pad16(x) = zero-bytes to reach the next 16-byte multiple; empty if
already aligned.
API for the embedder:
nx_chacha20poly1305_seal(key, nonce,
aad, aad_len,
plaintext, pt_len,
scratch, ciphertext_out, tag_out) -> i64
nx_chacha20poly1305_open(key, nonce,
aad, aad_len,
ciphertext, ct_len,
tag,
scratch, plaintext_out) -> i64
returns 0 on auth success + plaintext_out filled,
-1 on auth failure (plaintext_out NOT touched).
scratch_ptr must be >= 4096 bytes (Poly1305 needs 128 + AEAD staging).
Verified against RFC 7539 §2.8.2 test vector.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/ietf/rfc_7539
lineage_id: nishi_chacha20poly1305_wasm_q11
dependencies 0 imports · 0 importers
imports: none
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 36 | const M32: i64 = 0xFFFFFFFF |
| 37 | const M26: i64 = 0x3ffffff |
functions
| 41 | func _le32_read(buf: *u8, off: i64) -> i64 |
| 48 | func _le32_write(buf: *u8, off: i64, v: i64) -> i64 |
| 56 | func _rotl32(x: i64, n: i64) -> i64 called by 1: _qr |
| 63 | func _qr(state: *u8, ai: i64, bi: i64, ci: i64, di: i64) -> i64 |
| 79 | func _chacha20_block(init: *u8, work: *u8, keystream: *u8) -> i64 called by 3: _chacha20_xornx_chacha20poly1305_sealnx_chacha20poly1305_open calls 3: _qr_le32_read_le32_write |
| 105 | func _chacha20_init_state(init: *u8, key: *u8, nonce: *u8, counter: i64) -> i64 |
| 120 | func _chacha20_xor(key: *u8, nonce: *u8, counter: i64, |
| 146 | func _i64_get(buf: *u8, idx: i64) -> i64 |
| 157 | func _i64_set(buf: *u8, idx: i64, v: i64) -> i64 |
| 170 | func _clamp_and_split_r(key: *u8, r_lims: *u8) -> i64 |
| 188 | func _poly_block(acc: *u8, r_lims: *u8, blk: *u8, blk_len: i64, hi_bit: i64) -> i64 |
| 253 | func _poly1305(key: *u8, msg: *u8, msg_len: i64, scratch: *u8, out: *u8) -> i64 |
| 325 | func _pad16(len: i64) -> i64 |
| 343 | func nx_chacha20poly1305_seal(key: *u8, nonce: *u8, |
| 402 | func nx_chacha20poly1305_open(key: *u8, nonce: *u8, |