mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-24 14:35:51 +00:00
Drop asmcrypto.js for the AES AEAD modes in favor of noble-ciphers
This commit is contained in:
parent
1377644fb4
commit
edbb882bb5
13
package-lock.json
generated
13
package-lock.json
generated
@ -12,7 +12,6 @@
|
|||||||
"@noble/ciphers": "^0.6.0",
|
"@noble/ciphers": "^0.6.0",
|
||||||
"@noble/curves": "^1.4.0",
|
"@noble/curves": "^1.4.0",
|
||||||
"@noble/hashes": "^1.4.0",
|
"@noble/hashes": "^1.4.0",
|
||||||
"@openpgp/asmcrypto.js": "^3.1.0",
|
|
||||||
"@openpgp/jsdoc": "^3.6.11",
|
"@openpgp/jsdoc": "^3.6.11",
|
||||||
"@openpgp/seek-bzip": "^1.0.5-git",
|
"@openpgp/seek-bzip": "^1.0.5-git",
|
||||||
"@openpgp/tweetnacl": "^1.0.4-1",
|
"@openpgp/tweetnacl": "^1.0.4-1",
|
||||||
@ -870,12 +869,6 @@
|
|||||||
"node": ">= 8"
|
"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": {
|
"node_modules/@openpgp/jsdoc": {
|
||||||
"version": "3.6.11",
|
"version": "3.6.11",
|
||||||
"resolved": "https://registry.npmjs.org/@openpgp/jsdoc/-/jsdoc-3.6.11.tgz",
|
"resolved": "https://registry.npmjs.org/@openpgp/jsdoc/-/jsdoc-3.6.11.tgz",
|
||||||
@ -9098,12 +9091,6 @@
|
|||||||
"fastq": "^1.6.0"
|
"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": {
|
"@openpgp/jsdoc": {
|
||||||
"version": "3.6.11",
|
"version": "3.6.11",
|
||||||
"resolved": "https://registry.npmjs.org/@openpgp/jsdoc/-/jsdoc-3.6.11.tgz",
|
"resolved": "https://registry.npmjs.org/@openpgp/jsdoc/-/jsdoc-3.6.11.tgz",
|
||||||
|
|||||||
@ -65,7 +65,6 @@
|
|||||||
"@noble/ciphers": "^0.6.0",
|
"@noble/ciphers": "^0.6.0",
|
||||||
"@noble/curves": "^1.4.0",
|
"@noble/curves": "^1.4.0",
|
||||||
"@noble/hashes": "^1.4.0",
|
"@noble/hashes": "^1.4.0",
|
||||||
"@openpgp/asmcrypto.js": "^3.1.0",
|
|
||||||
"@openpgp/jsdoc": "^3.6.11",
|
"@openpgp/jsdoc": "^3.6.11",
|
||||||
"@openpgp/seek-bzip": "^1.0.5-git",
|
"@openpgp/seek-bzip": "^1.0.5-git",
|
||||||
"@openpgp/tweetnacl": "^1.0.4-1",
|
"@openpgp/tweetnacl": "^1.0.4-1",
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
* @module crypto/cmac
|
* @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';
|
import util from '../util';
|
||||||
|
|
||||||
const webCrypto = util.getWebCrypto();
|
const webCrypto = util.getWebCrypto();
|
||||||
@ -97,8 +97,7 @@ async function CBC(key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// asm.js fallback
|
|
||||||
return async function(pt) {
|
return async function(pt) {
|
||||||
return AES_CBC.encrypt(pt, key, false, zeroBlock);
|
return nobleAesCbc(key, zeroBlock, { disablePadding: true }).encrypt(pt);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
* @module crypto/mode/eax
|
* @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 CMAC from '../cmac';
|
||||||
import util from '../../util';
|
import util from '../../util';
|
||||||
import enums from '../../enums';
|
import enums from '../../enums';
|
||||||
@ -72,9 +72,8 @@ async function CTR(key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// asm.js fallback
|
|
||||||
return async function(pt, iv) {
|
return async function(pt, iv) {
|
||||||
return AES_CTR.encrypt(pt, key, iv);
|
return nobleAesCtr(key, iv).encrypt(pt);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
* @module crypto/mode/gcm
|
* @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 util from '../../util';
|
||||||
import enums from '../../enums';
|
import enums from '../../enums';
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ async function GCM(cipher, key) {
|
|||||||
return {
|
return {
|
||||||
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
||||||
if (webcryptoEmptyMessagesUnsupported && !pt.length) {
|
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);
|
const ct = await webCrypto.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, pt);
|
||||||
return new Uint8Array(ct);
|
return new Uint8Array(ct);
|
||||||
@ -82,7 +82,7 @@ async function GCM(cipher, key) {
|
|||||||
|
|
||||||
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
||||||
if (webcryptoEmptyMessagesUnsupported && ct.length === tagLength) {
|
if (webcryptoEmptyMessagesUnsupported && ct.length === tagLength) {
|
||||||
return AES_GCM.decrypt(ct, key, iv, adata);
|
return nobleAesGcm(key, iv, adata).decrypt(ct);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const pt = await webCrypto.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength * 8 }, _key, ct);
|
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 {
|
return {
|
||||||
encrypt: async function(pt, iv, adata) {
|
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) {
|
decrypt: async function(ct, iv, adata) {
|
||||||
return AES_GCM.decrypt(ct, key, iv, adata);
|
return nobleAesGcm(key, iv, adata).decrypt(ct);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* @module crypto/mode/ocb
|
* @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 { getCipherParams } from '../cipher';
|
||||||
import util from '../../util';
|
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,
|
// `encipher` and `decipher` cannot be async, since `crypt` shares state across calls,
|
||||||
// hence its execution cannot be broken up.
|
// hence its execution cannot be broken up.
|
||||||
// As a result, WebCrypto cannot currently be used for `encipher`.
|
// As a result, WebCrypto cannot currently be used for `encipher`.
|
||||||
const encipher = block => AES_CBC.encrypt(block, key, false);
|
const aes = nobleAesCbc(key, zeroBlock, { disablePadding: true });
|
||||||
const decipher = block => AES_CBC.decrypt(block, key, false);
|
const encipher = block => aes.encrypt(block);
|
||||||
|
const decipher = block => aes.decrypt(block);
|
||||||
let mask;
|
let mask;
|
||||||
|
|
||||||
constructKeyVariables(cipher, key);
|
constructKeyVariables(cipher, key);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user