diff --git a/package-lock.json b/package-lock.json index 3d846f7a..3462369f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "@noble/ciphers": "^0.6.0", "@noble/curves": "^1.4.0", "@noble/hashes": "^1.4.0", - "@openpgp/asmcrypto.js": "^3.1.0", "@openpgp/jsdoc": "^3.6.11", "@openpgp/seek-bzip": "^1.0.5-git", "@openpgp/tweetnacl": "^1.0.4-1", @@ -870,12 +869,6 @@ "node": ">= 8" } }, - "node_modules/@openpgp/asmcrypto.js": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@openpgp/asmcrypto.js/-/asmcrypto.js-3.1.0.tgz", - "integrity": "sha512-LlQZE/Vtkx/KFnJxg7BB0iwD7oYKDeC8eRECHxKLhYyL2Ad0+xT137VZwv8SZTJB2euPqpx7xkj04ieV0Q665w==", - "dev": true - }, "node_modules/@openpgp/jsdoc": { "version": "3.6.11", "resolved": "https://registry.npmjs.org/@openpgp/jsdoc/-/jsdoc-3.6.11.tgz", @@ -9098,12 +9091,6 @@ "fastq": "^1.6.0" } }, - "@openpgp/asmcrypto.js": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@openpgp/asmcrypto.js/-/asmcrypto.js-3.1.0.tgz", - "integrity": "sha512-LlQZE/Vtkx/KFnJxg7BB0iwD7oYKDeC8eRECHxKLhYyL2Ad0+xT137VZwv8SZTJB2euPqpx7xkj04ieV0Q665w==", - "dev": true - }, "@openpgp/jsdoc": { "version": "3.6.11", "resolved": "https://registry.npmjs.org/@openpgp/jsdoc/-/jsdoc-3.6.11.tgz", diff --git a/package.json b/package.json index 6058e2ba..89ad6293 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,6 @@ "@noble/ciphers": "^0.6.0", "@noble/curves": "^1.4.0", "@noble/hashes": "^1.4.0", - "@openpgp/asmcrypto.js": "^3.1.0", "@openpgp/jsdoc": "^3.6.11", "@openpgp/seek-bzip": "^1.0.5-git", "@openpgp/tweetnacl": "^1.0.4-1", diff --git a/src/crypto/cmac.js b/src/crypto/cmac.js index 19d996a8..6159cdf7 100644 --- a/src/crypto/cmac.js +++ b/src/crypto/cmac.js @@ -4,7 +4,7 @@ * @module crypto/cmac */ -import { AES_CBC } from '@openpgp/asmcrypto.js/aes/cbc.js'; +import { cbc as nobleAesCbc } from '@noble/ciphers/aes'; import util from '../util'; const webCrypto = util.getWebCrypto(); @@ -97,8 +97,7 @@ async function CBC(key) { } } - // asm.js fallback return async function(pt) { - return AES_CBC.encrypt(pt, key, false, zeroBlock); + return nobleAesCbc(key, zeroBlock, { disablePadding: true }).encrypt(pt); }; } diff --git a/src/crypto/mode/eax.js b/src/crypto/mode/eax.js index ab64ec6b..1ea2284d 100644 --- a/src/crypto/mode/eax.js +++ b/src/crypto/mode/eax.js @@ -21,7 +21,7 @@ * @module crypto/mode/eax */ -import { AES_CTR } from '@openpgp/asmcrypto.js/aes/ctr.js'; +import { ctr as nobleAesCtr } from '@noble/ciphers/aes'; import CMAC from '../cmac'; import util from '../../util'; import enums from '../../enums'; @@ -72,9 +72,8 @@ async function CTR(key) { } } - // asm.js fallback return async function(pt, iv) { - return AES_CTR.encrypt(pt, key, iv); + return nobleAesCtr(key, iv).encrypt(pt); }; } diff --git a/src/crypto/mode/gcm.js b/src/crypto/mode/gcm.js index b482a5dc..b1d2cfe4 100644 --- a/src/crypto/mode/gcm.js +++ b/src/crypto/mode/gcm.js @@ -21,7 +21,7 @@ * @module crypto/mode/gcm */ -import { AES_GCM } from '@openpgp/asmcrypto.js/aes/gcm.js'; +import { gcm as nobleAesGcm } from '@noble/ciphers/aes'; import util from '../../util'; import enums from '../../enums'; @@ -74,7 +74,7 @@ async function GCM(cipher, key) { return { encrypt: async function(pt, iv, adata = new Uint8Array()) { if (webcryptoEmptyMessagesUnsupported && !pt.length) { - return AES_GCM.encrypt(pt, key, iv, adata); + return nobleAesGcm(key, iv, adata).encrypt(pt); } const ct = await webCrypto.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, pt); return new Uint8Array(ct); @@ -82,7 +82,7 @@ async function GCM(cipher, key) { decrypt: async function(ct, iv, adata = new Uint8Array()) { if (webcryptoEmptyMessagesUnsupported && ct.length === tagLength) { - return AES_GCM.decrypt(ct, key, iv, adata); + return nobleAesGcm(key, iv, adata).decrypt(ct); } try { const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, ct); @@ -106,11 +106,11 @@ async function GCM(cipher, key) { return { encrypt: async function(pt, iv, adata) { - return AES_GCM.encrypt(pt, key, iv, adata); + return nobleAesGcm(key, iv, adata).encrypt(pt); }, decrypt: async function(ct, iv, adata) { - return AES_GCM.decrypt(ct, key, iv, adata); + return nobleAesGcm(key, iv, adata).decrypt(ct); } }; } diff --git a/src/crypto/mode/ocb.js b/src/crypto/mode/ocb.js index 868c67b9..e8b8cabf 100644 --- a/src/crypto/mode/ocb.js +++ b/src/crypto/mode/ocb.js @@ -20,7 +20,7 @@ * @module crypto/mode/ocb */ -import { AES_CBC } from '@openpgp/asmcrypto.js/aes/cbc.js'; +import { cbc as nobleAesCbc } from '@noble/ciphers/aes'; import { getCipherParams } from '../cipher'; import util from '../../util'; @@ -73,8 +73,9 @@ async function OCB(cipher, key) { // `encipher` and `decipher` cannot be async, since `crypt` shares state across calls, // hence its execution cannot be broken up. // As a result, WebCrypto cannot currently be used for `encipher`. - const encipher = block => AES_CBC.encrypt(block, key, false); - const decipher = block => AES_CBC.decrypt(block, key, false); + const aes = nobleAesCbc(key, zeroBlock, { disablePadding: true }); + const encipher = block => aes.encrypt(block); + const decipher = block => aes.decrypt(block); let mask; constructKeyVariables(cipher, key);