Fall back to asm for CTR and CBC in old Safari
This commit is contained in:
parent
b8191388cd
commit
550b758d57
|
@ -9,7 +9,7 @@
|
||||||
import { AES_CBC } from 'asmcrypto.js/src/aes/cbc/exports';
|
import { AES_CBC } from 'asmcrypto.js/src/aes/cbc/exports';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
|
|
||||||
const webCrypto = util.getWebCryptoAll();
|
const webCrypto = util.getWebCrypto();
|
||||||
const nodeCrypto = util.getNodeCrypto();
|
const nodeCrypto = util.getNodeCrypto();
|
||||||
const Buffer = util.getNodeBuffer();
|
const Buffer = util.getNodeBuffer();
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ export default async function CMAC(key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function CBC(key) {
|
async function CBC(key) {
|
||||||
if (util.getWebCryptoAll() && 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
|
||||||
key = await webCrypto.importKey('raw', key, { name: 'AES-CBC', length: key.length * 8 }, false, ['encrypt']);
|
key = await webCrypto.importKey('raw', key, { name: 'AES-CBC', length: key.length * 8 }, false, ['encrypt']);
|
||||||
return async function(pt) {
|
return async function(pt) {
|
||||||
const ct = await webCrypto.encrypt({ name: 'AES-CBC', iv: zeroBlock, length: blockLength * 8 }, key, pt);
|
const ct = await webCrypto.encrypt({ name: 'AES-CBC', iv: zeroBlock, length: blockLength * 8 }, key, pt);
|
||||||
|
|
|
@ -28,7 +28,7 @@ import { AES_CTR } from 'asmcrypto.js/src/aes/ctr/exports';
|
||||||
import CMAC from './cmac';
|
import CMAC from './cmac';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
|
|
||||||
const webCrypto = util.getWebCryptoAll();
|
const webCrypto = util.getWebCrypto();
|
||||||
const nodeCrypto = util.getNodeCrypto();
|
const nodeCrypto = util.getNodeCrypto();
|
||||||
const Buffer = util.getNodeBuffer();
|
const Buffer = util.getNodeBuffer();
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ async function OMAC(key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function CTR(key) {
|
async function CTR(key) {
|
||||||
if (util.getWebCryptoAll() && 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
|
||||||
key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']);
|
key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']);
|
||||||
return async function(pt, iv) {
|
return async function(pt, iv) {
|
||||||
const ct = await webCrypto.encrypt({ name: 'AES-CTR', counter: iv, length: blockLength * 8 }, key, pt);
|
const ct = await webCrypto.encrypt({ name: 'AES-CTR', counter: iv, length: blockLength * 8 }, key, pt);
|
||||||
|
|
|
@ -585,13 +585,13 @@ function onError(message, error) {
|
||||||
/**
|
/**
|
||||||
* Check for native AEAD support and configuration by the user. Only
|
* Check for native AEAD support and configuration by the user. Only
|
||||||
* browsers that implement the current WebCrypto specification support
|
* browsers that implement the current WebCrypto specification support
|
||||||
* native GCM. Native EAX is built on CTR and CBC, which all browsers
|
* native GCM. Native EAX is built on CTR and CBC, which current
|
||||||
* support. OCB and CFB are not natively supported.
|
* browsers support. OCB and CFB are not natively supported.
|
||||||
* @returns {Boolean} If authenticated encryption should be used
|
* @returns {Boolean} If authenticated encryption should be used
|
||||||
*/
|
*/
|
||||||
function nativeAEAD() {
|
function nativeAEAD() {
|
||||||
return config.aead_protect && (
|
return config.aead_protect && (
|
||||||
((config.aead_protect_version !== 4 || config.aead_mode === enums.aead.experimental_gcm) && util.getWebCrypto()) ||
|
((config.aead_protect_version !== 4 || config.aead_mode === enums.aead.experimental_gcm) && util.getWebCrypto()) ||
|
||||||
(config.aead_protect_version === 4 && config.aead_mode === enums.aead.eax && util.getWebCryptoAll())
|
(config.aead_protect_version === 4 && config.aead_mode === enums.aead.eax && util.getWebCrypto())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -720,7 +720,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tryTests('EAX mode (native)', tests, {
|
tryTests('EAX mode (native)', tests, {
|
||||||
if: openpgp.util.getWebCryptoAll() || openpgp.util.getNodeCrypto(),
|
if: openpgp.util.getWebCrypto() || openpgp.util.getNodeCrypto(),
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
openpgp.config.use_native = true;
|
openpgp.config.use_native = true;
|
||||||
openpgp.config.aead_protect = true;
|
openpgp.config.aead_protect = true;
|
||||||
|
@ -733,7 +733,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tryTests('EAX mode (small chunk size)', tests, {
|
tryTests('EAX mode (small chunk size)', tests, {
|
||||||
if: openpgp.util.getWebCryptoAll() || openpgp.util.getNodeCrypto(),
|
if: openpgp.util.getWebCrypto() || openpgp.util.getNodeCrypto(),
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
openpgp.config.use_native = true;
|
openpgp.config.use_native = true;
|
||||||
openpgp.config.aead_protect = true;
|
openpgp.config.aead_protect = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user