code wiki / (root) / nx_kyber_poly_wasm.nx

nx_kyber_poly_wasm.nx

buildroot/runtime/nx_kyber_poly_wasm.nx

8584 B239 linesdepth 0pulls 0 transitivereach 0 importersview sourcekind orphan librarytopic kyber
docsdependenciesstructsconstsfunctions

about

nx_kyber_poly_wasm.nx -- K-PKE polynomial helpers for FIPS 203 ML-KEM-768. Composes with the shipped nx_kyber_ntt (L117). Together these are the L2 substrate transforms that nx_ml_kem_768.nx (L118 next) composes the FIPS 203 KEM around. All polynomials are 256-coefficient over Z_{3329}. In-memory format: packed little-endian INT16 at byte ptr (512 bytes per polynomial). CALLER is responsible for canonical-form vs Montgomery-form bookkeeping per FIPS 203 conventions (NTT-domain polynomials are in Mont form per PQClean `_tomont`; canonical-form polynomials are NOT). Public API: nx_kyber_poly_add(out, a, b) -> i64 out = a + b mod q nx_kyber_poly_sub(out, a, b) -> i64 out = a - b mod q nx_kyber_poly_cbd_eta2(out, buf) -> i64 centered binomial sample from 128 bytes nx_kyber_poly_compress10(bytes_out, poly) -> i64 320-byte d_u packing nx_kyber_poly_decompress10(poly, bytes) -> i64 320-byte unpack nx_kyber_poly_compress4(bytes_out, poly) -> i64 128-byte d_v packing nx_kyber_poly_decompress4(poly, bytes) -> i64 128-byte unpack nx_kyber_poly_tobytes12(bytes_out, poly) -> i64 384-byte canonical nx_kyber_poly_frombytes12(poly, bytes) -> i64 384-byte parse Reductions: caller-provided polynomials should be in canonical [0, q). poly_add/sub output coefficients in [0, 2q-2] / [-q+1, q-1]; caller applies barrett_reduce (in NTT module) before passing further if needed. Verified: smoke runs each compress/decompress pair + tobytes/frombytes round-trip; the deterministic encoding round-trips bit-exact. license_tier: INDEPENDENT_REDERIVE genealogy_id: international-research-sources/nist/fips_203 lineage_id: nishi_kyber_poly_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

37const KYBER_Q: i64 = 3329
38const KYBER_N: i64 = 256

functions

42func _pload(p: *u8, i: i64) -> i64
50func _pstore(p: *u8, i: i64, v: i64) -> i64
59func _canon(v: i64) -> i64
67func nx_kyber_poly_add(out: *u8, a: *u8, b: *u8) -> i64
calls 2: _pload_pstore
77func nx_kyber_poly_sub(out: *u8, a: *u8, b: *u8) -> i64
calls 2: _pload_pstore
96func nx_kyber_poly_cbd_eta2(out: *u8, buf: *u8) -> i64
calls 1: _pstore
122func _compress10_one(v: i64) -> i64
called by 1: nx_kyber_poly_compress10 calls 1: _canon
128func nx_kyber_poly_compress10(bytes_out: *u8, poly: *u8) -> i64
147func _decompress10_one(x: i64) -> i64
151func nx_kyber_poly_decompress10(poly: *u8, bytes_in: *u8) -> i64
176func _compress4_one(v: i64) -> i64
called by 1: nx_kyber_poly_compress4 calls 1: _canon
181func nx_kyber_poly_compress4(bytes_out: *u8, poly: *u8) -> i64
192func _decompress4_one(x: i64) -> i64
196func nx_kyber_poly_decompress4(poly: *u8, bytes_in: *u8) -> i64
211func nx_kyber_poly_tobytes12(bytes_out: *u8, poly: *u8) -> i64
calls 2: _canon_pload
225func nx_kyber_poly_frombytes12(poly: *u8, bytes_in: *u8) -> i64
calls 1: _pstore