MlKemConformanceTest

FIPS 203 known-answer tests from NIST's ACVP vectors (github.com/usnistgov/ACVP-Server, commit 975de31e), replayed through the public operations of any backend with ML-KEM: key generation from NIST's d || z, encapsulation with NIST's m, decapsulation with NIST's keys, implicit rejection, and the input checks of FIPS 203 §7.2 and §7.3.

A backend's tests extend it with two factories, the second drawing every random byte from a script:

class MyMlKemTest : MlKemConformanceTest() {
override fun createBackend(): CryptoBackend = MyBackend(DefaultCryptoBackend())
override fun createBackend(random: ScriptedRandom): CryptoBackend =
MyBackend(object : CryptoBackend by DefaultCryptoBackend() {
override suspend fun randomBytes(size: Int): ByteArray = random.next(size)
})
}

The private keys are the seed or the expanded decapsulation key of KeyType (seedLength, expandedPrivateKeyLength), and the backend imports both with importKeyPair. Input that fails the FIPS 203 checks is rejected with an exception other than UnsupportedAlgorithmException. Parameter sets the backend does not support (supports(KemAlgorithm)) are skipped, but it must support one.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

FIPS 203 Algorithm 20 with NIST's m gives NIST's c and k, and dk decapsulates c back to k.

FIPS 203 §7.3: a decapsulation key whose H(ek) was modified fails the hash check, on import and on use.

FIPS 203 Algorithm 18, lines 7-10: NIST's modified ciphertext decapsulates to J(z || c), without an error.

Link copied to clipboard

FIPS 203 Algorithm 19 with NIST's d and z: the encapsulation key matches; the key is the seed or dk.

FIPS 203 §7.2: an encapsulation key with coefficients of q or more fails the modulus check.

The seed and NIST's expanded dk (FIPS 203 Algorithm 16) are the same key: both decapsulate a valid and a modified ciphertext to the same secrets, so s, H(ek) and z all agree.

Import refuses NIST's expanded dk with an encapsulation key it does not belong to.