ML-KEM-512 and ML-KEM-768
This allocation-free no_std wrapper uses a local copy of final-standard
fips203=0.5.0 with default features disabled. The local package retains upstream
validation, secret wiping and implicit rejection. Polynomial products compose
its existing canonical arithmetic without a software-wide u128 multiply;
public and ciphertext byte views avoid cloning a zeroizing object for export.
Public matrix generation streams one polynomial through multiplication, reducing
source-level matrix scratch from 2048/4608 bytes to 512 bytes for 512/768. This
is a storage bound, not a measured Wasm peak-stack or page claim. Choose the mlkem512 or mlkem768 module. It supplies
KEM primitives, not sender authentication or an application encryption envelope.
See the preferred paths and
dated best-pick report for qualified artifacts and
complete-operation input/preparation boundaries.
use cdk_rsx_crypto_mlkem::{CryptoRng, Error, RngCore, mlkem768};
fn example<R: CryptoRng + RngCore>(rng: &mut R) -> Result<(), Error> {
let recipient = mlkem768::keygen(rng)?;
let (ciphertext, sender_secret) = recipient.public.encapsulate(rng)?;
let receiver_secret = recipient.secret.decapsulate(&ciphertext)?;
assert_eq!(sender_secret.as_bytes(), receiver_secret.as_bytes());
Ok(())
}
Callers supply the CSPRNG; no ambient RNG is enabled. Deterministic
keygen_from_seeds(d,z) and encapsulate_from_seed(m) also exist, but real use
requires fresh uniform cryptographic seed material. Public benchmark entropy
must never provision live keys or messages.
| Parameter | Public key | Secret key | Ciphertext | Shared secret |
|---|---|---|---|---|
| ML-KEM-512 | 800 | 1632 | 768 | 32 |
| ML-KEM-768 | 1184 | 2400 | 1088 | 32 |
Byte imports enforce exact lengths and the upstream key consistency/coefficient checks. A correctly sized corrupted ciphertext normally produces an implicit-rejection secret; decapsulation success is not an authentication boolean. A higher-level authenticated protocol must decide acceptance. Keys and shared secrets erase on drop; explicit secret-key exports return a zeroizing copy. This is not a guarantee that every compiler spill or earlier copy erases.
Provenance pins the published archive/source and fixture
origins, with MIT and Apache licenses retained.
Tests execute all 120 supported NIST keygen/encapsulation/
decapsulation cases in the vector directory, plus boundary,
mutation, round-trip and failing-RNG cases. Differential tests
compare distinct key/encapsulation cohorts for each parameter set with the
untouched registry pin, including byte-exact implicit-rejection outputs. The research note
describes implicit rejection and protocol limits. Installed qualification and
targeted compiled-code review are recorded in the current reports linked above.
The integer polynomial oracles
run in the portable fork with simd128 or simd128-q15.
The benchmark registers fresh-key encapsulation/decapsulation, which import and validate each record's encoded key inside the measured call, and same-call-key controls, which import one key inside the call and reuse it across all records. Distinct input mode gives the latter one key and distinct encapsulation seeds/ ciphertexts. Separate public/secret decode cases measure checked key import. Prior-setup validated-key cases are diagnostics. They are not the primary complete-operation costs. Key generation and explicit-seed encapsulation use public deterministic entropy only for the benchmark. Every cohort executes once for its requested batch and retains every complete output for post-kernel checks.
The expanded-same-call-key controls additionally precompute the public matrix,
public-key hash and decoded polynomial coefficients once inside each call.
EncapsulationKey::prepare() and DecapsulationKey::prepare() create the
explicit contexts; callers still supply fresh entropy for each encapsulation.
Contexts retain no ciphertext verdict or successful-operation cache, and all
fields erase on drop. Encoded-key and expanded-key operations have identical
ciphertexts, shared secrets and implicit-rejection keys. Context object layouts
are separate from compiled peak-stack and page measurements. See optimization notes
for the source analysis and qualification scope.
The optional simd128 arithmetic leaf uses existing Wasm SIMD128
operations for NTT, pointwise multiplication and whole-polynomial addition.
Addition updates the caller-owned polynomial eight canonical coefficients at a
time with the existing butterfly add_mod: each sum is below 2q and one masked
subtraction restores the canonical range. Buffer ownership, erasure, encoded
outputs and implicit rejection are unchanged. The separate simd128-q15 feature
selects an exact Q15 Montgomery quotient and implies simd128; default builds
retain scalar arithmetic. Native lane-model proofs and artifact-specific Wasm
qualification remain distinct evidence.