HQC-128 key encapsulation mechanism wrapper class
HQC128
High-level wrapper for HQC-128 KEM operations. Provides secure key generation, encapsulation, and decapsulation with automatic memory management.
Memory Management:
const kem = await createHQC128();// Generate keypairconst { publicKey, secretKey } = kem.generateKeyPair();// Encapsulateconst { ciphertext, sharedSecret } = kem.encapsulate(publicKey);// Decapsulateconst recoveredSecret = kem.decapsulate(ciphertext, secretKey);// Cleanupkem.destroy(); Copy
const kem = await createHQC128();// Generate keypairconst { publicKey, secretKey } = kem.generateKeyPair();// Encapsulateconst { ciphertext, sharedSecret } = kem.encapsulate(publicKey);// Decapsulateconst recoveredSecret = kem.decapsulate(ciphertext, secretKey);// Cleanupkem.destroy();
Get algorithm information
Algorithm metadata
console.log(kem.info.name); // 'HQC-128'console.log(kem.info.securityLevel); // 1console.log(kem.info.keySize); // { publicKey: 2249, secretKey: 2305, ciphertext: 4433, sharedSecret: 64 } Copy
console.log(kem.info.name); // 'HQC-128'console.log(kem.info.securityLevel); // 1console.log(kem.info.keySize); // { publicKey: 2249, secretKey: 2305, ciphertext: 4433, sharedSecret: 64 }
Generate a new HQC-128 keypair
If instance is destroyed
If key generation fails
const { publicKey, secretKey } = kem.generateKeyPair();console.log('Public key:', publicKey.length); // 2249 bytesconsole.log('Secret key:', secretKey.length); // 2305 bytes Copy
const { publicKey, secretKey } = kem.generateKeyPair();console.log('Public key:', publicKey.length); // 2249 bytesconsole.log('Secret key:', secretKey.length); // 2305 bytes
Encapsulate a shared secret using a public key
Public key (2249 bytes)
If public key size is invalid
If encapsulation fails
const { ciphertext, sharedSecret } = kem.encapsulate(publicKey);console.log('Ciphertext:', ciphertext.length); // 4433 bytesconsole.log('Shared secret:', sharedSecret.length); // 64 bytes Copy
const { ciphertext, sharedSecret } = kem.encapsulate(publicKey);console.log('Ciphertext:', ciphertext.length); // 4433 bytesconsole.log('Shared secret:', sharedSecret.length); // 64 bytes
Decapsulate a shared secret using a secret key
Ciphertext (4433 bytes)
Secret key (2305 bytes)
Shared secret (64 bytes)
If ciphertext or secret key size is invalid
If decapsulation fails
const sharedSecret = kem.decapsulate(ciphertext, secretKey);console.log('Recovered secret:', sharedSecret.length); // 64 bytes Copy
const sharedSecret = kem.decapsulate(ciphertext, secretKey);console.log('Recovered secret:', sharedSecret.length); // 64 bytes
Free WASM resources
Releases all WASM memory associated with this instance. The instance cannot be used after calling destroy().
kem.destroy();// kem is now unusable Copy
kem.destroy();// kem is now unusable
HQC-128 key encapsulation mechanism wrapper class
HQC128
Description
High-level wrapper for HQC-128 KEM operations. Provides secure key generation, encapsulation, and decapsulation with automatic memory management.
Memory Management:
Example