Skip to content

About

ML-KEM.NetCore is a pure managed .NET implementation of the NIST-standardized ML-KEM (Kyber) post-quantum key encapsulation mechanism.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

ML-KEM.NetCore

License: MIT

ML-KEM.NetCore is a managed .NET 8 implementation of ML-KEM, tested against FIPS 203 vectors for ML-KEM-512, ML-KEM-768, and ML-KEM-1024. RFC 9936 specifies how to use ML-KEM in CMS and takes the algorithm from FIPS 203. FIPS 203 · RFC 9936

The 2.0.0 candidate has a cryptographic compatibility break with 1.0.0. Use an explicit protocol or format version when selecting keys or handling persisted ciphertexts. See the migration runbook.

Quick start

Reference MLKEM.NetCore/MLKEM.NetCore.csproj from your .NET 8 project.

using MLKEM.NetCore;

var kem = new MLKem(MLKemParameterSet.MLKem768);
var alice = kem.GenerateKeyPair();
using var aliceKey = alice.SecretKey;

var bob = kem.Encapsulate(alice.PublicKey);
using var bobSecret = bob.SharedSecret;

using var aliceSecret = kem.Decapsulate(
    aliceKey.Read().AsSpan(0, kem.SecretKeyBytes), bob.CipherText);

// Use each side's shared secret in the application's authenticated protocol.
var aliceBytes = aliceSecret.Read().AsSpan(0, kem.SharedSecretBytes);
var bobBytes = bobSecret.Read().AsSpan(0, kem.SharedSecretBytes);

Dispose the pinned key and shared-secret buffers promptly. Read() exposes the backing array, which can be larger than the logical value. Use the advertised byte lengths and do not access the array after disposal. Holding a span or array reference does not extend the lifetime of the pinned buffer. Inputs should remain stable while an operation reads them.

Key and ciphertext formats

Parameter set Public key Expanded private key Ciphertext Shared secret
MLKem512 800 1632 768 32
MLKem768 1184 2400 1088 32
MLKem1024 1568 3168 1568 32

Sizes are in bytes. The expanded private key is dkPKE || ek || H(ek) || z. A compact 64-byte d || z seed can be expanded with GenerateKeyPair(d, z). The deterministic APIs accept exactly 32 bytes per seed or encapsulation message and are intended for seed expansion, test vectors, or protocols that enforce their own fresh private randomness. Ordinary callers should use GenerateKeyPair() and Encapsulate(publicKey).

Encapsulation rejects an incorrectly sized key or a noncanonical public polynomial. Decapsulation rejects incorrectly sized inputs and a mismatch between the embedded public key and its stored hash. For an invalid ciphertext of the correct size and a valid key, it derives a rejection secret from SHAKE256(z || ciphertext, 32) and returns it through the same API as a successful shared secret. Applications should authenticate the payload using their protocol and should keep key validation errors distinct from payload authentication failures.

Validation and security scope

dotnet test MLKEM.sln -c Release

The tests use pinned NIST ACVP fixtures and independently generated SHA3/SHAKE and rejection outputs. They run offline after NuGet restore. OpenSSL 3.5+ is used as a separate interoperability oracle. See the validation report for commands, results, and runner scope.

The implementation wipes its owned secret buffers and uses PinnedMemory 2.0.1 for returned secrets. OS page locking is best effort. Explicit cleanup covers owned buffers and carries no guarantee about registers, historical GC copies, or operating-system snapshots. FIPS 203 vector results do not establish FIPS 140 validation. Runtime code-generation evidence is scoped to the platforms and modes recorded in the validation report.

License

MIT

About

ML-KEM.NetCore is a pure managed .NET implementation of the NIST-standardized ML-KEM (Kyber) post-quantum key encapsulation mechanism.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages