crypto/mlkem
lib/crypto/mlkem.vklib/crypto/mlkem.vk
Pure-Veko FIPS 203 ML-KEM (Module-Lattice-Based Key-Encapsulation Mechanism):
Supports ML-KEM-512, ML-KEM-768, and ML-KEM-1024 using in-place 256-coeff NTTs (put)
and FIPS 202 SHA3/SHAKE (crypto/sha3). Zero capabilities required.
KeyPair = struct { param enum, ek bytes, dk bytes }
Key pair produced by mlkem/keygen or mlkem/keygen-deterministic.
EncapsResult = struct { ciphertext bytes, shared_secret bytes }
Encapsulation output produced by mlkem/encaps or mlkem/encaps-deterministic.
keygen-deterministic = fn [param enum, d_seed bytes, z_seed bytes] KeyPair
Deterministic FIPS 203 ML-KEM key generation from 32-byte d_seed and 32-byte z_seed.
use [kem = crypto/mlkem]
d = bytes/fill 32 0x11
z = bytes/fill 32 0x22
m = bytes/fill 32 0x33
kp = kem/keygen-deterministic .mlkem512 d z
enc = kem/encaps-deterministic .mlkem512 kp.ek m
ss2 = kem/decaps .mlkem512 kp.dk enc.ciphertext
if ss2 != enc.shared_secret or (len kp.ek) != 800 or (len enc.ciphertext) != 768 [
err 'mlkem-512 roundtrip failed'
] else [ .ok ]
keygen = fn [param enum] KeyPair
Generates a fresh ML-KEM key pair using the OS/hardware CSPRNG (random/bytes).
encaps-deterministic = fn [param enum, ek bytes, m32 bytes] EncapsResult
Deterministic FIPS 203 ML-KEM encapsulation using 32-byte message seed m32.
encaps = fn [param enum, ek bytes] EncapsResult
Encapsulates a fresh 32-byte shared secret to ek using the OS/hardware CSPRNG.
decaps = fn [param enum, dk bytes, ct bytes] bytes
FIPS 203 ML-KEM decapsulation with constant-time implicit rejection on tampered ciphertexts.