nx_kyber_msg_codec_wasm.nx
buildroot/runtime/nx_kyber_msg_codec_wasm.nx
about
nx_kyber_msg_codec_wasm.nx -- 1-bit message <-> polynomial codec.
FIPS 203 ยง4.2.4 Compress_1 / Decompress_1 specialized for the K-PKE
message-embedding step. Each bit of the 32-byte message becomes one
coefficient of a 256-coef polynomial (32 * 8 = 256 bits).
Encoding direction (msg -> poly, used in K-PKE encrypt step 10):
For each bit b in msg: coefficient = b * Decompress_1(1)
= b * round(q/2)
= b * 1665 (since (3329 + 1) / 2 = 1665)
Decoding direction (poly -> msg, used in K-PKE decrypt step 9):
For each coefficient c (canonical [0, q)): bit = Compress_1(c)
= round((2 * c) / q) mod 2
= ((c << 1) + q/2) / q mod 2
= ((2*c + 1665) / 3329) & 1
The decoding boundary is c = q/2 = 1665 (and -1665 = 1664 in [0,q)).
Coefficients close to 0 decode to bit 0; coefficients close to q/2
decode to bit 1. This is the error-correcting margin that makes
K-PKE robust to the small noise added during encrypt.
API:
nx_kyber_msg_to_poly(poly_out, msg_32) -> i64
nx_kyber_msg_from_poly(msg_out, poly) -> i64
Verified: KAT round-trip on random 32-byte messages + boundary cases.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: international-research-sources/nist/fips_203
lineage_id: nishi_kyber_msg_codec_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
| 34 | const KYBER_Q: i64 = 3329 |
| 35 | const KYBER_N: i64 = 256 |
| 36 | const KYBER_HALF: i64 = 1665 // (q+1)/2 = Decompress_1(1) |
functions
| 38 | func _pstore(p: *u8, i: i64, v: i64) -> i64 called by 1: nx_kyber_msg_to_poly |
| 46 | func _pload(p: *u8, i: i64) -> i64 called by 1: nx_kyber_msg_from_poly |
| 56 | func nx_kyber_msg_to_poly(poly_out: *u8, msg_in: *u8) -> i64 calls 1: _pstore |
| 72 | func _canon(v: i64) -> i64 called by 1: nx_kyber_msg_from_poly |
| 83 | func _compress_1(c: i64) -> i64 called by 1: nx_kyber_msg_from_poly |
| 88 | func nx_kyber_msg_from_poly(msg_out: *u8, poly_in: *u8) -> i64 |