crypto-browserify
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -33,6 +33,5 @@ var rng = require('./rng') | ||
return ['sha1', 'sha256', 'sha512', 'md5', 'rmd160'] | ||
} | ||
var p = require('./pbkdf2')(exports.createHmac) | ||
var p = require('./pbkdf2')(exports) | ||
exports.pbkdf2 = p.pbkdf2 | ||
@@ -39,0 +38,0 @@ exports.pbkdf2Sync = p.pbkdf2Sync |
@@ -5,3 +5,3 @@ { | ||
"description": "partial implementation of crypto for the browser", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"homepage": "https://github.com/dominictarr/crypto-browserify", | ||
@@ -19,2 +19,3 @@ "repository": { | ||
"dependencies": { | ||
"pbkdf2-compat": "2.0.0", | ||
"ripemd160": "0.2.0", | ||
@@ -21,0 +22,0 @@ "sha.js": "2.2.6" |
@@ -1,82 +0,12 @@ | ||
// JavaScript PBKDF2 Implementation | ||
// Based on http://git.io/qsv2zw | ||
// Licensed under LGPL v3 | ||
// Copyright (c) 2013 jduncanator | ||
var pbkdf2Export = require('pbkdf2-compat').__pbkdf2Export | ||
var blocksize = 64 | ||
var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0) | ||
module.exports = function (createHmac, exports) { | ||
module.exports = function (crypto, exports) { | ||
exports = exports || {} | ||
exports.pbkdf2 = function(password, salt, iterations, keylen, cb) { | ||
if('function' !== typeof cb) | ||
throw new Error('No callback provided to pbkdf2'); | ||
setTimeout(function () { | ||
cb(null, exports.pbkdf2Sync(password, salt, iterations, keylen)) | ||
}) | ||
} | ||
var exported = pbkdf2Export(crypto) | ||
exports.pbkdf2Sync = function(key, salt, iterations, keylen) { | ||
if('number' !== typeof iterations) | ||
throw new TypeError('Iterations not a number') | ||
if(iterations < 0) | ||
throw new TypeError('Bad iterations') | ||
if('number' !== typeof keylen) | ||
throw new TypeError('Key length not a number') | ||
if(keylen < 0) | ||
throw new TypeError('Bad key length') | ||
exports.pbkdf2 = exported.pbkdf2 | ||
exports.pbkdf2Sync = exported.pbkdf2Sync | ||
//stretch key to the correct length that hmac wants it, | ||
//otherwise this will happen every time hmac is called | ||
//twice per iteration. | ||
var key = !Buffer.isBuffer(key) ? new Buffer(key) : key | ||
if(key.length > blocksize) { | ||
key = createHash(alg).update(key).digest() | ||
} else if(key.length < blocksize) { | ||
key = Buffer.concat([key, zeroBuffer], blocksize) | ||
} | ||
var HMAC; | ||
var cplen, p = 0, i = 1, itmp = new Buffer(4), digtmp; | ||
var out = new Buffer(keylen); | ||
out.fill(0); | ||
while(keylen) { | ||
if(keylen > 20) | ||
cplen = 20; | ||
else | ||
cplen = keylen; | ||
/* We are unlikely to ever use more than 256 blocks (5120 bits!) | ||
* but just in case... | ||
*/ | ||
itmp[0] = (i >> 24) & 0xff; | ||
itmp[1] = (i >> 16) & 0xff; | ||
itmp[2] = (i >> 8) & 0xff; | ||
itmp[3] = i & 0xff; | ||
HMAC = createHmac('sha1', key); | ||
HMAC.update(salt) | ||
HMAC.update(itmp); | ||
digtmp = HMAC.digest(); | ||
digtmp.copy(out, p, 0, cplen); | ||
for(var j = 1; j < iterations; j++) { | ||
HMAC = createHmac('sha1', key); | ||
HMAC.update(digtmp); | ||
digtmp = HMAC.digest(); | ||
for(var k = 0; k < cplen; k++) { | ||
out[k] ^= digtmp[k]; | ||
} | ||
} | ||
keylen -= cplen; | ||
i++; | ||
p += cplen; | ||
} | ||
return out; | ||
} | ||
return exports | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33556
3
910
+ Addedpbkdf2-compat@2.0.0
+ Addedabbrev@1.0.9(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedasync@1.5.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addedescodegen@1.7.1(transitive)
+ Addedesprima@1.2.52.5.04.0.1(transitive)
+ Addedestraverse@1.9.3(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@1.0.7(transitive)
+ Addedfileset@0.2.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedhandlebars@4.7.8(transitive)
+ Addedhas-flag@1.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedistanbul@0.3.22(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedlevn@0.2.5(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addednopt@3.0.6(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedoptionator@0.5.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpbkdf2-compat@2.0.0(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedresolve@1.1.7(transitive)
+ Addedsource-map@0.2.00.6.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsupports-color@3.2.3(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwordwrap@0.0.31.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)