diff --git a/src/crypto/eax.js b/src/crypto/eax.js index 08444185..6eed009b 100644 --- a/src/crypto/eax.js +++ b/src/crypto/eax.js @@ -49,7 +49,11 @@ async function OMAC(key) { } async function CTR(key) { - if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support + if ( + util.getWebCrypto() && + key.length !== 24 && // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support + navigator.userAgent.indexOf('Edge') === -1 + ) { key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']); return async function(pt, iv) { const ct = await webCrypto.encrypt({ name: 'AES-CTR', counter: iv, length: blockLength * 8 }, key, pt); diff --git a/src/crypto/gcm.js b/src/crypto/gcm.js index dc268211..fa57f905 100644 --- a/src/crypto/gcm.js +++ b/src/crypto/gcm.js @@ -50,22 +50,30 @@ async function GCM(cipher, key) { return { encrypt: async function(pt, iv, adata=new Uint8Array()) { - if (!pt.length) { + if ( + !pt.length || // iOS does not support GCM-en/decrypting empty messages // Also, synchronous en/decryption might be faster in this case. + (!adata.length && navigator.userAgent.indexOf('Edge') !== -1) + // Edge does not support GCM-en/decrypting without ADATA + ) { return AES_GCM.encrypt(pt, key, iv, adata); } - const ct = await webCrypto.encrypt({ name: ALGO, iv, additionalData: adata }, _key, pt); + const ct = await webCrypto.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, pt); return new Uint8Array(ct); }, decrypt: async function(ct, iv, adata=new Uint8Array()) { - if (ct.length === tagLength) { + if ( + ct.length === tagLength || // iOS does not support GCM-en/decrypting empty messages // Also, synchronous en/decryption might be faster in this case. - return AES_GCM.decrypt(ct, key, iv, adata); + (!adata.length && navigator.userAgent.indexOf('Edge') !== -1) + // Edge does not support GCM-en/decrypting without ADATA + ) { + return AES_GCM.decrypt(ct, key, iv, adata); } - const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata }, _key, ct); + const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, ct); return new Uint8Array(pt); } };