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 2.1.6 to 2.1.7

2

create-hash.js
var createHash = require('sha.js')
var md5 = toConstructor(require('./md5'))
var rmd160 = toConstructor(require('ripemd160'))

@@ -27,3 +28,4 @@ function toConstructor (fn) {

if('md5' === alg) return new md5()
if('rmd160' === alg) return new rmd160()
return createHash(alg)
}

@@ -32,2 +32,7 @@ var Buffer = require('buffer').Buffer

exports.getHashes = function () {
return ['sha1', 'sha256', 'md5', 'rmd160']
}
var p = require('./pbkdf2')(exports.createHmac)

@@ -34,0 +39,0 @@ exports.pbkdf2 = p.pbkdf2

8

md5.js

@@ -13,10 +13,2 @@ /*

/*
* Perform a simple self-test to see if the VM is working
*/
function md5_vm_test()
{
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length

@@ -23,0 +15,0 @@ */

@@ -5,3 +5,3 @@ {

"description": "partial implementation of crypto for the browser",
"version": "2.1.6",
"version": "2.1.7",
"homepage": "https://github.com/dominictarr/crypto-browserify",

@@ -19,9 +19,11 @@ "repository": {

"dependencies": {
"ripemd160": "0.2.0",
"sha.js": "2.1.3"
},
"devDependencies": {
"tape": "~2.3.2"
"tape": "~2.3.2",
"hash-test-vectors": "~1.3.0"
},
"testling": {
"files": "test/{create-hash,create-hmac,simple}.js",
"files": "test/*.js-",
"browsers": [

@@ -28,0 +30,0 @@ "ie/8..latest",

@@ -1,32 +0,32 @@

var assertSame = require('./util').same
var fs = require('fs')
var test = require('tape')
var algorithms = ['sha1', 'sha256', 'md5'];
var algorithms = require('../').getHashes()
var encodings = [/*'binary',*/ 'hex', 'base64'];
var vectors = require('hash-test-vectors')
var createHash = require('../create-hash')
algorithms.forEach(function (algorithm) {
test('test ' + algorithm + ' against test vectors', function (t) {
vectors.forEach(function (obj, i) {
var input = new Buffer(obj.input, 'base64')
var node = obj[algorithm]
var js = createHash(algorithm).update(input).digest('hex')
t.equal(js, node, algorithm + '(testVector['+i+']) == ' + node)
})
encodings.forEach(function (encoding) {
assertSame(algorithm + ' hash using ' + encoding, function (crypto, cb) {
cb(null, crypto.createHash(algorithm).update('hellø', 'utf-8').digest(encoding));
vectors.forEach(function (obj, i) {
var input = new Buffer(obj.input, 'base64').toString(encoding)
var node = obj[algorithm]
var js = createHash(algorithm).update(input, encoding).digest('hex')
t.equal(js, node, algorithm + '(testVector['+i+'], '+encoding+') == ' + node)
})
assertSame(algorithm + ' hmac using ' + encoding, function (crypto, cb) {
cb(null, crypto.createHmac(algorithm, 'secret').update('hellø', 'utf-8').digest(encoding))
})
});
assertSame(algorithm + ' with raw binary', function (crypto, cb) {
var seed = 'hellø';
for (var i = 0; i < 1000; i++) {
seed = crypto.createHash(algorithm).update(new Buffer(seed)).digest('binary');
}
cb(null, crypto.createHash(algorithm).update(new Buffer(seed)).digest('hex'));
});
assertSame(algorithm + ' empty string', function (crypto, cb) {
cb(null, crypto.createHash(algorithm).update('').digest('hex'));
});
t.end()
})
});
var same = require('./util').same
var join = require('./util').join
var test = require('tape')
var data = require('crypto').pseudoRandomBytes(256)
var algorithms = require('../').getHashes()
var vectors = require('hash-test-vectors/hmac')
var createHmac = require('../create-hmac')
;['sha1', 'sha256', 'md5'].forEach(function (alg) {
console.log('alg', alg)
;['p455w0rd', 'secretz', 'whatevs', 'such secure, wow', ''].forEach(function (pass) {
same('createHmac('+alg+', ' + JSON.stringify(pass) + ')' , function (crypto, cb) {
var r = crypto
.createHmac(alg, new Buffer(pass, 'ascii'))
.digest('hex')
console.log(r)
cb(null, r)
algorithms.forEach(function (alg) {
test('hmac('+alg+')', function (t) {
vectors.forEach(function (input, i) {
var output = createHmac(alg, new Buffer(input.key, 'hex'))
.update(input.data, 'hex').digest()
output = input.truncate ? output.slice(0, input.truncate) : output
t.equal(output.toString('hex'), input[alg])
})
t.end()
})
for(var i = 8; i < data.length; i += 7)
(function (i) {
var pass = data.slice(0, i)
same('createHmac('+alg+', pseudoRandomBytes('+ i + ')' , function (crypto, cb) {
var r = crypto
.createHmac(alg, pass)
.digest('hex')
console.log(r)
cb(null, r)
})
}(i))
})

@@ -34,0 +22,0 @@

var tape = require('tape')
var pbkdf2 = require('../').pbkdf2
var crypto = require('crypto')
var pbkdf2Sync = require('../').pbkdf2Sync
var vectors = require('hash-test-vectors/pbkdf2')
tape('pbkdf2', function (t) {
pbkdf2('hello', 'salt', 1000, 20, function (err, key) {
if(err) throw err
t.deepEqual(key.toString('hex'), crypto.pbkdf2Sync('hello', 'salt', 1000, 20).toString('hex'))
t.end()
vectors.forEach(function (input) {
//skip inputs that will take way too long
if(input.iterations > 10000) return
var key = pbkdf2Sync(input.password, input.salt, input.iterations, input.length)
if(key.toString('hex') !== input.sha1)
console.log(input)
t.equal(key.toString('hex'), input.sha1)
})
t.end()
})

Sorry, the diff of this file is not supported yet

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