diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-11-21 11:29:07 +0100 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2014-01-22 15:58:07 +0400 |
commit | 74d9aa49d57d2c505d1d3712414ca245a805173d (patch) | |
tree | 70f29529c7ea4d19fe0e275b9edb2043d64f5d4a /lib/crypto.js | |
parent | e6016dae348cf105be435abf4b8b318801c09900 (diff) | |
download | android-node-v8-74d9aa49d57d2c505d1d3712414ca245a805173d.tar.gz android-node-v8-74d9aa49d57d2c505d1d3712414ca245a805173d.tar.bz2 android-node-v8-74d9aa49d57d2c505d1d3712414ca245a805173d.zip |
crypto: support custom pbkdf2 digest methods
Make the HMAC digest method configurable. Update crypto.pbkdf2() and
crypto.pbkdf2Sync() to take an extra, optional digest argument.
Before this commit, SHA-1 (admittedly the most common method) was used
exclusively.
Fixes #6553.
Diffstat (limited to 'lib/crypto.js')
-rw-r--r-- | lib/crypto.js | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/crypto.js b/lib/crypto.js index 050d54afd1..8226241490 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -575,36 +575,47 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) { -exports.pbkdf2 = function(password, salt, iterations, keylen, callback) { +exports.pbkdf2 = function(password, + salt, + iterations, + keylen, + digest, + callback) { + if (util.isFunction(digest)) { + callback = digest; + digest = undefined; + } + if (!util.isFunction(callback)) throw new Error('No callback provided to pbkdf2'); - return pbkdf2(password, salt, iterations, keylen, callback); + return pbkdf2(password, salt, iterations, keylen, digest, callback); }; -exports.pbkdf2Sync = function(password, salt, iterations, keylen) { - return pbkdf2(password, salt, iterations, keylen); +exports.pbkdf2Sync = function(password, salt, iterations, keylen, digest) { + return pbkdf2(password, salt, iterations, keylen, digest); }; -function pbkdf2(password, salt, iterations, keylen, callback) { +function pbkdf2(password, salt, iterations, keylen, digest, callback) { password = toBuf(password); salt = toBuf(salt); if (exports.DEFAULT_ENCODING === 'buffer') - return binding.PBKDF2(password, salt, iterations, keylen, callback); + return binding.PBKDF2(password, salt, iterations, keylen, digest, callback); // at this point, we need to handle encodings. var encoding = exports.DEFAULT_ENCODING; if (callback) { - binding.PBKDF2(password, salt, iterations, keylen, function(er, ret) { + function next(er, ret) { if (ret) ret = ret.toString(encoding); callback(er, ret); - }); + } + binding.PBKDF2(password, salt, iterations, keylen, digest, next); } else { - var ret = binding.PBKDF2(password, salt, iterations, keylen); + var ret = binding.PBKDF2(password, salt, iterations, keylen, digest); return ret.toString(encoding); } } |