Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crypto-browserify

Package Overview
Dependencies
Maintainers
1
Versions
76
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 1.0.9 to 2.0.0

create-hash.js

60

index.js
var Buffer = require('buffer').Buffer
var sha = require('./sha')
var sha256 = require('./sha256')
var rng = require('./rng')
var md5 = require('./md5')
var algorithms = {
sha1: sha,
sha256: sha256,
md5: md5
}
var blocksize = 64
var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0)
function hmac(fn, key, data) {
if(!Buffer.isBuffer(key)) key = new Buffer(key)
if(!Buffer.isBuffer(data)) data = new Buffer(data)
if(key.length > blocksize) {
key = fn(key)
} else if(key.length < blocksize) {
key = Buffer.concat([key, zeroBuffer], blocksize)
}
var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
for(var i = 0; i < blocksize; i++) {
ipad[i] = key[i] ^ 0x36
opad[i] = key[i] ^ 0x5C
}
var hash = fn(Buffer.concat([ipad, data]))
return fn(Buffer.concat([opad, hash]))
}
function hash(alg, key) {
alg = alg || 'sha1'
var fn = algorithms[alg]
var bufs = []
var length = 0
if(!fn) error('algorithm:', alg, 'is not yet supported')
return {
update: function (data) {
if(!Buffer.isBuffer(data)) data = new Buffer(data)
bufs.push(data)
length += data.length
return this
},
digest: function (enc) {
var buf = Buffer.concat(bufs)
var r = key ? hmac(fn, key, buf) : fn(buf)
bufs = null
return enc ? r.toString(enc) : r
}
}
}
function error () {

@@ -67,4 +13,6 @@ var m = [].slice.call(arguments).join(' ')

exports.createHash = function (alg) { return hash(alg) }
exports.createHmac = function (alg, key) { return hash(alg, key) }
exports.createHash = require('./create-hash')
exports.createHmac = require('./create-hmac')
exports.randomBytes = function(size, callback) {

@@ -71,0 +19,0 @@ if (callback && callback.call) {

@@ -0,0 +0,0 @@ /*

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

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

@@ -13,3 +13,3 @@ "repository": {

"scripts": {
"test": "node test/node.js"
"test": "set -e; for t in test/*.js; do node $t; done"
},

@@ -20,6 +20,6 @@ "engines": {

"dependencies": {
"sha.js": "1.3.0"
},
"devDependencies": {
"brfs": "~0.0.8",
"tape": "~1.0.4"
"tape": "~2.3.2"
},

@@ -26,0 +26,0 @@ "testling": {

@@ -7,16 +7,6 @@ var test = require('tape');

function assertSame(name, fn) {
test(name, function (t) {
t.plan(1);
fn(crypto, function (err, expected) {
fn(cryptoB, function (err, actual) {
t.equal(actual, expected);
t.end();
});
});
});
}
var assertSame = require('./util').same
var algorithms = ['sha1', 'sha256', 'md5'];
var encodings = ['binary', 'hex', 'base64'];
var encodings = [/*'binary',*/ 'hex', 'base64'];

@@ -52,18 +42,2 @@

var vectors = fs.readdirSync(__dirname + '/vectors').sort().
filter(function (t) { return t.match(/\.dat$/); }).
map(function (t) { return fs.readFileSync(__dirname + '/vectors/' + t); });
['md5', 'sha1', 'sha256'].forEach(function (algorithm) {
test(algorithm, function (t) {
function hash(data) { return cryptoB.createHash(algorithm).update(data).digest('hex'); }
var hashes = fs.readFileSync(__dirname + '/vectors/byte-hashes.' + algorithm).toString().split(/\r?\n/);
t.plan(vectors.length);
for (var i = 0; i < vectors.length; i++) {
t.equal(hash(vectors[i]), hashes[i], 'byte' + pad(i, 4) + '.dat');
}
});
});
test('randomBytes', function (t) {

@@ -70,0 +44,0 @@ t.plan(5);

@@ -6,3 +6,3 @@ var test = require("tape")

function assertSame (fn) {
function assertSame (fn, name) {
test(fn.name, function (t) {

@@ -12,3 +12,3 @@ t.plan(1)

fn(cryptoB, function (err, actual) {
t.equal(actual, expected)
t.equal(actual, expected, name)
t.end()

@@ -22,3 +22,3 @@ })

cb(null, crypto.createHash('sha1').update('hello', 'utf-8').digest('hex'))
})
}, 'sha1 same as node\'s sha1("hello")')

@@ -25,0 +25,0 @@ assertSame(function md5(crypto, cb) {

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