Socket
Socket
Sign inDemoInstall

crypto-browserify

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-browserify - npm Package Compare versions

Comparing version 3.2.0 to 3.2.1

3

index.js

@@ -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
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc