diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
commit | 0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch) | |
tree | f9864d4a4148621378958794cbbfdc2393733283 /node_modules/sha.js | |
parent | 6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff) | |
download | wallet-core-0469abd4a9c9270a1fdc962969e36e63699af8b4.tar.xz |
upgrade dependencies
Diffstat (limited to 'node_modules/sha.js')
-rw-r--r-- | node_modules/sha.js/.npmignore | 2 | ||||
-rw-r--r-- | node_modules/sha.js/.travis.yml | 6 | ||||
-rw-r--r-- | node_modules/sha.js/README.md | 62 | ||||
-rwxr-xr-x | node_modules/sha.js/bin.js | 2 | ||||
-rw-r--r-- | node_modules/sha.js/hash.js | 68 | ||||
-rw-r--r-- | node_modules/sha.js/hexpp.js | 26 | ||||
-rw-r--r-- | node_modules/sha.js/package.json | 7 | ||||
-rw-r--r-- | node_modules/sha.js/sha.js | 3 | ||||
-rw-r--r-- | node_modules/sha.js/sha1.js | 3 | ||||
-rw-r--r-- | node_modules/sha.js/sha224.js | 3 | ||||
-rw-r--r-- | node_modules/sha.js/sha256.js | 3 | ||||
-rw-r--r-- | node_modules/sha.js/sha384.js | 3 | ||||
-rw-r--r-- | node_modules/sha.js/sha512.js | 3 | ||||
-rw-r--r-- | node_modules/sha.js/test/hash.js | 39 | ||||
-rw-r--r-- | node_modules/sha.js/test/test.js | 19 | ||||
-rw-r--r-- | node_modules/sha.js/test/vectors.js | 10 |
16 files changed, 119 insertions, 140 deletions
diff --git a/node_modules/sha.js/.npmignore b/node_modules/sha.js/.npmignore index 3c3629e64..2bfa6a4d9 100644 --- a/node_modules/sha.js/.npmignore +++ b/node_modules/sha.js/.npmignore @@ -1 +1 @@ -node_modules +tests/ diff --git a/node_modules/sha.js/.travis.yml b/node_modules/sha.js/.travis.yml index cbc0adb7f..0b606eb57 100644 --- a/node_modules/sha.js/.travis.yml +++ b/node_modules/sha.js/.travis.yml @@ -3,17 +3,15 @@ os: - linux language: node_js node_js: - - "0.10" - - "0.11" - - "0.12" - "4" - "5" - "6" + - "7" env: matrix: - TEST_SUITE=unit matrix: include: - - node_js: "4" + - node_js: "7" env: TEST_SUITE=lint script: npm run $TEST_SUITE diff --git a/node_modules/sha.js/README.md b/node_modules/sha.js/README.md index fbce2319b..1cc3db558 100644 --- a/node_modules/sha.js/README.md +++ b/node_modules/sha.js/README.md @@ -1,54 +1,44 @@ # sha.js +[![NPM Package](https://img.shields.io/npm/v/sha.js.svg?style=flat-square)](https://www.npmjs.org/package/sha.js) +[![Build Status](https://img.shields.io/travis/crypto-browserify/sha.js.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/sha.js) +[![Dependency status](https://img.shields.io/david/crypto-browserify/sha.js.svg?style=flat-square)](https://david-dm.org/crypto-browserify/sha.js#info=dependencies) -Streamable SHA hashes in pure javascript. +[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) -[![build status](https://secure.travis-ci.org/crypto-browserify/sha.js.png)](http://travis-ci.org/crypto-browserify/sha.js) -[![NPM](http://img.shields.io/npm/v/sha.js.svg)](https://www.npmjs.org/package/sha.js) +Node style `SHA` on pure JavaScript. +```js +var shajs = require('sha.js') -## Example - -``` js -var createHash = require('sha.js') - -var sha256 = createHash('sha256') -var sha512 = createHash('sha512') - -var h = sha256.update('abc', 'utf8').digest('hex') -console.log(h) //ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad - -//LEGACY, do not use in new systems: -var sha0 = createHash('sha') -var sha1 = createHash('sha1') - +console.log(shajs('sha256').update('42').digest('hex')) +// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049 +console.log(new shajs.sha256().update('42').digest('hex')) +// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049 +var sha256stream = shajs('sha256') +sha256stream.end('42') +console.log(sha256stream.read().toString('hex')) +// => 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049 ``` ## supported hashes +`sha.js` currently implements: -sha.js currently implements: + - SHA (SHA-0) -- **legacy, do not use in new systems** + - SHA-1 -- **legacy, do not use in new systems** + - SHA-224 + - SHA-256 + - SHA-384 + - SHA-512 -* sha256 -* sha512 -* sha1 (legacy, no not use in new systems) -* sha (legacy, no not use in new systems) - -## Note - +## Not an actual stream Note, this doesn't actually implement a stream, but wrapping this in a stream is trivial. -but is does update incrementally, so you can hash things larger than ram, and also, since it reuses -the typedarrays, it uses a constant amount of memory (except when using base64 or utf8 encoding, -see code comments) +It does update incrementally, so you can hash things larger than RAM, as it uses a constant amount of memory (except when using base64 or utf8 encoding, see code comments). ## Acknowledgements +This work is derived from Paul Johnston's [A JavaScript implementation of the Secure Hash Algorithm](http://pajhome.org.uk/crypt/md5/sha1.html). -This work is derived from Paul Johnston's ["A JavaScript implementation of the Secure Hash Algorithm"] -(http://pajhome.org.uk/crypt/md5/sha1.html) - - - -## License -MIT +## LICENSE [MIT](LICENSE) diff --git a/node_modules/sha.js/bin.js b/node_modules/sha.js/bin.js index 0a4e95bf8..5a7ac83a2 100755 --- a/node_modules/sha.js/bin.js +++ b/node_modules/sha.js/bin.js @@ -28,11 +28,9 @@ function usage () { if (!process.stdin.isTTY) { pipe(argv[0], process.stdin) - } else if (argv.length) { if (/--help|-h/.test(argv[0])) { usage() - } else { var filename = argv.pop() var algorithm = argv.pop() diff --git a/node_modules/sha.js/hash.js b/node_modules/sha.js/hash.js index 09579d2de..f7cbd0714 100644 --- a/node_modules/sha.js/hash.js +++ b/node_modules/sha.js/hash.js @@ -1,63 +1,75 @@ +var Buffer = require('safe-buffer').Buffer + // prototype class for hash functions function Hash (blockSize, finalSize) { - this._block = new Buffer(blockSize) + this._block = Buffer.alloc(blockSize) this._finalSize = finalSize this._blockSize = blockSize this._len = 0 - this._s = 0 } Hash.prototype.update = function (data, enc) { if (typeof data === 'string') { enc = enc || 'utf8' - data = new Buffer(data, enc) + data = Buffer.from(data, enc) } - var l = this._len += data.length - var s = this._s || 0 - var f = 0 - var buffer = this._block + var block = this._block + var blockSize = this._blockSize + var length = data.length + var accum = this._len - while (s < l) { - var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize)) - var ch = (t - f) + for (var offset = 0; offset < length;) { + var assigned = accum % blockSize + var remainder = Math.min(length - offset, blockSize - assigned) - for (var i = 0; i < ch; i++) { - buffer[(s % this._blockSize) + i] = data[i + f] + for (var i = 0; i < remainder; i++) { + block[assigned + i] = data[offset + i] } - s += ch - f += ch + accum += remainder + offset += remainder - if ((s % this._blockSize) === 0) { - this._update(buffer) + if ((accum % blockSize) === 0) { + this._update(block) } } - this._s = s + this._len += length return this } Hash.prototype.digest = function (enc) { - // Suppose the length of the message M, in bits, is l - var l = this._len * 8 + var rem = this._len % this._blockSize - // Append the bit 1 to the end of the message - this._block[this._len % this._blockSize] = 0x80 + this._block[rem] = 0x80 - // and then k zero bits, where k is the smallest non-negative solution to the equation (l + 1 + k) === finalSize mod blockSize - this._block.fill(0, this._len % this._blockSize + 1) + // zero (rem + 1) trailing bits, where (rem + 1) is the smallest + // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize + this._block.fill(0, rem + 1) - if (l % (this._blockSize * 8) >= this._finalSize * 8) { + if (rem >= this._finalSize) { this._update(this._block) this._block.fill(0) } - // to this append the block which is equal to the number l written in binary - // TODO: handle case where l is > Math.pow(2, 29) - this._block.writeInt32BE(l, this._blockSize - 4) + var bits = this._len * 8 + + // uint32 + if (bits <= 0xffffffff) { + this._block.writeUInt32BE(bits, this._blockSize - 4) + + // uint64 + } else { + var lowBits = bits & 0xffffffff + var highBits = (bits - lowBits) / 0x100000000 + + this._block.writeUInt32BE(highBits, this._blockSize - 8) + this._block.writeUInt32BE(lowBits, this._blockSize - 4) + } - var hash = this._update(this._block) || this._hash() + this._update(this._block) + var hash = this._hash() return enc ? hash.toString(enc) : hash } diff --git a/node_modules/sha.js/hexpp.js b/node_modules/sha.js/hexpp.js deleted file mode 100644 index 4f1e9219f..000000000 --- a/node_modules/sha.js/hexpp.js +++ /dev/null @@ -1,26 +0,0 @@ -function toHex (buf, group, wrap, LE) { - buf = buf.buffer || buf - var s = '' - var l = buf.byteLength || buf.length - for (var i = 0; i < l ; i++) { - var byteParam = (i & 0xfffffffc) | (!LE ? i % 4 : 3 - i % 4) - s += ((buf[byteParam] >> 4).toString(16)) + - ((buf[byteParam] & 0xf).toString(16)) + - (group - 1 === i % group ? ' ' : '') + - (wrap - 1 === i % wrap ? '\n' : '') - } - return s -} - -var hexpp = module.exports = function hexpp (buffer, opts) { - opts = opts || {} - opts.groups = opts.groups || 4 - opts.wrap = opts.wrap || 16 - return toHex(buffer, opts.groups, opts.wrap, opts.bigendian, opts.ints) -} - -hexpp.defaults = function (opts) { - return function (b) { - return hexpp(b, opts) - } -} diff --git a/node_modules/sha.js/package.json b/node_modules/sha.js/package.json index 2837066b5..a344cfaaa 100644 --- a/node_modules/sha.js/package.json +++ b/node_modules/sha.js/package.json @@ -1,19 +1,20 @@ { "name": "sha.js", "description": "Streamable SHA hashes in pure javascript", - "version": "2.4.8", + "version": "2.4.9", "homepage": "https://github.com/crypto-browserify/sha.js", "repository": { "type": "git", "url": "git://github.com/crypto-browserify/sha.js.git" }, "dependencies": { - "inherits": "^2.0.1" + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" }, "devDependencies": { "buffer": "~2.3.2", "hash-test-vectors": "^1.3.1", - "standard": "^4.0.0", + "standard": "^10.0.2", "tape": "~2.3.2", "typedarray": "0.0.6" }, diff --git a/node_modules/sha.js/sha.js b/node_modules/sha.js/sha.js index 7cde1b0c1..50c4fa801 100644 --- a/node_modules/sha.js/sha.js +++ b/node_modules/sha.js/sha.js @@ -8,6 +8,7 @@ var inherits = require('inherits') var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer var K = [ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 @@ -79,7 +80,7 @@ Sha.prototype._update = function (M) { } Sha.prototype._hash = function () { - var H = new Buffer(20) + var H = Buffer.allocUnsafe(20) H.writeInt32BE(this._a | 0, 0) H.writeInt32BE(this._b | 0, 4) diff --git a/node_modules/sha.js/sha1.js b/node_modules/sha.js/sha1.js index 97f6b142d..cabd747ce 100644 --- a/node_modules/sha.js/sha1.js +++ b/node_modules/sha.js/sha1.js @@ -9,6 +9,7 @@ var inherits = require('inherits') var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer var K = [ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 @@ -84,7 +85,7 @@ Sha1.prototype._update = function (M) { } Sha1.prototype._hash = function () { - var H = new Buffer(20) + var H = Buffer.allocUnsafe(20) H.writeInt32BE(this._a | 0, 0) H.writeInt32BE(this._b | 0, 4) diff --git a/node_modules/sha.js/sha224.js b/node_modules/sha.js/sha224.js index 31899ef48..35541e575 100644 --- a/node_modules/sha.js/sha224.js +++ b/node_modules/sha.js/sha224.js @@ -9,6 +9,7 @@ var inherits = require('inherits') var Sha256 = require('./sha256') var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer var W = new Array(64) @@ -36,7 +37,7 @@ Sha224.prototype.init = function () { } Sha224.prototype._hash = function () { - var H = new Buffer(28) + var H = Buffer.allocUnsafe(28) H.writeInt32BE(this._a, 0) H.writeInt32BE(this._b, 4) diff --git a/node_modules/sha.js/sha256.js b/node_modules/sha.js/sha256.js index 69b60fef0..342e48aee 100644 --- a/node_modules/sha.js/sha256.js +++ b/node_modules/sha.js/sha256.js @@ -8,6 +8,7 @@ var inherits = require('inherits') var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer var K = [ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, @@ -117,7 +118,7 @@ Sha256.prototype._update = function (M) { } Sha256.prototype._hash = function () { - var H = new Buffer(32) + var H = Buffer.allocUnsafe(32) H.writeInt32BE(this._a, 0) H.writeInt32BE(this._b, 4) diff --git a/node_modules/sha.js/sha384.js b/node_modules/sha.js/sha384.js index dc483120c..afc85e51f 100644 --- a/node_modules/sha.js/sha384.js +++ b/node_modules/sha.js/sha384.js @@ -1,6 +1,7 @@ var inherits = require('inherits') var SHA512 = require('./sha512') var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer var W = new Array(160) @@ -36,7 +37,7 @@ Sha384.prototype.init = function () { } Sha384.prototype._hash = function () { - var H = new Buffer(48) + var H = Buffer.allocUnsafe(48) function writeInt64BE (h, l, offset) { H.writeInt32BE(h, offset) diff --git a/node_modules/sha.js/sha512.js b/node_modules/sha.js/sha512.js index 204a7b830..fb28f2f6b 100644 --- a/node_modules/sha.js/sha512.js +++ b/node_modules/sha.js/sha512.js @@ -1,5 +1,6 @@ var inherits = require('inherits') var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer var K = [ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, @@ -237,7 +238,7 @@ Sha512.prototype._update = function (M) { } Sha512.prototype._hash = function () { - var H = new Buffer(64) + var H = Buffer.allocUnsafe(64) function writeInt64BE (h, l, offset) { H.writeInt32BE(h, offset) diff --git a/node_modules/sha.js/test/hash.js b/node_modules/sha.js/test/hash.js index 2f376b4d9..5fa000d5a 100644 --- a/node_modules/sha.js/test/hash.js +++ b/node_modules/sha.js/test/hash.js @@ -1,73 +1,62 @@ -var hexpp = require('../hexpp').defaults({ bigendian: false }) var tape = require('tape') var Hash = require('../hash') - var hex = '0A1B2C3D4E5F6G7H' function equal (t, a, b) { t.equal(a.length, b.length) - - for (var i = 0; i < a.length; i++) { - t.equal(a[i], b[i]) - } + t.equal(a.toString('hex'), b.toString('hex')) } -var hexBuf = new Buffer([48, 65, 49, 66, 50, 67, 51, 68, 52, 69, 53, 70, 54, 71, 55, 72]) +var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8') var count16 = { strings: ['0A1B2C3D4E5F6G7H'], buffers: [ hexBuf, - new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]) + Buffer.from('80000000000000000000000000000080', 'hex') ] } var empty = { strings: [''], buffers: [ - new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]) + Buffer.from('80000000000000000000000000000000', 'hex') ] } var multi = { - strings: ['abcd', 'efhijk', 'lmnopq'], - buffers: [ - new Buffer('abcdefhijklmnopq', 'ascii'), - new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]) - ] - } + strings: ['abcd', 'efhijk', 'lmnopq'], + buffers: [ + Buffer.from('abcdefhijklmnopq', 'ascii'), + Buffer.from('80000000000000000000000000000080', 'hex') + ] +} var long = { strings: [hex + hex], buffers: [ hexBuf, hexBuf, - new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]) + Buffer.from('80000000000000000000000000000100', 'hex') ] } function makeTest (name, data) { tape(name, function (t) { - var h = new Hash(16, 8) - var hash = new Buffer(20) + var hash = Buffer.alloc(20) var n = 2 var expected = data.buffers.slice() // t.plan(expected.length + 1) h._update = function (block) { var e = expected.shift() - - console.log('---block---') - console.log(hexpp(block), block.length) - console.log('---e---') - console.log(hexpp(e), block.length) - console.log(block) equal(t, block, e) if (n < 0) { throw new Error('expecting only 2 calls to _update') } - + } + h._hash = function () { return hash } diff --git a/node_modules/sha.js/test/test.js b/node_modules/sha.js/test/test.js index 0a46e44be..623899ddb 100644 --- a/node_modules/sha.js/test/test.js +++ b/node_modules/sha.js/test/test.js @@ -71,8 +71,8 @@ tape('hex encoding', function (t) { for (var i = 0; i < v[0].length; i = (i + 1) * 2) { var s = v[0].substring(i, (i + 1) * 2) - hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex') - _hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex') + hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex') + _hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex') } var a = hash.digest('hex') var e = _hash.digest('hex') @@ -83,3 +83,18 @@ tape('hex encoding', function (t) { t.end() }) + +tape('call digest for more than MAX_UINT32 bits of data', function (t) { + var _hash = crypto.createHash('sha1') + var hash = new Sha1() + var bigData = Buffer.alloc(Math.pow(2, 32) / 8) + + hash.update(bigData) + _hash.update(bigData) + + var a = hash.digest('hex') + var e = _hash.digest('hex') + + t.equal(a, e) + t.end() +}) diff --git a/node_modules/sha.js/test/vectors.js b/node_modules/sha.js/test/vectors.js index 4aef39cc3..48a646ef6 100644 --- a/node_modules/sha.js/test/vectors.js +++ b/node_modules/sha.js/test/vectors.js @@ -1,8 +1,7 @@ var tape = require('tape') var vectors = require('hash-test-vectors') // var from = require('bops/typedarray/from') -var Buffer = require('buffer').Buffer -var hexpp = require('../hexpp') +var Buffer = require('safe-buffer').Buffer var createHash = require('../') @@ -14,11 +13,10 @@ function makeTest (alg, i, verbose) { console.log(v) console.log('VECTOR', i) console.log('INPUT', v.input) - console.log(hexpp(new Buffer(v.input, 'base64'))) - console.log(new Buffer(v.input, 'base64').toString('hex')) + console.log(Buffer.from(v.input, 'base64').toString('hex')) } - var buf = new Buffer(v.input, 'base64') + var buf = Buffer.from(v.input, 'base64') t.equal(createHash(alg).update(buf).digest('hex'), v[alg]) i = ~~(buf.length / 2) @@ -58,12 +56,10 @@ function makeTest (alg, i, verbose) { t.end() }) }) - } if (process.argv[2]) { makeTest(process.argv[2], parseInt(process.argv[3], 10), true) - } else { vectors.forEach(function (v, i) { makeTest('sha', i) |