UNPKG

@iota-big3/sdk-quantum

Version:

Quantum-ready architecture with post-quantum cryptography

64 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KyberKEM = void 0; class KyberKEM { constructor(securityLevel) { this.securityLevel = securityLevel; this.params = this.getParameters(securityLevel); } async generateKeyPair() { const publicKeySize = this?.params?.publicKeySize; const privateKeySize = this?.params?.privateKeySize; const publicKey = crypto.getRandomValues(new Uint8Array(publicKeySize)); const privateKey = crypto.getRandomValues(new Uint8Array(privateKeySize)); console.log(`Generated Kyber-${this?.params?.n} keypair`); return { publicKey, privateKey }; } async encapsulate(_publicKey) { const ciphertextSize = this?.params?.ciphertextSize; const sharedSecretSize = 32; const ciphertext = crypto.getRandomValues(new Uint8Array(ciphertextSize)); const sharedSecret = crypto.getRandomValues(new Uint8Array(sharedSecretSize)); return { ciphertext, sharedSecret }; } async decapsulate(_ciphertext, _privateKey) { const sharedSecretSize = 32; const sharedSecret = crypto.getRandomValues(new Uint8Array(sharedSecretSize)); return sharedSecret; } getParameters(level) { switch (level) { case 1: return { n: 256, k: 2, q: 3329, publicKeySize: 800, privateKeySize: 1632, ciphertextSize: 768 }; case 3: return { n: 256, k: 3, q: 3329, publicKeySize: 1184, privateKeySize: 2400, ciphertextSize: 1088 }; case 5: return { n: 256, k: 4, q: 3329, publicKeySize: 1568, privateKeySize: 3168, ciphertextSize: 1568 }; default: return this.getParameters(3); } } } exports.KyberKEM = KyberKEM; //# sourceMappingURL=kyber.js.map