crystals-kyber-ts
Version:
KYBER is an IND-CCA2-secure key encapsulation mechanism (KEM).
83 lines • 2.38 kB
JavaScript
/**
* Kyber Handshake
*/
export class KyberHandshake {
constructor(kyberService) {
this.kyberService = kyberService;
this._remotePublicKey = [];
this._cipherText = [];
this._sharedSecret = [];
this._remoteSharedSecret = [];
this._remoteCipherText = [];
const kyberKeys = this.kyberService.generateKyberKeys();
this._publicKey = kyberKeys[0];
this._privateKey = kyberKeys[1];
}
/**
* Process the remote public key to create a cipher text and shared
* secret
* @param remotePublicKey
* @return cipherText
*/
generateCipherTextAndSharedSecret(remotePublicKey) {
this.remotePublicKey = remotePublicKey;
const sharedSecretCipher = this.kyberService.encrypt(remotePublicKey);
this.cipherText = sharedSecretCipher[0];
this.sharedSecret = sharedSecretCipher[1];
return this.cipherText;
}
/**
* Process the remote cipher text to generate the same shared
* secret
* @param remoteCipherText
* @return remoteSharedSecret
*/
generateRemoteSharedSecret(remoteCipherText) {
this.remoteCipherText = remoteCipherText;
this.remoteSharedSecret = this.kyberService.decrypt(remoteCipherText, this.privateKey);
return this.remoteSharedSecret;
}
get sharedSecret() {
return this._sharedSecret;
}
set sharedSecret(value) {
this._sharedSecret = value;
}
get publicKey() {
return this._publicKey;
}
set publicKey(value) {
this._publicKey = value;
}
get remoteSharedSecret() {
return this._remoteSharedSecret;
}
set remoteSharedSecret(value) {
this._remoteSharedSecret = value;
}
get cipherText() {
return this._cipherText;
}
set cipherText(value) {
this._cipherText = value;
}
get remoteCipherText() {
return this._remoteCipherText;
}
set remoteCipherText(value) {
this._remoteCipherText = value;
}
get privateKey() {
return this._privateKey;
}
set privateKey(value) {
this._privateKey = value;
}
get remotePublicKey() {
return this._remotePublicKey;
}
set remotePublicKey(value) {
this._remotePublicKey = value;
}
}
//# sourceMappingURL=kyber-handshake.js.map