pax_global_header 0000666 0000000 0000000 00000000064 13154546666 0014532 g ustar 00root root 0000000 0000000 52 comment=bd438b002303ad3407790b8e57b922dc2f71df4b
pbkdf2-3.0.14/ 0000775 0000000 0000000 00000000000 13154546666 0012767 5 ustar 00root root 0000000 0000000 pbkdf2-3.0.14/.gitignore 0000664 0000000 0000000 00000001104 13154546666 0014753 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
# build artifact
test/bundle.js
.nyc_output
pbkdf2-3.0.14/.travis.yml 0000664 0000000 0000000 00000000435 13154546666 0015102 0 ustar 00root root 0000000 0000000 sudo: false
language: node_js
before_install:
- npm install npm -g
node_js:
- "4"
- "5"
- "6"
- "7"
matrix:
include:
- node_js: "7"
env: TEST_SUITE=coverage
- node_js: "7"
env: TEST_SUITE=lint
env:
- TEST_SUITE=test
script: npm run-script $TEST_SUITE
pbkdf2-3.0.14/LICENSE 0000664 0000000 0000000 00000002071 13154546666 0013774 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2014 Daniel Cousens
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
pbkdf2-3.0.14/README.md 0000664 0000000 0000000 00000002637 13154546666 0014256 0 ustar 00root root 0000000 0000000 # pbkdf2
[](https://www.npmjs.org/package/pbkdf2)
[](https://travis-ci.org/crypto-browserify/pbkdf2)
[](https://david-dm.org/crypto-browserify/pbkdf2#info=dependencies)
[](https://github.com/feross/standard)
This library provides the functionality of PBKDF2 with the ability to use any supported hashing algorithm returned from `crypto.getHashes()`
## Usage
```js
var pbkdf2 = require('pbkdf2')
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).
## Credits
This module is a derivative of [cryptocoinjs/pbkdf2-sha256](https://github.com/cryptocoinjs/pbkdf2-sha256/), so thanks to [JP Richardson](https://github.com/jprichardson/) for laying the ground work.
Thank you to [FangDun Cai](https://github.com/fundon) for donating the package name on npm, if you're looking for his previous module it is located at [fundon/pbkdf2](https://github.com/fundon/pbkdf2).
pbkdf2-3.0.14/bench/ 0000775 0000000 0000000 00000000000 13154546666 0014046 5 ustar 00root root 0000000 0000000 pbkdf2-3.0.14/bench/index.js 0000664 0000000 0000000 00000001715 13154546666 0015517 0 ustar 00root root 0000000 0000000 var Benchmark = require('benchmark')
var current = require('../lib/sync')
var old = require('./old')
run('hello', 'world', 100, 32, 'md5')
run('hello', 'world', 100, 32, 'sha256')
run('hello', 'world', 10000, 70, 'md5')
run('hello', 'world', 10000, 70, 'sha256')
function run (password, salt, iterations, keylen, digest) {
var suite = new Benchmark.Suite()
console.log(`password: ${password}`)
console.log(`salt: ${salt}`)
console.log(`iterations: ${iterations}`)
console.log(`keylen: ${keylen}`)
console.log(`digest: ${digest}`)
// add tests
suite
.add('current', function () {
current(password, salt, iterations, keylen, digest)
})
.add('old', function () {
old(password, salt, iterations, keylen, digest)
})
// add listeners
.on('cycle', function (event) {
console.log(String(event.target))
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
console.log('')
}).run()
}
pbkdf2-3.0.14/bench/old.js 0000664 0000000 0000000 00000002364 13154546666 0015167 0 ustar 00root root 0000000 0000000 var createHmac = require('create-hmac')
var checkParameters = require('../lib/precondition')
var defaultEncoding = require('../lib/default-encoding')
var Buffer = require('safe-buffer').Buffer
module.exports = pbkdf2
function pbkdf2 (password, salt, iterations, keylen, digest) {
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 hLen
var l = 1
var DK = Buffer.allocUnsafe(keylen)
var block1 = Buffer.allocUnsafe(salt.length + 4)
salt.copy(block1, 0, 0, salt.length)
var r
var T
for (var i = 1; i <= l; i++) {
block1.writeUInt32BE(i, salt.length)
var U = createHmac(digest, password).update(block1).digest()
if (!hLen) {
hLen = U.length
T = Buffer.allocUnsafe(hLen)
l = Math.ceil(keylen / hLen)
r = keylen - (l - 1) * hLen
}
U.copy(T, 0, 0, hLen)
for (var j = 1; j < iterations; j++) {
U = createHmac(digest, password).update(U).digest()
for (var k = 0; k < hLen; k++) T[k] ^= U[k]
}
var destPos = (i - 1) * hLen
var len = (i === l ? r : hLen)
T.copy(DK, destPos, 0, len)
}
return DK
}
pbkdf2-3.0.14/browser.js 0000664 0000000 0000000 00000000125 13154546666 0015006 0 ustar 00root root 0000000 0000000
exports.pbkdf2 = require('./lib/async')
exports.pbkdf2Sync = require('./lib/sync')
pbkdf2-3.0.14/index.js 0000664 0000000 0000000 00000000515 13154546666 0014435 0 ustar 00root root 0000000 0000000 var crypto = require('crypto')
/* istanbul ignore next */
if (crypto && (!crypto.pbkdf2Sync || crypto.pbkdf2Sync.toString().indexOf('keylen, digest') === -1)) {
exports.pbkdf2 = require('./lib/async')
exports.pbkdf2Sync = require('./lib/sync')
} else {
exports.pbkdf2Sync = crypto.pbkdf2Sync
exports.pbkdf2 = crypto.pbkdf2
}
pbkdf2-3.0.14/lib/ 0000775 0000000 0000000 00000000000 13154546666 0013535 5 ustar 00root root 0000000 0000000 pbkdf2-3.0.14/lib/async.js 0000664 0000000 0000000 00000005166 13154546666 0015220 0 ustar 00root root 0000000 0000000 var checkParameters = require('./precondition')
var defaultEncoding = require('./default-encoding')
var sync = require('./sync')
var Buffer = require('safe-buffer').Buffer
var ZERO_BUF
var subtle = global.crypto && global.crypto.subtle
var toBrowser = {
'sha': 'SHA-1',
'sha-1': 'SHA-1',
'sha1': 'SHA-1',
'sha256': 'SHA-256',
'sha-256': 'SHA-256',
'sha384': 'SHA-384',
'sha-384': 'SHA-384',
'sha-512': 'SHA-512',
'sha512': 'SHA-512'
}
var checks = []
function checkNative (algo) {
if (global.process && !global.process.browser) {
return Promise.resolve(false)
}
if (!subtle || !subtle.importKey || !subtle.deriveBits) {
return Promise.resolve(false)
}
if (checks[algo] !== undefined) {
return checks[algo]
}
ZERO_BUF = ZERO_BUF || Buffer.alloc(8)
var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo)
.then(function () {
return true
}).catch(function () {
return false
})
checks[algo] = prom
return prom
}
function browserPbkdf2 (password, salt, iterations, length, algo) {
return subtle.importKey(
'raw', password, {name: 'PBKDF2'}, false, ['deriveBits']
).then(function (key) {
return subtle.deriveBits({
name: 'PBKDF2',
salt: salt,
iterations: iterations,
hash: {
name: algo
}
}, key, length << 3)
}).then(function (res) {
return Buffer.from(res)
})
}
function resolvePromise (promise, callback) {
promise.then(function (out) {
process.nextTick(function () {
callback(null, out)
})
}, function (e) {
process.nextTick(function () {
callback(e)
})
})
}
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
try {
out = sync(password, salt, iterations, keylen, digest)
} catch (e) {
return callback(e)
}
callback(null, out)
})
}
resolvePromise(checkNative(algo).then(function (resp) {
if (resp) {
return browserPbkdf2(password, salt, iterations, keylen, algo)
} else {
return sync(password, salt, iterations, keylen, digest)
}
}), callback)
}
pbkdf2-3.0.14/lib/default-encoding.js 0000664 0000000 0000000 00000000426 13154546666 0017305 0 ustar 00root root 0000000 0000000 var defaultEncoding
/* istanbul ignore next */
if (process.browser) {
defaultEncoding = 'utf-8'
} else {
var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
}
module.exports = defaultEncoding
pbkdf2-3.0.14/lib/precondition.js 0000664 0000000 0000000 00000000772 13154546666 0016576 0 ustar 00root root 0000000 0000000 var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
module.exports = function (iterations, keylen) {
if (typeof iterations !== 'number') {
throw new TypeError('Iterations not a number')
}
if (iterations < 0) {
throw new TypeError('Bad iterations')
}
if (typeof keylen !== 'number') {
throw new TypeError('Key length not a number')
}
if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
throw new TypeError('Bad key length')
}
}
pbkdf2-3.0.14/lib/sync-browser.js 0000664 0000000 0000000 00000004577 13154546666 0016545 0 ustar 00root root 0000000 0000000 var md5 = require('create-hash/md5')
var rmd160 = require('ripemd160')
var sha = require('sha.js')
var checkParameters = require('./precondition')
var defaultEncoding = require('./default-encoding')
var Buffer = require('safe-buffer').Buffer
var ZEROS = Buffer.alloc(128)
var sizes = {
md5: 16,
sha1: 20,
sha224: 28,
sha256: 32,
sha384: 48,
sha512: 64,
rmd160: 20,
ripemd160: 20
}
function Hmac (alg, key, saltLen) {
var hash = getDigest(alg)
var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
if (key.length > blocksize) {
key = hash(key)
} else if (key.length < blocksize) {
key = Buffer.concat([key, ZEROS], blocksize)
}
var ipad = Buffer.allocUnsafe(blocksize + sizes[alg])
var opad = Buffer.allocUnsafe(blocksize + sizes[alg])
for (var i = 0; i < blocksize; i++) {
ipad[i] = key[i] ^ 0x36
opad[i] = key[i] ^ 0x5C
}
var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4)
ipad.copy(ipad1, 0, 0, blocksize)
this.ipad1 = ipad1
this.ipad2 = ipad
this.opad = opad
this.alg = alg
this.blocksize = blocksize
this.hash = hash
this.size = sizes[alg]
}
Hmac.prototype.run = function (data, ipad) {
data.copy(ipad, this.blocksize)
var h = this.hash(ipad)
h.copy(this.opad, this.blocksize)
return this.hash(this.opad)
}
function getDigest (alg) {
function shaFunc (data) {
return sha(alg).update(data).digest()
}
if (alg === 'rmd160' || alg === 'ripemd160') return rmd160
if (alg === 'md5') return md5
return shaFunc
}
function pbkdf2 (password, salt, iterations, keylen, digest) {
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)
var DK = Buffer.allocUnsafe(keylen)
var block1 = Buffer.allocUnsafe(salt.length + 4)
salt.copy(block1, 0, 0, salt.length)
var destPos = 0
var hLen = sizes[digest]
var l = Math.ceil(keylen / hLen)
for (var i = 1; i <= l; i++) {
block1.writeUInt32BE(i, salt.length)
var T = hmac.run(block1, hmac.ipad1)
var U = T
for (var j = 1; j < iterations; j++) {
U = hmac.run(U, hmac.ipad2)
for (var k = 0; k < hLen; k++) T[k] ^= U[k]
}
T.copy(DK, destPos)
destPos += hLen
}
return DK
}
module.exports = pbkdf2
pbkdf2-3.0.14/lib/sync.js 0000664 0000000 0000000 00000002302 13154546666 0015044 0 ustar 00root root 0000000 0000000 var sizes = {
md5: 16,
sha1: 20,
sha224: 28,
sha256: 32,
sha384: 48,
sha512: 64,
rmd160: 20,
ripemd160: 20
}
var createHmac = require('create-hmac')
var checkParameters = require('../lib/precondition')
var defaultEncoding = require('../lib/default-encoding')
var Buffer = require('safe-buffer').Buffer
function pbkdf2 (password, salt, iterations, keylen, digest) {
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)
var block1 = Buffer.allocUnsafe(salt.length + 4)
salt.copy(block1, 0, 0, salt.length)
var destPos = 0
var hLen = sizes[digest]
var l = Math.ceil(keylen / hLen)
for (var i = 1; i <= l; i++) {
block1.writeUInt32BE(i, salt.length)
var T = createHmac(digest, password).update(block1).digest()
var U = T
for (var j = 1; j < iterations; j++) {
U = createHmac(digest, password).update(U).digest()
for (var k = 0; k < hLen; k++) T[k] ^= U[k]
}
T.copy(DK, destPos)
destPos += hLen
}
return DK
}
module.exports = pbkdf2
pbkdf2-3.0.14/package.json 0000664 0000000 0000000 00000003047 13154546666 0015261 0 ustar 00root root 0000000 0000000 {
"name": "pbkdf2",
"version": "3.0.14",
"description": "This library provides the functionality of PBKDF2 with the ability to use any supported hashing algorithm returned from crypto.getHashes()",
"keywords": [
"pbkdf2",
"kdf",
"salt",
"hash"
],
"homepage": "https://github.com/crypto-browserify/pbkdf2",
"bugs": {
"url": "https://github.com/crypto-browserify/pbkdf2/issues"
},
"license": "MIT",
"author": "Daniel Cousens",
"browser": {
"./index.js": "./browser.js",
"./lib/sync.js": "./lib/sync-browser.js"
},
"files": [
"browser.js",
"index.js",
"lib/"
],
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/crypto-browserify/pbkdf2.git"
},
"scripts": {
"prepublish": "npm run test",
"coverage": "nyc --check-coverage --branches 90 --functions 100 tape test/*.js",
"lint": "standard",
"test": "npm run lint && npm run unit",
"bundle-test": "browserify test/index.js > test/bundle.js",
"unit": "tape test/*.js",
"bench": "node bench/"
},
"devDependencies": {
"benchmark": "^2.1.4",
"browserify": "*",
"nyc": "^6.4.0",
"standard": "*",
"tape": "^4.5.1"
},
"dependencies": {
"create-hash": "^1.1.2",
"create-hmac": "^1.1.4",
"ripemd160": "^2.0.1",
"safe-buffer": "^5.0.1",
"sha.js": "^2.4.8"
},
"standard": {
"ignore": [
"test/bundle.js"
]
},
"engines": {
"node": ">=0.12"
},
"nyc": {
"exclude": [
"lib/async.js",
"test/bundle.js"
]
}
}
pbkdf2-3.0.14/test/ 0000775 0000000 0000000 00000000000 13154546666 0013746 5 ustar 00root root 0000000 0000000 pbkdf2-3.0.14/test/bundle.html 0000664 0000000 0000000 00000000071 13154546666 0016103 0 ustar 00root root 0000000 0000000
pbkdf2-3.0.14/test/fixtures.json 0000664 0000000 0000000 00000020436 13154546666 0016517 0 ustar 00root root 0000000 0000000 {
"valid": [
{
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": 32,
"results": {
"sha1": "0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164",
"sha256": "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b",
"sha512": "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252",
"sha224": "3c198cbdb9464b7857966bd05b7bc92bc1cc4e6e63155d4e490557fd85989497",
"sha384": "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b78676"
}
},
{
"key": "password",
"salt": "salt",
"iterations": 2,
"dkLen": 32,
"results": {
"sha1": "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957cae93136266537a8d7bf4b76",
"sha256": "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43",
"sha512": "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53c",
"sha224": "93200ffa96c5776d38fa10abdf8f5bfc0054b9718513df472d2331d2d1e66a3f",
"sha384": "54f775c6d790f21930459162fc535dbf04a939185127016a04176a0730c6f1f4"
}
},
{
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": 64,
"results": {
"sha1": "0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164ac2e7a8e3f9d2e83ace57e0d50e5e1071367c179bc86c767fc3f78ddb561363f",
"sha256": "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b4dbf3a2f3dad3377264bb7b8e8330d4efc7451418617dabef683735361cdc18c",
"sha512": "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce",
"sha224": "3c198cbdb9464b7857966bd05b7bc92bc1cc4e6e63155d4e490557fd859894978ab846d52a1083ac610c36c2c5ea8ce4a024dd691064d5453bd17b15ea1ac194",
"sha384": "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b78676b38fc800cc53ddb642f5c74442e62be44d727702213e3bb9223c53b767fbfb5d"
}
},
{
"key": "password",
"salt": "salt",
"iterations": 2,
"dkLen": 64,
"results": {
"sha1": "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957cae93136266537a8d7bf4b76c51094cc1ae010b19923ddc4395cd064acb023ffd1edd5ef4be8ffe61426c28e",
"sha256": "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43830651afcb5c862f0b249bd031f7a67520d136470f5ec271ece91c07773253d9",
"sha512": "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e",
"sha224": "93200ffa96c5776d38fa10abdf8f5bfc0054b9718513df472d2331d2d1e66a3f97b510224f700ce72581ffb10a1c99ec99a8cc1b951851a71f30d9265fccf912",
"sha384": "54f775c6d790f21930459162fc535dbf04a939185127016a04176a0730c6f1f4fb48832ad1261baadd2cedd50814b1c806ad1bbf43ebdc9d047904bf7ceafe1e"
}
},
{
"key": "password",
"salt": "salt",
"iterations": 4096,
"dkLen": 32,
"results": {
"sha1": "4b007901b765489abead49d926f721d065a429c12e463f6c4cd79401085b03db",
"sha256": "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a",
"sha512": "d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5",
"sha224": "218c453bf90635bd0a21a75d172703ff6108ef603f65bb821aedade1d6961683",
"sha384": "559726be38db125bc85ed7895f6e3cf574c7a01c080c3447db1e8a76764deb3c"
}
},
{
"key": "passwordPASSWORDpassword",
"salt": "saltSALTsaltSALTsaltSALTsaltSALTsalt",
"iterations": 4096,
"dkLen": 40,
"results": {
"sha1": "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038b6b89a48612c5a25284e6605e12329",
"sha256": "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c635518c7dac47e9",
"sha512": "8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd953",
"sha224": "056c4ba438ded91fc14e0594e6f52b87e1f3690c0dc0fbc05784ed9a754ca780e6c017e80c8de278",
"sha384": "819143ad66df9a552559b9e131c52ae6c5c1b0eed18f4d283b8c5c9eaeb92b392c147cc2d2869d58"
}
},
{
"key": "pass\u00000word",
"salt": "sa\u00000lt",
"iterations": 4096,
"dkLen": 16,
"results": {
"sha1": "345cbad979dfccb90cac5257bea6ea46",
"sha256": "1df6274d3c0bd2fc7f54fb46f149dda4",
"sha512": "336d14366099e8aac2c46c94a8f178d2",
"sha224": "0aca9ca9634db6ef4927931f633c6453",
"sha384": "b6ab6f8f6532fd9c5c30a79e1f93dcc6"
}
},
{
"keyHex": "63ffeeddccbbaa",
"salt": "salt",
"iterations": 1,
"dkLen": 32,
"results": {
"sha1": "f6635023b135a57fb8caa89ef8ad93a29d9debb1b011e6e88bffbb212de7c01c",
"sha256": "dadd4a2638c1cf90a220777bc85d81859459513eb83063e3fce7d081490f259a",
"sha512": "f69de451247225a7b30cc47632899572bb980f500d7c606ac9b1c04f928a3488",
"sha224": "9cdee023b5d5e06ccd6c5467463e34fe461a7ed43977f8237f97b0bc7ebfd280",
"sha384": "25c72b6f0e052c883a9273a54cfd41fab86759fa3b33eb7920b923abaad62f99"
}
},
{
"description": "Unicode salt, no truncation due to hex",
"key": "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
"saltHex": "6d6e656d6f6e6963e383a1e383bce38388e383abe382abe38299e3838fe38299e382a6e38299e382a1e381afe3829ae381afe38299e3818fe38299e3829de38299e381a1e381a1e38299e58d81e4babae58d81e889b2",
"iterations": 2048,
"dkLen": 64,
"results": {
"sha1": "7e042a2f41ba17e2235fbc794e22a150816b0f54a1dfe113919fccb7a056066a109385e538f183c92bad896ae8b7d8e0f4cd66df359c77c8c7785cd1001c9a2c",
"sha256": "0b57118f2b6b079d9371c94da3a8315c3ada87a1e819b40c4c4e90b36ff2d3c8fd7555538b5119ac4d3da7844aa4259d92f9dd2188e78ac33c4b08d8e6b5964b",
"sha512": "ba553eedefe76e67e2602dc20184c564010859faada929a090dd2c57aacb204ceefd15404ab50ef3e8dbeae5195aeae64b0def4d2eead1cdc728a33ced520ffd",
"sha224": "d76474c525616ce2a527d23df8d6f6fcc4251cc3535cae4e955810a51ead1ec6acbe9c9619187ca5a3c4fd636de5b5fe58d031714731290bbc081dbf0fcb8fc1",
"sha384": "15010450f456769467e834db7fa93dd9d353e8bb733b63b0621090f96599ac3316908eb64ac9366094f0787cd4bfb2fea25be41dc271a19309710db6144f9b34"
}
},
{
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": 10,
"results": {
"sha1": "0c60c80f961f0e71f3a9",
"sha256": "120fb6cffcf8b32c43e7",
"sha512": "867f70cf1ade02cff375",
"sha224": "3c198cbdb9464b785796",
"sha384": "c0e14f06e49e32d73f9f"
}
},
{
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": 100,
"results": {
"sha1": "0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164ac2e7a8e3f9d2e83ace57e0d50e5e1071367c179bc86c767fc3f78ddb561363fc692ba406d1301e42bcccc3c520d06751d78b80c3db926b16ffa3395bd697c647f280b51",
"sha256": "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b4dbf3a2f3dad3377264bb7b8e8330d4efc7451418617dabef683735361cdc18c22cd7fe60fa40e91c65849e1f60c0d8b62a7b2dbd0d3dfd75fb8498a5c2131ab02b66de5",
"sha512": "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce7b532e206c2967d4c7d2ffa460539fc4d4e5eec70125d74c6c7cf86d25284f297907fcea",
"sha224": "3c198cbdb9464b7857966bd05b7bc92bc1cc4e6e63155d4e490557fd859894978ab846d52a1083ac610c36c2c5ea8ce4a024dd691064d5453bd17b15ea1ac1944bbfd62e61b997e7b22660f588e297186572480015f33bc2bfd2b423827bcdcdb4845914",
"sha384": "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b78676b38fc800cc53ddb642f5c74442e62be44d727702213e3bb9223c53b767fbfb5db9d270d54c45d9cb6003d2967280b22671e2dbc6375f6ebf219c36f0d127be35e19d65a8"
}
}
],
"invalid": [
{
"key": "password",
"salt": "salt",
"iterations": "NaN",
"dkLen": 16,
"exception": "Iterations not a number"
},
{
"key": "password",
"salt": "salt",
"iterations": -1,
"dkLen": 16,
"exception": "Bad iterations"
},
{
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": "NaN",
"exception": "Key length not a number"
},
{
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": -1,
"exception": "Bad key length"
}
]
}
pbkdf2-3.0.14/test/index.js 0000664 0000000 0000000 00000014003 13154546666 0015411 0 ustar 00root root 0000000 0000000 // SHA-1 vectors generated by Node.js
// SHA-256/SHA-512 test vectors from:
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
// https://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors
var fixtures = require('./fixtures')
var tape = require('tape')
var Buffer = require('safe-buffer').Buffer
var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
/* istanbul ignore next */
if (pVersionMajor !== 4 || process.browser) {
fixtures.invalid.push({
'key': 'password',
'salt': 'salt',
'iterations': 1,
'dkLen': -1,
'exception': 'Bad key length'
}, {
'key': 'password',
'salt': 'salt',
'iterations': 1,
'dkLen': 4073741824,
'exception': 'Bad key length'
})
}
/* istanbul ignore next */
if (pVersionMajor >= 5 || process.browser) {
fixtures.invalid.push({
'key': 'password',
'salt': 'salt',
'iterations': 1,
'dkLen': NaN,
'exception': 'Bad key length'
}, {
'key': 'password',
'salt': 'salt',
'iterations': 1,
'dkLen': Infinity,
'exception': 'Bad key length'
})
}
/* istanbul ignore next */
if (pVersionMajor >= 6 || process.browser) {
fixtures.valid.push({
'description': 'Unicode salt, no truncation',
'key': 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'salt': 'mnemonicメートルガバヴァぱばぐゞちぢ十人十色',
'iterations': 2048,
'dkLen': 64,
'results': {
'sha1': '7e042a2f41ba17e2235fbc794e22a150816b0f54a1dfe113919fccb7a056066a109385e538f183c92bad896ae8b7d8e0f4cd66df359c77c8c7785cd1001c9a2c',
'sha256': '0b57118f2b6b079d9371c94da3a8315c3ada87a1e819b40c4c4e90b36ff2d3c8fd7555538b5119ac4d3da7844aa4259d92f9dd2188e78ac33c4b08d8e6b5964b',
'sha512': 'ba553eedefe76e67e2602dc20184c564010859faada929a090dd2c57aacb204ceefd15404ab50ef3e8dbeae5195aeae64b0def4d2eead1cdc728a33ced520ffd',
'sha224': 'd76474c525616ce2a527d23df8d6f6fcc4251cc3535cae4e955810a51ead1ec6acbe9c9619187ca5a3c4fd636de5b5fe58d031714731290bbc081dbf0fcb8fc1',
'sha384': '15010450f456769467e834db7fa93dd9d353e8bb733b63b0621090f96599ac3316908eb64ac9366094f0787cd4bfb2fea25be41dc271a19309710db6144f9b34'
}
})
// 'binary' behaviour, Node 6 defaulted to 'utf-8'
} else {
fixtures.valid.push({
'description': 'Unicode salt, suffers from truncation',
'key': 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'salt': 'mnemonicメートルガバヴァぱばぐゞちぢ十人十色',
'iterations': 2048,
'dkLen': 64,
'results': {
'sha1': 'd85d14adcb7bdb5d976160e504f520a98cf71aca4cd5fceadf37759743bd6e1d2ff78bdd4403552aef7658094384b341ede80fffd334182be076f9d988a0a40f',
'sha256': 'b86b5b900c29ed2724359afd793e10ffc1eb0e7d6f624fc9c85b8ac1785d9a2f0575af52a2338e611f2e6cffdee544adfff6f3d4f43be2ba0e2bd7e917b38a14',
'sha512': '3a863fa00f2e97a83fa9b18805e0047a6282cbae0ff48438b33a14475771c52d05137daa12e364cb34d84547ac07568b801c5c7f8dd4baaeee18a67a5c6a3377',
'sha224': '95727793842437774ad9ae27b8154a6f37f208b75a03d3a4d4a2443422bb6bc85efcfa92aa4376926ea89a8f5a63118eecdb58c8ca28ab31007da79437e0a1ef',
'sha384': '1a7e02e8ba0e357269a55642024b85738b95238d6cdc49bc440204995aefeff499e22cba76d4c7e96b7d4a9596a70e744f53fa94f3547e7dc506fcaf16ceb4a2'
}
})
}
function runTests (name, compat) {
tape(name + ' defaults to sha1 and handles buffers', function (t) {
t.plan(2)
compat.pbkdf2(Buffer.from('password'), Buffer.from('salt'), 1, 32, function (err, result) {
t.error(err)
t.equal(result.toString('hex'), '0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164')
})
})
tape(name + ' should throw if no callback is provided', function (t) {
t.plan(1)
t.throws(function () {
compat.pbkdf2('password', 'salt', 1, 32, 'sha1')
}, /No callback provided to pbkdf2/)
})
var algos = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512']
algos.forEach(function (algorithm) {
fixtures.valid.forEach(function (f) {
var key = f.key || Buffer.from(f.keyHex, 'hex')
var salt = f.salt || Buffer.from(f.saltHex, 'hex')
var expected = f.results[algorithm]
var description = algorithm + ' encodes ' + key + ' (' + f.salt + ') with ' + algorithm + ' to ' + expected
tape(name + ' async w/ ' + description, function (t) {
t.plan(2)
compat.pbkdf2(key, salt, f.iterations, f.dkLen, algorithm, function (err, result) {
t.error(err)
t.equal(result.toString('hex'), expected)
})
})
tape(name + 'sync w/ ' + description, function (t) {
t.plan(1)
var result = compat.pbkdf2Sync(key, salt, f.iterations, f.dkLen, algorithm)
t.equal(result.toString('hex'), expected)
})
})
fixtures.invalid.forEach(function (f) {
var description = algorithm + ' should throw ' + f.exception
tape(name + ' async w/ ' + description, function (t) {
t.plan(1)
/* istanbul ignore next */
function noop () {}
t.throws(function () {
compat.pbkdf2(f.key, f.salt, f.iterations, f.dkLen, f.algo, noop)
}, new RegExp(f.exception))
})
tape(name + ' sync w/' + description, function (t) {
t.plan(1)
t.throws(function () {
compat.pbkdf2Sync(f.key, f.salt, f.iterations, f.dkLen, f.algo)
}, new RegExp(f.exception))
})
})
})
tape('pbkdf2Sync defaults to sha1', function (t) {
t.plan(1)
var result = compat.pbkdf2Sync('password', 'salt', 1, 32)
t.equal(result.toString('hex'), '0c60c80f961f0e71f3a9b524af6012062fe037a6e0f0eb94fe8fc46bdc637164')
})
}
var browser = require('../browser')
runTests('JavaScript pbkdf2', browser)
/* istanbul ignore next */
if (!process.browser) {
browser.pbkdf2Sync = require('../lib/sync-browser')
runTests('browser pbkdf2', {
pbkdf2: browser.pbkdf2,
pbkdf2Sync: require('../lib/sync-browser')
})
runTests('node pbkdf2', require('../'))
}