aboutsummaryrefslogtreecommitdiff
path: root/node_modules/pbkdf2
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/pbkdf2')
-rw-r--r--node_modules/pbkdf2/README.md2
-rw-r--r--node_modules/pbkdf2/browser.js2
-rw-r--r--node_modules/pbkdf2/index.js32
-rw-r--r--node_modules/pbkdf2/lib/async.js22
-rw-r--r--node_modules/pbkdf2/lib/precondition.js12
-rw-r--r--node_modules/pbkdf2/lib/sync-browser.js4
-rw-r--r--node_modules/pbkdf2/lib/sync.js3
-rw-r--r--node_modules/pbkdf2/package.json6
8 files changed, 60 insertions, 23 deletions
diff --git a/node_modules/pbkdf2/README.md b/node_modules/pbkdf2/README.md
index 05757828e..614934f72 100644
--- a/node_modules/pbkdf2/README.md
+++ b/node_modules/pbkdf2/README.md
@@ -20,6 +20,8 @@ var derivedKey = pbkdf2.pbkdf2Sync('password', 'salt', 1, 32, 'sha512')
For more information on the API, please see the relevant [Node documentation](https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback).
+For high performance, use the `async` variant (`pbkdf2.pbkdf2`), not `pbkdf2.pbkdf2Sync`, this variant has the oppurtunity to use `window.crypto.subtle` when browserified.
+
## Credits
diff --git a/node_modules/pbkdf2/browser.js b/node_modules/pbkdf2/browser.js
index 98e615a85..ac5fdd8d6 100644
--- a/node_modules/pbkdf2/browser.js
+++ b/node_modules/pbkdf2/browser.js
@@ -1,4 +1,2 @@
-
exports.pbkdf2 = require('./lib/async')
-
exports.pbkdf2Sync = require('./lib/sync')
diff --git a/node_modules/pbkdf2/index.js b/node_modules/pbkdf2/index.js
index 205abf08f..fc2f8d96f 100644
--- a/node_modules/pbkdf2/index.js
+++ b/node_modules/pbkdf2/index.js
@@ -1,9 +1,31 @@
-var crypto = require('crypto')
+var checkParameters = require('./lib/precondition')
+var native = require('crypto')
+
+function nativePBKDF2 (password, salt, iterations, keylen, digest, callback) {
+ checkParameters(password, salt, iterations, keylen)
+
+ if (typeof digest === 'function') {
+ callback = digest
+ digest = 'sha1'
+ }
+ if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
+
+ return native.pbkdf2(password, salt, iterations, keylen, digest, callback)
+}
+
+function nativePBKDF2Sync (password, salt, iterations, keylen, digest) {
+ checkParameters(password, salt, iterations, keylen)
+ digest = digest || 'sha1'
+ return native.pbkdf2Sync(password, salt, iterations, keylen, digest)
+}
+
/* istanbul ignore next */
-if (crypto && (!crypto.pbkdf2Sync || crypto.pbkdf2Sync.toString().indexOf('keylen, digest') === -1)) {
- exports.pbkdf2 = require('./lib/async')
+if (!native.pbkdf2Sync || native.pbkdf2Sync.toString().indexOf('keylen, digest') === -1) {
exports.pbkdf2Sync = require('./lib/sync')
+ exports.pbkdf2 = require('./lib/async')
+
+// native
} else {
- exports.pbkdf2Sync = crypto.pbkdf2Sync
- exports.pbkdf2 = crypto.pbkdf2
+ exports.pbkdf2Sync = nativePBKDF2Sync
+ exports.pbkdf2 = nativePBKDF2
}
diff --git a/node_modules/pbkdf2/lib/async.js b/node_modules/pbkdf2/lib/async.js
index c0b91b9a8..b20da7c8b 100644
--- a/node_modules/pbkdf2/lib/async.js
+++ b/node_modules/pbkdf2/lib/async.js
@@ -37,6 +37,7 @@ function checkNative (algo) {
checks[algo] = prom
return prom
}
+
function browserPbkdf2 (password, salt, iterations, length, algo) {
return subtle.importKey(
'raw', password, {name: 'PBKDF2'}, false, ['deriveBits']
@@ -53,6 +54,7 @@ function browserPbkdf2 (password, salt, iterations, length, algo) {
return Buffer.from(res)
})
}
+
function resolvePromise (promise, callback) {
promise.then(function (out) {
process.nextTick(function () {
@@ -65,18 +67,14 @@ function resolvePromise (promise, callback) {
})
}
module.exports = function (password, salt, iterations, keylen, digest, callback) {
- if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
- if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
-
- checkParameters(iterations, keylen)
if (typeof digest === 'function') {
callback = digest
digest = undefined
}
- if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
digest = digest || 'sha1'
var algo = toBrowser[digest.toLowerCase()]
+
if (!algo || typeof global.Promise !== 'function') {
return process.nextTick(function () {
var out
@@ -88,11 +86,15 @@ module.exports = function (password, salt, iterations, keylen, digest, callback)
callback(null, out)
})
}
+
+ checkParameters(password, salt, iterations, keylen)
+ if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
+ if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
+ if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
+
resolvePromise(checkNative(algo).then(function (resp) {
- if (resp) {
- return browserPbkdf2(password, salt, iterations, keylen, algo)
- } else {
- return sync(password, salt, iterations, keylen, digest)
- }
+ if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo)
+
+ return sync(password, salt, iterations, keylen, digest)
}), callback)
}
diff --git a/node_modules/pbkdf2/lib/precondition.js b/node_modules/pbkdf2/lib/precondition.js
index 1519b0092..683db5630 100644
--- a/node_modules/pbkdf2/lib/precondition.js
+++ b/node_modules/pbkdf2/lib/precondition.js
@@ -1,5 +1,15 @@
var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
-module.exports = function (iterations, keylen) {
+
+function checkBuffer (buf, name) {
+ if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
+ throw new TypeError(name + ' must be a buffer or string')
+ }
+}
+
+module.exports = function (password, salt, iterations, keylen) {
+ checkBuffer(password, 'Password')
+ checkBuffer(salt, 'Salt')
+
if (typeof iterations !== 'number') {
throw new TypeError('Iterations not a number')
}
diff --git a/node_modules/pbkdf2/lib/sync-browser.js b/node_modules/pbkdf2/lib/sync-browser.js
index 7f0bf9131..202d29edb 100644
--- a/node_modules/pbkdf2/lib/sync-browser.js
+++ b/node_modules/pbkdf2/lib/sync-browser.js
@@ -63,11 +63,11 @@ function getDigest (alg) {
}
function pbkdf2 (password, salt, iterations, keylen, digest) {
+ checkParameters(password, salt, iterations, keylen)
+
if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
- checkParameters(iterations, keylen)
-
digest = digest || 'sha1'
var hmac = new Hmac(digest, password, salt.length)
diff --git a/node_modules/pbkdf2/lib/sync.js b/node_modules/pbkdf2/lib/sync.js
index 67b2e543d..f691e31a6 100644
--- a/node_modules/pbkdf2/lib/sync.js
+++ b/node_modules/pbkdf2/lib/sync.js
@@ -15,10 +15,11 @@ var defaultEncoding = require('../lib/default-encoding')
var Buffer = require('safe-buffer').Buffer
function pbkdf2 (password, salt, iterations, keylen, digest) {
+ checkParameters(password, salt, iterations, keylen)
+
if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
- checkParameters(iterations, keylen)
digest = digest || 'sha1'
var DK = Buffer.allocUnsafe(keylen)
diff --git a/node_modules/pbkdf2/package.json b/node_modules/pbkdf2/package.json
index 10a064186..4955599c3 100644
--- a/node_modules/pbkdf2/package.json
+++ b/node_modules/pbkdf2/package.json
@@ -1,6 +1,6 @@
{
"name": "pbkdf2",
- "version": "3.0.14",
+ "version": "3.0.16",
"description": "This library provides the functionality of PBKDF2 with the ability to use any supported hashing algorithm returned from crypto.getHashes()",
"keywords": [
"pbkdf2",
@@ -30,7 +30,9 @@
},
"scripts": {
"prepublish": "npm run test",
- "coverage": "nyc --check-coverage --branches 90 --functions 100 tape test/*.js",
+ "coverage-report": "nyc report --reporter=lcov",
+ "coverage-html": "nyc report --reporter=html",
+ "coverage": "nyc --check-coverage --branches 95 --functions 95 tape test/*.js",
"lint": "standard",
"test": "npm run lint && npm run unit",
"bundle-test": "browserify test/index.js > test/bundle.js",