From d5d4c972287c6aeed8938e51b4dd5c51952b52b2 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Tue, 10 Apr 2018 14:23:37 +0200 Subject: [PATCH] Fix config.use_native --- src/crypto/eax.js | 4 ++-- src/crypto/gcm.js | 8 ++++---- src/crypto/public_key/elliptic/curves.js | 4 ++-- src/crypto/public_key/elliptic/key.js | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/crypto/eax.js b/src/crypto/eax.js index 6a8dcad8..28d9cce5 100644 --- a/src/crypto/eax.js +++ b/src/crypto/eax.js @@ -137,9 +137,9 @@ function concat(...arrays) { } function CTR(plaintext, key, iv) { - if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support + if (util.getWebCryptoAll() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support return webCtr(plaintext, key, iv); - } else if (nodeCrypto) { // Node crypto library + } else if (util.getNodeCrypto()) { // Node crypto library return nodeCtr(plaintext, key, iv); } // asm.js fallback return Promise.resolve(AES_CTR.encrypt(plaintext, key, iv)); diff --git a/src/crypto/gcm.js b/src/crypto/gcm.js index 6f357fb6..7d5f4a91 100644 --- a/src/crypto/gcm.js +++ b/src/crypto/gcm.js @@ -49,9 +49,9 @@ function encrypt(cipher, plaintext, key, iv) { return Promise.reject(new Error('GCM mode supports only AES cipher')); } - if (webCrypto && 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 return webEncrypt(plaintext, key, iv); - } else if (nodeCrypto) { // Node crypto library + } else if (util.getNodeCrypto()) { // Node crypto library return nodeEncrypt(plaintext, key, iv); } // asm.js fallback return Promise.resolve(AES_GCM.encrypt(plaintext, key, iv)); @@ -70,9 +70,9 @@ function decrypt(cipher, ciphertext, key, iv) { return Promise.reject(new Error('GCM mode supports only AES cipher')); } - if (webCrypto && 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 return webDecrypt(ciphertext, key, iv); - } else if (nodeCrypto) { // Node crypto library + } else if (util.getNodeCrypto()) { // Node crypto library return nodeDecrypt(ciphertext, key, iv); } // asm.js fallback return Promise.resolve(AES_GCM.decrypt(ciphertext, key, iv)); diff --git a/src/crypto/public_key/elliptic/curves.js b/src/crypto/public_key/elliptic/curves.js index 46290620..f19f6662 100644 --- a/src/crypto/public_key/elliptic/curves.js +++ b/src/crypto/public_key/elliptic/curves.js @@ -182,14 +182,14 @@ Curve.prototype.keyFromPublic = function (pub) { Curve.prototype.genKeyPair = async function () { let keyPair; - if (webCrypto && this.web) { + if (this.web && util.getWebCrypto()) { // If browser doesn't support a curve, we'll catch it try { keyPair = await webGenKeyPair(this.name); } catch (err) { util.print_debug("Browser did not support signing: " + err.message); } - } else if (nodeCrypto && this.node) { + } else if (this.node && util.getNodeCrypto()) { keyPair = await nodeGenKeyPair(this.name); } diff --git a/src/crypto/public_key/elliptic/key.js b/src/crypto/public_key/elliptic/key.js index 5bffe80b..f74e0a9b 100644 --- a/src/crypto/public_key/elliptic/key.js +++ b/src/crypto/public_key/elliptic/key.js @@ -45,7 +45,7 @@ function KeyPair(curve, options) { } KeyPair.prototype.sign = async function (message, hash_algo) { - if (webCrypto && this.curve.web) { + if (this.curve.web && util.getWebCrypto()) { // If browser doesn't support a curve, we'll catch it try { // need to await to make sure browser succeeds @@ -54,7 +54,7 @@ KeyPair.prototype.sign = async function (message, hash_algo) { } catch (err) { util.print_debug("Browser did not support signing: " + err.message); } - } else if (nodeCrypto && this.curve.node) { + } else if (this.curve.node && util.getNodeCrypto()) { return nodeSign(this.curve, hash_algo, message, this.keyPair); } const digest = (typeof hash_algo === 'undefined') ? message : hash.digest(hash_algo, message); @@ -62,7 +62,7 @@ KeyPair.prototype.sign = async function (message, hash_algo) { }; KeyPair.prototype.verify = async function (message, signature, hash_algo) { - if (webCrypto && this.curve.web) { + if (this.curve.web && util.getWebCrypto()) { // If browser doesn't support a curve, we'll catch it try { // need to await to make sure browser succeeds @@ -71,7 +71,7 @@ KeyPair.prototype.verify = async function (message, signature, hash_algo) { } catch (err) { util.print_debug("Browser did not support signing: " + err.message); } - } else if (nodeCrypto && this.curve.node) { + } else if (this.curve.node && util.getNodeCrypto()) { return nodeVerify(this.curve, hash_algo, signature, message, this.keyPair.getPublic()); } const digest = (typeof hash_algo === 'undefined') ? message : hash.digest(hash_algo, message);