Expand description
ML-KEM (Kyber) negacyclic NTT runtime kernel — the verified scalar reference + AVX2 i16×16
path that compiled LOGOS reaches through the mlkemNtt stdlib function. Ported from the
validated scripts/ntt_simd_proto.rs (round-trip + AVX2==scalar bit-identical). q = 3329,
R = 2¹⁶, the incomplete 7-level transform over ℤ_q[X]/(X²⁵⁶+1). The Montgomery reduction it
uses is kernel-certified (logicaffeine_kernel::field_algebra::montgomery_reduction_*).
Input/output are LOGOS Int (i64); coefficients are reduced into [0, q) at the boundary, the
transform runs in i16, and the result is returned reduced into [0, q). On x86-64 with AVX2 the
16-wide kernel runs (≈49 ns/NTT on a modern core); otherwise the scalar path (≈147 ns).
Functions§
- mlkem_
add_ mod_ q_ w16 (a + b) mod q, element-wise on Word16 [0, q) — the native modular-add the Logos matrix-vector loop calls (so the orchestration never does Word16 arithmetic, only structure).- mlkem_
base_ mul - The compiled form of LOGOS
mlkemBaseMul(a, b)— pointwise multiply of two NTT-domain polynomials.mlkemInvNtt(mlkemBaseMul(mlkemNtt(a), mlkemNtt(b)))is the ML-KEM polynomial product a·b in ℤ_q[X]/(X²⁵⁶+1). - mlkem_
base_ mul_ w16 - mlkem_
base_ mul_ w16_ seq - mlkem_
byte_ decode - The compiled form of LOGOS
byteDecode(bytes, d)— unpack bytes to coefficients. - mlkem_
byte_ decode_ w16 - mlkem_
byte_ decode_ w16_ from_ int - mlkem_
byte_ decode_ w16_ seq - mlkem_
byte_ encode - The compiled form of LOGOS
byteEncode(coeffs, d)— pack coefficients to bytes. - mlkem_
byte_ encode_ w16 - mlkem_
byte_ encode_ w16_ seq - mlkem_
byte_ encode_ w16_ to_ int - mlkem_
cbd2 - The compiled form of LOGOS
cbd2(buf)— sample a noise polynomial (η=2) from 128 bytes of (SHAKE) randomness; 256 coefficients in [−2, 2]. - mlkem_
cbd3 - The compiled form of LOGOS
cbd3(buf)— η=3 noise from 192 bytes; coefficients in [−3, 3]. - mlkem_
cbd2_ w16 - CBD noise sampled to [0, q) Word16 (the reduced form the Word16 NTT consumes directly).
- mlkem_
cbd2_ w16_ from_ int - mlkem_
cbd2_ w16_ seq - mlkem_
cbd3_ w16 - mlkem_
cbd3_ w16_ seq - mlkem_
compress - The compiled form of LOGOS
compress(coeffs, d)— element-wise Compress_d. - mlkem_
compress_ w16 - mlkem_
compress_ w16_ seq - mlkem_
decompress - The compiled form of LOGOS
decompress(coeffs, d)— element-wise Decompress_d. - mlkem_
decompress_ w16 - mlkem_
decompress_ w16_ seq - mlkem_
inv_ ntt - The compiled form of LOGOS
mlkemInvNtt(a)— the inverse ML-KEM NTT (tomont), somlkemInvNtt(mlkemNtt(p)) = p·2285 mod q. Together withmlkemNttand a base-multiply this is the polynomial-multiplication primitive ML-KEM is built on. - mlkem_
inv_ ntt_ w16 Word16-native inverse NTT, base multiply, and tomont — same zero-conversion carrier.- mlkem_
inv_ ntt_ w16_ seq - mlkem_
ntt - The compiled form of LOGOS
mlkemNtt(a)— the runtime entry the generated Rust calls (and the interpreter dispatches to). Takes/returns the LOGOSSeq of Intcarrier. - mlkem_
ntt_ w16 Word16-native forward NTT — coefficients are carried asWord16(u16) in [0, q), so the boundary is a plain reinterpret (w.0 as i16, exact since q < 2¹⁵), no rem_euclid and no i64 round-trip. The experimental fast carrier for the Word16-representation crypto.- mlkem_
ntt_ w16_ seq - Native entry for the LOGOS
Seq of Word16carrier — wraps the raw Word16 NTT in aLogosSeq. - mlkem_
sample_ a - The compiled form of LOGOS
sampleA(seed, i, j)— expand matrix entry Â[i][j] from the 32-byte seed ρ via SHAKE128, with the XOF and rejection handled in one verified step. - mlkem_
sample_ a_ w16 - Matrix entry Â[i][j] sampled to [0, q) Word16 — streaming SHAKE128 rejection (scalar reference).
- mlkem_
sample_ a_ w16_ from_ int - mlkem_
sample_ a_ w16_ seq - mlkem_
sample_ matrix_ w16 - Sample the full ML-KEM-768 3×3 matrix  at once (9 × 256 Word16, entry Â[r][c] at slot
(r·3+c)·256), batching four rejection-sampling streams per 4-way AVX2 SHAKE128 permutation. Bit-identical to ninemlkem_sample_a_w16calls; falls back to scalar without AVX2. This is the matrix-expansion keystone — sampleA is ~60% of keygen and is×9again in encaps. - mlkem_
sample_ matrix_ w16_ from_ int - Native entry for the full 3×3 matrix  (9 × 256 Word16, entry Â[r][c] at slot
(r·3+c)·256), 4-way AVX2 SHAKE128 batched — the shipped-LogosmlkemSampleMatrixW16(rho). - mlkem_
sample_ ntt - The compiled form of LOGOS
sampleNtt(stream)— rejection-sample a uniform NTT-domain polynomial directly from a caller-provided byte stream. - mlkem_
sub_ mod_ q_ w16 (a − b) mod q, element-wise on Word16 [0, q).- mlkem_
to_ mont - The compiled form of LOGOS
toMont(coeffs)— multiply a polynomial into the Montgomery domain. - mlkem_
to_ mont_ w16 - mlkem_
to_ mont_ w16_ seq - mlkem_
zeros_ w16 - A run of
nzero coefficients (Word16). - sha3_
256_ w8_ seq - sha3_
512_ w8_ seq - shake128_
w8_ seq - shake256_
w8_ seq