Safari 8 compatibility
This commit is contained in:
parent
cc1f7a4765
commit
a7fce27424
|
@ -140,7 +140,7 @@ async function EAX(cipher, key) {
|
||||||
for (let i = 0; i < tagLength; i++) {
|
for (let i = 0; i < tagLength; i++) {
|
||||||
tag[i] ^= omacAdata[i] ^ omacNonce[i];
|
tag[i] ^= omacAdata[i] ^ omacNonce[i];
|
||||||
}
|
}
|
||||||
if (!util.equalsUint8Array(ctTag, tag)) throw new Error('Authentication tag mismatch in EAX ciphertext');
|
if (!util.equalsUint8Array(ctTag, tag)) throw new Error('Authentication tag mismatch');
|
||||||
const plaintext = await ctr(ciphered, omacNonce);
|
const plaintext = await ctr(ciphered, omacNonce);
|
||||||
return plaintext;
|
return plaintext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ async function OCB(cipher, key) {
|
||||||
if (util.equalsUint8Array(tag, crypted.subarray(-tagLength))) {
|
if (util.equalsUint8Array(tag, crypted.subarray(-tagLength))) {
|
||||||
return crypted.subarray(0, -tagLength);
|
return crypted.subarray(0, -tagLength);
|
||||||
}
|
}
|
||||||
throw new Error('Authentication tag mismatch in OCB ciphertext');
|
throw new Error('Authentication tag mismatch');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,7 +309,7 @@ SecretKey.prototype.decrypt = async function (passphrase) {
|
||||||
const modeInstance = await mode(symmetric, key);
|
const modeInstance = await mode(symmetric, key);
|
||||||
cleartext = await modeInstance.decrypt(ciphertext, iv.subarray(0, mode.ivLength), new Uint8Array());
|
cleartext = await modeInstance.decrypt(ciphertext, iv.subarray(0, mode.ivLength), new Uint8Array());
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (err.message.startsWith('Authentication tag mismatch')) {
|
if (err.message === 'Authentication tag mismatch') {
|
||||||
throw new Error('Incorrect key passphrase: ' + err.message);
|
throw new Error('Incorrect key passphrase: ' + err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ function testAESEAX() {
|
||||||
ct = await eax.encrypt(msgBytes, nonceBytes, headerBytes);
|
ct = await eax.encrypt(msgBytes, nonceBytes, headerBytes);
|
||||||
ct[2] ^= 8;
|
ct[2] ^= 8;
|
||||||
pt = eax.decrypt(ct, nonceBytes, headerBytes);
|
pt = eax.decrypt(ct, nonceBytes, headerBytes);
|
||||||
await expect(pt).to.eventually.be.rejectedWith('Authentication tag mismatch in EAX ciphertext')
|
await expect(pt).to.eventually.be.rejectedWith('Authentication tag mismatch')
|
||||||
|
|
||||||
// testing without additional data
|
// testing without additional data
|
||||||
ct = await eax.encrypt(msgBytes, nonceBytes, new Uint8Array());
|
ct = await eax.encrypt(msgBytes, nonceBytes, new Uint8Array());
|
||||||
|
|
|
@ -136,7 +136,7 @@ describe('Symmetric AES-OCB', function() {
|
||||||
ct = await ocb.encrypt(msgBytes, nonceBytes, headerBytes);
|
ct = await ocb.encrypt(msgBytes, nonceBytes, headerBytes);
|
||||||
ct[2] ^= 8;
|
ct[2] ^= 8;
|
||||||
pt = ocb.decrypt(ct, nonceBytes, headerBytes);
|
pt = ocb.decrypt(ct, nonceBytes, headerBytes);
|
||||||
await expect(pt).to.eventually.be.rejectedWith('Authentication tag mismatch in OCB ciphertext')
|
await expect(pt).to.eventually.be.rejectedWith('Authentication tag mismatch')
|
||||||
|
|
||||||
// testing without additional data
|
// testing without additional data
|
||||||
ct = await ocb.encrypt(msgBytes, nonceBytes, new Uint8Array());
|
ct = await ocb.encrypt(msgBytes, nonceBytes, new Uint8Array());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user