Post-quantum primitives
@webbuf/mlkem
Rust/wasm ML-KEM (FIPS 203) post-quantum key encapsulation
Install
npm install @webbuf/mlkem Usage
const { encapsulationKey, decapsulationKey } = mlKem768KeyPair();
const { ciphertext, sharedSecret } = mlKem768Encapsulate(encapsulationKey);
const recovered = mlKem768Decapsulate(decapsulationKey, ciphertext); API reference (20 exports)
Constants
ML_KEM_1024
constML_KEM_1024: { readonly encapsulationKeySize: 1568; readonly decapsulationKeySize: 3168; readonly ciphertextSize: 1568; readonly sharedSecretSize: 32; } ML_KEM_512
constML_KEM_512: { readonly encapsulationKeySize: 800; readonly decapsulationKeySize: 1632; readonly ciphertextSize: 768; readonly sharedSecretSize: 32; } ML_KEM_768
constML_KEM_768: { readonly encapsulationKeySize: 1184; readonly decapsulationKeySize: 2400; readonly ciphertextSize: 1088; readonly sharedSecretSize: 32; } Functions
mlKem1024Decapsulate
functionmlKem1024Decapsulate(decapsulationKey: FixedBuf<3168>, ciphertext: FixedBuf<1568>): FixedBuf<32> mlKem1024Encapsulate
functionmlKem1024Encapsulate(encapsulationKey: FixedBuf<1568>): MlKemEncapResult<1568, 32>
mlKem1024Encapsulate(encapsulationKey: FixedBuf<1568>, m: FixedBuf<32>): MlKemEncapResult<1568, 32> mlKem1024EncapsulateDeterministic
functionmlKem1024EncapsulateDeterministic(encapsulationKey: FixedBuf<1568>, m: FixedBuf<32>): MlKemEncapResult<1568, 32> mlKem1024KeyPair
functionmlKem1024KeyPair(): MlKemKeyPair<1568, 3168>
mlKem1024KeyPair(d: FixedBuf<32>, z: FixedBuf<32>): MlKemKeyPair<1568, 3168> mlKem1024KeyPairDeterministic
functionmlKem1024KeyPairDeterministic(d: FixedBuf<32>, z: FixedBuf<32>): MlKemKeyPair<1568, 3168> mlKem512Decapsulate
functionmlKem512Decapsulate(decapsulationKey: FixedBuf<1632>, ciphertext: FixedBuf<768>): FixedBuf<32> mlKem512Encapsulate
functionmlKem512Encapsulate(encapsulationKey: FixedBuf<800>): MlKemEncapResult<768, 32>
mlKem512Encapsulate(encapsulationKey: FixedBuf<800>, m: FixedBuf<32>): MlKemEncapResult<768, 32> mlKem512EncapsulateDeterministic
functionmlKem512EncapsulateDeterministic(encapsulationKey: FixedBuf<800>, m: FixedBuf<32>): MlKemEncapResult<768, 32> mlKem512KeyPair
functionmlKem512KeyPair(): MlKemKeyPair<800, 1632>
mlKem512KeyPair(d: FixedBuf<32>, z: FixedBuf<32>): MlKemKeyPair<800, 1632> mlKem512KeyPairDeterministic
functionmlKem512KeyPairDeterministic(d: FixedBuf<32>, z: FixedBuf<32>): MlKemKeyPair<800, 1632> mlKem768Decapsulate
functionmlKem768Decapsulate(decapsulationKey: FixedBuf<2400>, ciphertext: FixedBuf<1088>): FixedBuf<32> mlKem768Encapsulate
functionmlKem768Encapsulate(encapsulationKey: FixedBuf<1184>): MlKemEncapResult<1088, 32>
mlKem768Encapsulate(encapsulationKey: FixedBuf<1184>, m: FixedBuf<32>): MlKemEncapResult<1088, 32> mlKem768EncapsulateDeterministic
functionmlKem768EncapsulateDeterministic(encapsulationKey: FixedBuf<1184>, m: FixedBuf<32>): MlKemEncapResult<1088, 32> mlKem768KeyPair
functionmlKem768KeyPair(): MlKemKeyPair<1184, 2400>
mlKem768KeyPair(d: FixedBuf<32>, z: FixedBuf<32>): MlKemKeyPair<1184, 2400> mlKem768KeyPairDeterministic
functionmlKem768KeyPairDeterministic(d: FixedBuf<32>, z: FixedBuf<32>): MlKemKeyPair<1184, 2400> Interfaces
MlKemEncapResult
interfaceciphertext: FixedBuf<CtSize>
sharedSecret: FixedBuf<SsSize> MlKemKeyPair
interfaceencapsulationKey: FixedBuf<EkSize>
decapsulationKey: FixedBuf<DkSize>