nx_kyber_poly_wasm.nx
buildroot/runtime/nx_kyber_poly_wasm.nx
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
| 37 | const KYBER_Q: i64 = 3329 |
| 38 | const KYBER_N: i64 = 256 |
functions
| 42 | func _pload(p: *u8, i: i64) -> i64 |
| 50 | func _pstore(p: *u8, i: i64, v: i64) -> i64 |
| 59 | func _canon(v: i64) -> i64 |
| 67 | func nx_kyber_poly_add(out: *u8, a: *u8, b: *u8) -> i64 |
| 77 | func nx_kyber_poly_sub(out: *u8, a: *u8, b: *u8) -> i64 |
| 96 | func nx_kyber_poly_cbd_eta2(out: *u8, buf: *u8) -> i64 calls 1: _pstore |
| 122 | func _compress10_one(v: i64) -> i64 |
| 128 | func nx_kyber_poly_compress10(bytes_out: *u8, poly: *u8) -> i64 |
| 147 | func _decompress10_one(x: i64) -> i64 called by 1: nx_kyber_poly_decompress10 |
| 151 | func nx_kyber_poly_decompress10(poly: *u8, bytes_in: *u8) -> i64 |
| 176 | func _compress4_one(v: i64) -> i64 |
| 181 | func nx_kyber_poly_compress4(bytes_out: *u8, poly: *u8) -> i64 |
| 192 | func _decompress4_one(x: i64) -> i64 called by 1: nx_kyber_poly_decompress4 |
| 196 | func nx_kyber_poly_decompress4(poly: *u8, bytes_in: *u8) -> i64 |
| 211 | func nx_kyber_poly_tobytes12(bytes_out: *u8, poly: *u8) -> i64 |
| 225 | func nx_kyber_poly_frombytes12(poly: *u8, bytes_in: *u8) -> i64 calls 1: _pstore |