@iota-big3/sdk-quantum
Version:
Quantum-ready architecture with post-quantum cryptography
67 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FrodoKEM = void 0;
class FrodoKEM {
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 FrodoKEM-${this?.params?.n} keypair`);
return { publicKey, privateKey };
}
async encapsulate(_publicKey) {
const ciphertextSize = this?.params?.ciphertextSize;
const sharedSecretSize = this?.params?.sharedSecretSize;
const ciphertext = crypto.getRandomValues(new Uint8Array(ciphertextSize));
const sharedSecret = crypto.getRandomValues(new Uint8Array(sharedSecretSize));
return { ciphertext, sharedSecret };
}
async decapsulate(_ciphertext, _privateKey) {
const sharedSecretSize = this?.params?.sharedSecretSize;
const sharedSecret = crypto.getRandomValues(new Uint8Array(sharedSecretSize));
return sharedSecret;
}
getParameters(level) {
switch (level) {
case 1:
return {
n: 640,
q: 32768,
sigma: 2.8,
publicKeySize: 9616,
privateKeySize: 19888,
ciphertextSize: 9720,
sharedSecretSize: 16
};
case 3:
return {
n: 976,
q: 65536,
sigma: 2.3,
publicKeySize: 15632,
privateKeySize: 31296,
ciphertextSize: 15744,
sharedSecretSize: 24
};
case 5:
return {
n: 1344,
q: 65536,
sigma: 1.4,
publicKeySize: 21520,
privateKeySize: 43088,
ciphertextSize: 21632,
sharedSecretSize: 32
};
default:
return this.getParameters(3);
}
}
}
exports.FrodoKEM = FrodoKEM;
//# sourceMappingURL=frodo.js.map