code wiki / (root) / nx_kyber_poly_basemul_acc_wasm.nx

nx_kyber_poly_basemul_acc_wasm.nx

buildroot/runtime/nx_kyber_poly_basemul_acc_wasm.nx

5330 B117 linesdepth 0pulls 0 transitivereach 0 importersview sourcekind orphan librarytopic kyber
docsdependenciesstructsconstsfunctions

about

nx_kyber_poly_basemul_acc_wasm.nx -- full-polynomial basemul accumulate. Where K-PKE inner-product loops live. Each call accumulates ONE basemul-product polynomial into the accumulator -- caller invokes this k times to compute a vector inner product (matrix row times vector). FIPS 203 ML-KEM-768 cost: keygen: 9 basemul_acc + 3 poly_zero (= 1 matrix * 1 vec) encrypt: 18 basemul_acc + 6 poly_zero (= 2 matrix-vec + 1 vec dot) decrypt: 3 basemul_acc + 1 poly_zero (= 1 vector dot) Inlined: zetas[64..127] (64 entries from FIPS 203 / PQClean) + montgomery_reduce + fqmul. The L117 nx_kyber_ntt also has these but each WAT module must be self-contained per the build pipeline. API: nx_kyber_poly_zero(p) -> i64 set all 256 coefs = 0 nx_kyber_poly_basemul_acc(acc, a, b) -> i64 acc += basemul(a, b) Result is in Montgomery form (basemul uses fqmul, which has the Mont factor). Caller composes with INVNTT (= invntt_tomont) which expects Montgomery-form input and produces canonical * R output. Per PQClean poly_basemul_montgomery (FIPS 203 ยง4.3.3 equivalent): for i in 0..64: basemul(r[4i..4i+2], a[4i..4i+2], b[4i..4i+2], zetas[64+i]) basemul(r[4i+2..4i+4], a[4i+2..4i+4], b[4i+2..4i+4], -zetas[64+i]) Verified: KAT cross-checked against pure-JS reference implementation. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/nist/fips_203 lineage_id: nishi_kyber_poly_basemul_acc_wasm_q1 safe_shift_audit: no 64-bit rotations in this module

dependencies 0 imports · 0 importers

imports: none

imported by: nobody (leaf or entry point)

structs

none

consts

36const KYBER_Q: i64 = 3329
37const KYBER_QINV: i64 = 62209
38const KYBER_N: i64 = 256

functions

40func _pload(p: *u8, i: i64) -> i64
called by 1: _basemul_pair_acc
48func _pstore(p: *u8, i: i64, v: i64) -> i64
56func _mont(a: i64) -> i64
called by 1: _fqmul
62func _fqmul(a: i64, b: i64) -> i64 { return _mont(a * b) }
called by 1: _basemul_pair_acc calls 1: _mont
66func _zbm(i: i64) -> i64
86func nx_kyber_poly_zero(p: *u8) -> i64
calls 1: _pstore
95func _basemul_pair_acc(acc: *u8, off: i64,
108func nx_kyber_poly_basemul_acc(acc: *u8, a: *u8, b: *u8) -> i64