Class: HybridKEM
Defined in: kem.ts:123
Hybrid classical + post-quantum KEM. Default: X25519+ML-KEM-768, byte-compatible with quantum-safe-py's HybridKEM. Also accepts X-Wing (interoperable with other X-Wing implementations and with quantum-safe-py 1.0.0's XWing).
Example
await init(); // no-op on Node.js
const kem = new HybridKEM();
using pair = kem.generateKeyPair();
const { ciphertext, sharedSecret } = kem.encapsulate(pair.publicKey);
using recovered = kem.decapsulate(pair.secretKey, ciphertext);Extends
BaseKem
Constructors
Constructor
new HybridKEM(
algorithm?):HybridKEM
Defined in: kem.ts:130
Creates a hybrid KEM.
Parameters
algorithm?
KemAlgorithm = DEFAULT_KEM
A hybrid KEM name (see kemSuites()). Default X25519+ML-KEM-768.
Returns
HybridKEM
Throws
if algorithm is not a supported hybrid KEM.
Throws
if init() has not completed.
Overrides
BaseKem.constructor
Properties
algorithm
readonlyalgorithm:KemAlgorithm
Defined in: kem.ts:33
Canonical algorithm string.
Inherited from
BaseKem.algorithm
info
readonlyinfo:SuiteInfo
Defined in: kem.ts:35
Suite metadata (NIST level, CNSA 2.0 status, …).
Inherited from
BaseKem.info
Methods
decapsulate()
decapsulate(
secretKey,ciphertext):SecretBytes
Defined in: kem.ts:95
Recovers the shared secret from ciphertext.
ML-KEM uses implicit rejection (FIPS 203): a ciphertext that was not produced for this key yields a pseudorandom secret rather than an error, so a wrong ciphertext is detected downstream (for example by AEAD authentication), not here.
Parameters
secretKey
The recipient's secret key for this KEM's algorithm.
ciphertext
Uint8Array
The ciphertext field of the Encapsulation returned by encapsulate().
Returns
The shared secret; free it when done.
Throws
if the ciphertext has the wrong structure or length.
Throws
if the key belongs to a different algorithm.
Throws
if the classical component of a hybrid fails.
Throws
if secretKey is not a SecretKey, has been freed, or ciphertext is not bytes.
Inherited from
BaseKem.decapsulate
encapsulate()
encapsulate(
publicKey):Encapsulation
Defined in: kem.ts:66
Encapsulates a fresh shared secret to publicKey.
Parameters
publicKey
The recipient's public key for this KEM's algorithm.
Returns
The ciphertext to send and the 32-byte shared secret; free the secret when done.
Throws
if the key belongs to a different algorithm.
Throws
if the key bytes are invalid.
Throws
if publicKey is not a PublicKey or has been freed.
Inherited from
BaseKem.encapsulate
generateKeyPair()
generateKeyPair():
KeyPair
Defined in: kem.ts:54
Generates a key pair. Free it (or use using) when done.
Returns
A new key pair for this KEM's algorithm.
Throws
if init() has not completed.
Inherited from
BaseKem.generateKeyPair