HQC-256 key encapsulation mechanism wrapper class
HQC256
High-level wrapper for HQC-256 KEM operations. Provides secure key generation, encapsulation, and decapsulation with automatic memory management.
Memory Management:
const kem = await createHQC256();// Generate keypairconst { publicKey, secretKey } = kem.generateKeyPair();// Encapsulateconst { ciphertext, sharedSecret } = kem.encapsulate(publicKey);// Decapsulateconst recoveredSecret = kem.decapsulate(ciphertext, secretKey);// Cleanupkem.destroy(); Copy
const kem = await createHQC256();// 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-256'console.log(kem.info.securityLevel); // 5console.log(kem.info.keySize); // { publicKey: 7245, secretKey: 7317, ciphertext: 14421, sharedSecret: 64 } Copy
console.log(kem.info.name); // 'HQC-256'console.log(kem.info.securityLevel); // 5console.log(kem.info.keySize); // { publicKey: 7245, secretKey: 7317, ciphertext: 14421, sharedSecret: 64 }
Generate a new HQC-256 keypair
If instance is destroyed
If key generation fails
const { publicKey, secretKey } = kem.generateKeyPair();console.log('Public key:', publicKey.length); // 7245 bytesconsole.log('Secret key:', secretKey.length); // 7317 bytes Copy
const { publicKey, secretKey } = kem.generateKeyPair();console.log('Public key:', publicKey.length); // 7245 bytesconsole.log('Secret key:', secretKey.length); // 7317 bytes
Encapsulate a shared secret using a public key
Public key (7245 bytes)
If public key size is invalid
If encapsulation fails
const { ciphertext, sharedSecret } = kem.encapsulate(publicKey);console.log('Ciphertext:', ciphertext.length); // 14421 bytesconsole.log('Shared secret:', sharedSecret.length); // 64 bytes Copy
const { ciphertext, sharedSecret } = kem.encapsulate(publicKey);console.log('Ciphertext:', ciphertext.length); // 14421 bytesconsole.log('Shared secret:', sharedSecret.length); // 64 bytes
Decapsulate a shared secret using a secret key
Ciphertext (14421 bytes)
Secret key (7317 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-256 key encapsulation mechanism wrapper class
HQC256
Description
High-level wrapper for HQC-256 KEM operations. Provides secure key generation, encapsulation, and decapsulation with automatic memory management.
Memory Management:
Example