aboutsummaryrefslogtreecommitdiff
path: root/node_modules/sha.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/sha.js
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
downloadwallet-core-de98e0b232509d5f40c135d540a70e415272ff85.tar.xz
node_modules
Diffstat (limited to 'node_modules/sha.js')
-rw-r--r--node_modules/sha.js/.npmignore1
-rw-r--r--node_modules/sha.js/.travis.yml19
-rw-r--r--node_modules/sha.js/LICENSE22
-rw-r--r--node_modules/sha.js/README.md54
-rwxr-xr-xnode_modules/sha.js/bin.js43
-rw-r--r--node_modules/sha.js/hash.js69
-rw-r--r--node_modules/sha.js/hexpp.js26
-rw-r--r--node_modules/sha.js/index.js15
-rw-r--r--node_modules/sha.js/package.json29
-rw-r--r--node_modules/sha.js/sha.js93
-rw-r--r--node_modules/sha.js/sha1.js98
-rw-r--r--node_modules/sha.js/sha224.js52
-rw-r--r--node_modules/sha.js/sha256.js134
-rw-r--r--node_modules/sha.js/sha384.js56
-rw-r--r--node_modules/sha.js/sha512.js259
-rw-r--r--node_modules/sha.js/test/hash.js86
-rw-r--r--node_modules/sha.js/test/test.js85
-rw-r--r--node_modules/sha.js/test/vectors.js76
18 files changed, 1217 insertions, 0 deletions
diff --git a/node_modules/sha.js/.npmignore b/node_modules/sha.js/.npmignore
new file mode 100644
index 000000000..3c3629e64
--- /dev/null
+++ b/node_modules/sha.js/.npmignore
@@ -0,0 +1 @@
+node_modules
diff --git a/node_modules/sha.js/.travis.yml b/node_modules/sha.js/.travis.yml
new file mode 100644
index 000000000..cbc0adb7f
--- /dev/null
+++ b/node_modules/sha.js/.travis.yml
@@ -0,0 +1,19 @@
+sudo: false
+os:
+ - linux
+language: node_js
+node_js:
+ - "0.10"
+ - "0.11"
+ - "0.12"
+ - "4"
+ - "5"
+ - "6"
+env:
+ matrix:
+ - TEST_SUITE=unit
+matrix:
+ include:
+ - node_js: "4"
+ env: TEST_SUITE=lint
+script: npm run $TEST_SUITE
diff --git a/node_modules/sha.js/LICENSE b/node_modules/sha.js/LICENSE
new file mode 100644
index 000000000..92ba9d30d
--- /dev/null
+++ b/node_modules/sha.js/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2013-2014 sha.js contributors
+
+Permission is hereby granted, free of charge,
+to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to
+deal in the Software without restriction, including
+without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom
+the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/sha.js/README.md b/node_modules/sha.js/README.md
new file mode 100644
index 000000000..fbce2319b
--- /dev/null
+++ b/node_modules/sha.js/README.md
@@ -0,0 +1,54 @@
+# sha.js
+
+Streamable SHA hashes in pure javascript.
+
+[![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)
+
+
+## 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')
+
+
+```
+
+## supported hashes
+
+sha.js currently implements:
+
+
+* sha256
+* sha512
+* sha1 (legacy, no not use in new systems)
+* sha (legacy, no not use in new systems)
+
+## Note
+
+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)
+
+
+## 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)
+
+
+
+## License
+
+MIT
diff --git a/node_modules/sha.js/bin.js b/node_modules/sha.js/bin.js
new file mode 100755
index 000000000..0a4e95bf8
--- /dev/null
+++ b/node_modules/sha.js/bin.js
@@ -0,0 +1,43 @@
+#! /usr/bin/env node
+
+var createHash = require('./browserify')
+var argv = process.argv.slice(2)
+
+function pipe (algorithm, s) {
+ var start = Date.now()
+ var hash = createHash(algorithm || 'sha1')
+
+ s.on('data', function (data) {
+ hash.update(data)
+ })
+
+ s.on('end', function () {
+ if (process.env.DEBUG) {
+ return console.log(hash.digest('hex'), Date.now() - start)
+ }
+
+ console.log(hash.digest('hex'))
+ })
+}
+
+function usage () {
+ console.error('sha.js [algorithm=sha1] [filename] # hash filename with algorithm')
+ console.error('input | sha.js [algorithm=sha1] # hash stdin with algorithm')
+ console.error('sha.js --help # display this message')
+}
+
+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()
+ pipe(algorithm, require('fs').createReadStream(filename))
+ }
+} else {
+ usage()
+}
diff --git a/node_modules/sha.js/hash.js b/node_modules/sha.js/hash.js
new file mode 100644
index 000000000..09579d2de
--- /dev/null
+++ b/node_modules/sha.js/hash.js
@@ -0,0 +1,69 @@
+// prototype class for hash functions
+function Hash (blockSize, finalSize) {
+ this._block = new Buffer(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)
+ }
+
+ var l = this._len += data.length
+ var s = this._s || 0
+ var f = 0
+ var buffer = this._block
+
+ while (s < l) {
+ var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
+ var ch = (t - f)
+
+ for (var i = 0; i < ch; i++) {
+ buffer[(s % this._blockSize) + i] = data[i + f]
+ }
+
+ s += ch
+ f += ch
+
+ if ((s % this._blockSize) === 0) {
+ this._update(buffer)
+ }
+ }
+ this._s = s
+
+ return this
+}
+
+Hash.prototype.digest = function (enc) {
+ // Suppose the length of the message M, in bits, is l
+ var l = this._len * 8
+
+ // Append the bit 1 to the end of the message
+ this._block[this._len % this._blockSize] = 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)
+
+ if (l % (this._blockSize * 8) >= this._finalSize * 8) {
+ 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 hash = this._update(this._block) || this._hash()
+
+ return enc ? hash.toString(enc) : hash
+}
+
+Hash.prototype._update = function () {
+ throw new Error('_update must be implemented by subclass')
+}
+
+module.exports = Hash
diff --git a/node_modules/sha.js/hexpp.js b/node_modules/sha.js/hexpp.js
new file mode 100644
index 000000000..4f1e9219f
--- /dev/null
+++ b/node_modules/sha.js/hexpp.js
@@ -0,0 +1,26 @@
+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/index.js b/node_modules/sha.js/index.js
new file mode 100644
index 000000000..87cdf4939
--- /dev/null
+++ b/node_modules/sha.js/index.js
@@ -0,0 +1,15 @@
+var exports = module.exports = function SHA (algorithm) {
+ algorithm = algorithm.toLowerCase()
+
+ var Algorithm = exports[algorithm]
+ if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
+
+ return new Algorithm()
+}
+
+exports.sha = require('./sha')
+exports.sha1 = require('./sha1')
+exports.sha224 = require('./sha224')
+exports.sha256 = require('./sha256')
+exports.sha384 = require('./sha384')
+exports.sha512 = require('./sha512')
diff --git a/node_modules/sha.js/package.json b/node_modules/sha.js/package.json
new file mode 100644
index 000000000..2837066b5
--- /dev/null
+++ b/node_modules/sha.js/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "sha.js",
+ "description": "Streamable SHA hashes in pure javascript",
+ "version": "2.4.8",
+ "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"
+ },
+ "devDependencies": {
+ "buffer": "~2.3.2",
+ "hash-test-vectors": "^1.3.1",
+ "standard": "^4.0.0",
+ "tape": "~2.3.2",
+ "typedarray": "0.0.6"
+ },
+ "bin": "./bin.js",
+ "scripts": {
+ "prepublish": "npm ls && npm run unit",
+ "lint": "standard",
+ "test": "npm run lint && npm run unit",
+ "unit": "set -e; for t in test/*.js; do node $t; done;"
+ },
+ "author": "Dominic Tarr <dominic.tarr@gmail.com> (dominictarr.com)",
+ "license": "MIT"
+}
diff --git a/node_modules/sha.js/sha.js b/node_modules/sha.js/sha.js
new file mode 100644
index 000000000..7cde1b0c1
--- /dev/null
+++ b/node_modules/sha.js/sha.js
@@ -0,0 +1,93 @@
+/*
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
+ * in FIPS PUB 180-1
+ * This source code is derived from sha1.js of the same repository.
+ * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
+ * operation was added.
+ */
+
+var inherits = require('inherits')
+var Hash = require('./hash')
+
+var K = [
+ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
+]
+
+var W = new Array(80)
+
+function Sha () {
+ this.init()
+ this._w = W
+
+ Hash.call(this, 64, 56)
+}
+
+inherits(Sha, Hash)
+
+Sha.prototype.init = function () {
+ this._a = 0x67452301
+ this._b = 0xefcdab89
+ this._c = 0x98badcfe
+ this._d = 0x10325476
+ this._e = 0xc3d2e1f0
+
+ return this
+}
+
+function rotl5 (num) {
+ return (num << 5) | (num >>> 27)
+}
+
+function rotl30 (num) {
+ return (num << 30) | (num >>> 2)
+}
+
+function ft (s, b, c, d) {
+ if (s === 0) return (b & c) | ((~b) & d)
+ if (s === 2) return (b & c) | (b & d) | (c & d)
+ return b ^ c ^ d
+}
+
+Sha.prototype._update = function (M) {
+ var W = this._w
+
+ var a = this._a | 0
+ var b = this._b | 0
+ var c = this._c | 0
+ var d = this._d | 0
+ var e = this._e | 0
+
+ for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
+ for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
+
+ for (var j = 0; j < 80; ++j) {
+ var s = ~~(j / 20)
+ var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
+
+ e = d
+ d = c
+ c = rotl30(b)
+ b = a
+ a = t
+ }
+
+ this._a = (a + this._a) | 0
+ this._b = (b + this._b) | 0
+ this._c = (c + this._c) | 0
+ this._d = (d + this._d) | 0
+ this._e = (e + this._e) | 0
+}
+
+Sha.prototype._hash = function () {
+ var H = new Buffer(20)
+
+ H.writeInt32BE(this._a | 0, 0)
+ H.writeInt32BE(this._b | 0, 4)
+ H.writeInt32BE(this._c | 0, 8)
+ H.writeInt32BE(this._d | 0, 12)
+ H.writeInt32BE(this._e | 0, 16)
+
+ return H
+}
+
+module.exports = Sha
diff --git a/node_modules/sha.js/sha1.js b/node_modules/sha.js/sha1.js
new file mode 100644
index 000000000..97f6b142d
--- /dev/null
+++ b/node_modules/sha.js/sha1.js
@@ -0,0 +1,98 @@
+/*
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
+ * in FIPS PUB 180-1
+ * Version 2.1a Copyright Paul Johnston 2000 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ */
+
+var inherits = require('inherits')
+var Hash = require('./hash')
+
+var K = [
+ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
+]
+
+var W = new Array(80)
+
+function Sha1 () {
+ this.init()
+ this._w = W
+
+ Hash.call(this, 64, 56)
+}
+
+inherits(Sha1, Hash)
+
+Sha1.prototype.init = function () {
+ this._a = 0x67452301
+ this._b = 0xefcdab89
+ this._c = 0x98badcfe
+ this._d = 0x10325476
+ this._e = 0xc3d2e1f0
+
+ return this
+}
+
+function rotl1 (num) {
+ return (num << 1) | (num >>> 31)
+}
+
+function rotl5 (num) {
+ return (num << 5) | (num >>> 27)
+}
+
+function rotl30 (num) {
+ return (num << 30) | (num >>> 2)
+}
+
+function ft (s, b, c, d) {
+ if (s === 0) return (b & c) | ((~b) & d)
+ if (s === 2) return (b & c) | (b & d) | (c & d)
+ return b ^ c ^ d
+}
+
+Sha1.prototype._update = function (M) {
+ var W = this._w
+
+ var a = this._a | 0
+ var b = this._b | 0
+ var c = this._c | 0
+ var d = this._d | 0
+ var e = this._e | 0
+
+ for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
+ for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
+
+ for (var j = 0; j < 80; ++j) {
+ var s = ~~(j / 20)
+ var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
+
+ e = d
+ d = c
+ c = rotl30(b)
+ b = a
+ a = t
+ }
+
+ this._a = (a + this._a) | 0
+ this._b = (b + this._b) | 0
+ this._c = (c + this._c) | 0
+ this._d = (d + this._d) | 0
+ this._e = (e + this._e) | 0
+}
+
+Sha1.prototype._hash = function () {
+ var H = new Buffer(20)
+
+ H.writeInt32BE(this._a | 0, 0)
+ H.writeInt32BE(this._b | 0, 4)
+ H.writeInt32BE(this._c | 0, 8)
+ H.writeInt32BE(this._d | 0, 12)
+ H.writeInt32BE(this._e | 0, 16)
+
+ return H
+}
+
+module.exports = Sha1
diff --git a/node_modules/sha.js/sha224.js b/node_modules/sha.js/sha224.js
new file mode 100644
index 000000000..31899ef48
--- /dev/null
+++ b/node_modules/sha.js/sha224.js
@@ -0,0 +1,52 @@
+/**
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
+ * in FIPS 180-2
+ * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ *
+ */
+
+var inherits = require('inherits')
+var Sha256 = require('./sha256')
+var Hash = require('./hash')
+
+var W = new Array(64)
+
+function Sha224 () {
+ this.init()
+
+ this._w = W // new Array(64)
+
+ Hash.call(this, 64, 56)
+}
+
+inherits(Sha224, Sha256)
+
+Sha224.prototype.init = function () {
+ this._a = 0xc1059ed8
+ this._b = 0x367cd507
+ this._c = 0x3070dd17
+ this._d = 0xf70e5939
+ this._e = 0xffc00b31
+ this._f = 0x68581511
+ this._g = 0x64f98fa7
+ this._h = 0xbefa4fa4
+
+ return this
+}
+
+Sha224.prototype._hash = function () {
+ var H = new Buffer(28)
+
+ H.writeInt32BE(this._a, 0)
+ H.writeInt32BE(this._b, 4)
+ H.writeInt32BE(this._c, 8)
+ H.writeInt32BE(this._d, 12)
+ H.writeInt32BE(this._e, 16)
+ H.writeInt32BE(this._f, 20)
+ H.writeInt32BE(this._g, 24)
+
+ return H
+}
+
+module.exports = Sha224
diff --git a/node_modules/sha.js/sha256.js b/node_modules/sha.js/sha256.js
new file mode 100644
index 000000000..69b60fef0
--- /dev/null
+++ b/node_modules/sha.js/sha256.js
@@ -0,0 +1,134 @@
+/**
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
+ * in FIPS 180-2
+ * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ *
+ */
+
+var inherits = require('inherits')
+var Hash = require('./hash')
+
+var K = [
+ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
+ 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
+ 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
+ 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
+ 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
+ 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
+ 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
+ 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
+ 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
+ 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
+ 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
+ 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
+ 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
+ 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
+ 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
+ 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
+]
+
+var W = new Array(64)
+
+function Sha256 () {
+ this.init()
+
+ this._w = W // new Array(64)
+
+ Hash.call(this, 64, 56)
+}
+
+inherits(Sha256, Hash)
+
+Sha256.prototype.init = function () {
+ this._a = 0x6a09e667
+ this._b = 0xbb67ae85
+ this._c = 0x3c6ef372
+ this._d = 0xa54ff53a
+ this._e = 0x510e527f
+ this._f = 0x9b05688c
+ this._g = 0x1f83d9ab
+ this._h = 0x5be0cd19
+
+ return this
+}
+
+function ch (x, y, z) {
+ return z ^ (x & (y ^ z))
+}
+
+function maj (x, y, z) {
+ return (x & y) | (z & (x | y))
+}
+
+function sigma0 (x) {
+ return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
+}
+
+function sigma1 (x) {
+ return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
+}
+
+function gamma0 (x) {
+ return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
+}
+
+function gamma1 (x) {
+ return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
+}
+
+Sha256.prototype._update = function (M) {
+ var W = this._w
+
+ var a = this._a | 0
+ var b = this._b | 0
+ var c = this._c | 0
+ var d = this._d | 0
+ var e = this._e | 0
+ var f = this._f | 0
+ var g = this._g | 0
+ var h = this._h | 0
+
+ for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
+ for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
+
+ for (var j = 0; j < 64; ++j) {
+ var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
+ var T2 = (sigma0(a) + maj(a, b, c)) | 0
+
+ h = g
+ g = f
+ f = e
+ e = (d + T1) | 0
+ d = c
+ c = b
+ b = a
+ a = (T1 + T2) | 0
+ }
+
+ this._a = (a + this._a) | 0
+ this._b = (b + this._b) | 0
+ this._c = (c + this._c) | 0
+ this._d = (d + this._d) | 0
+ this._e = (e + this._e) | 0
+ this._f = (f + this._f) | 0
+ this._g = (g + this._g) | 0
+ this._h = (h + this._h) | 0
+}
+
+Sha256.prototype._hash = function () {
+ var H = new Buffer(32)
+
+ H.writeInt32BE(this._a, 0)
+ H.writeInt32BE(this._b, 4)
+ H.writeInt32BE(this._c, 8)
+ H.writeInt32BE(this._d, 12)
+ H.writeInt32BE(this._e, 16)
+ H.writeInt32BE(this._f, 20)
+ H.writeInt32BE(this._g, 24)
+ H.writeInt32BE(this._h, 28)
+
+ return H
+}
+
+module.exports = Sha256
diff --git a/node_modules/sha.js/sha384.js b/node_modules/sha.js/sha384.js
new file mode 100644
index 000000000..dc483120c
--- /dev/null
+++ b/node_modules/sha.js/sha384.js
@@ -0,0 +1,56 @@
+var inherits = require('inherits')
+var SHA512 = require('./sha512')
+var Hash = require('./hash')
+
+var W = new Array(160)
+
+function Sha384 () {
+ this.init()
+ this._w = W
+
+ Hash.call(this, 128, 112)
+}
+
+inherits(Sha384, SHA512)
+
+Sha384.prototype.init = function () {
+ this._ah = 0xcbbb9d5d
+ this._bh = 0x629a292a
+ this._ch = 0x9159015a
+ this._dh = 0x152fecd8
+ this._eh = 0x67332667
+ this._fh = 0x8eb44a87
+ this._gh = 0xdb0c2e0d
+ this._hh = 0x47b5481d
+
+ this._al = 0xc1059ed8
+ this._bl = 0x367cd507
+ this._cl = 0x3070dd17
+ this._dl = 0xf70e5939
+ this._el = 0xffc00b31
+ this._fl = 0x68581511
+ this._gl = 0x64f98fa7
+ this._hl = 0xbefa4fa4
+
+ return this
+}
+
+Sha384.prototype._hash = function () {
+ var H = new Buffer(48)
+
+ function writeInt64BE (h, l, offset) {
+ H.writeInt32BE(h, offset)
+ H.writeInt32BE(l, offset + 4)
+ }
+
+ writeInt64BE(this._ah, this._al, 0)
+ writeInt64BE(this._bh, this._bl, 8)
+ writeInt64BE(this._ch, this._cl, 16)
+ writeInt64BE(this._dh, this._dl, 24)
+ writeInt64BE(this._eh, this._el, 32)
+ writeInt64BE(this._fh, this._fl, 40)
+
+ return H
+}
+
+module.exports = Sha384
diff --git a/node_modules/sha.js/sha512.js b/node_modules/sha.js/sha512.js
new file mode 100644
index 000000000..204a7b830
--- /dev/null
+++ b/node_modules/sha.js/sha512.js
@@ -0,0 +1,259 @@
+var inherits = require('inherits')
+var Hash = require('./hash')
+
+var K = [
+ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
+ 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
+ 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
+ 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
+ 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
+ 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
+ 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
+ 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
+ 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
+ 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
+ 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
+ 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
+ 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
+ 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
+ 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
+ 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
+ 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
+ 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
+ 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
+ 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
+ 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
+ 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
+ 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
+ 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
+ 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
+ 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
+ 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
+ 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
+ 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
+ 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
+ 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
+ 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
+ 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
+ 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
+ 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
+ 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
+ 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
+ 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
+ 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
+ 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
+]
+
+var W = new Array(160)
+
+function Sha512 () {
+ this.init()
+ this._w = W
+
+ Hash.call(this, 128, 112)
+}
+
+inherits(Sha512, Hash)
+
+Sha512.prototype.init = function () {
+ this._ah = 0x6a09e667
+ this._bh = 0xbb67ae85
+ this._ch = 0x3c6ef372
+ this._dh = 0xa54ff53a
+ this._eh = 0x510e527f
+ this._fh = 0x9b05688c
+ this._gh = 0x1f83d9ab
+ this._hh = 0x5be0cd19
+
+ this._al = 0xf3bcc908
+ this._bl = 0x84caa73b
+ this._cl = 0xfe94f82b
+ this._dl = 0x5f1d36f1
+ this._el = 0xade682d1
+ this._fl = 0x2b3e6c1f
+ this._gl = 0xfb41bd6b
+ this._hl = 0x137e2179
+
+ return this
+}
+
+function Ch (x, y, z) {
+ return z ^ (x & (y ^ z))
+}
+
+function maj (x, y, z) {
+ return (x & y) | (z & (x | y))
+}
+
+function sigma0 (x, xl) {
+ return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
+}
+
+function sigma1 (x, xl) {
+ return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
+}
+
+function Gamma0 (x, xl) {
+ return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
+}
+
+function Gamma0l (x, xl) {
+ return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
+}
+
+function Gamma1 (x, xl) {
+ return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
+}
+
+function Gamma1l (x, xl) {
+ return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
+}
+
+function getCarry (a, b) {
+ return (a >>> 0) < (b >>> 0) ? 1 : 0
+}
+
+Sha512.prototype._update = function (M) {
+ var W = this._w
+
+ var ah = this._ah | 0
+ var bh = this._bh | 0
+ var ch = this._ch | 0
+ var dh = this._dh | 0
+ var eh = this._eh | 0
+ var fh = this._fh | 0
+ var gh = this._gh | 0
+ var hh = this._hh | 0
+
+ var al = this._al | 0
+ var bl = this._bl | 0
+ var cl = this._cl | 0
+ var dl = this._dl | 0
+ var el = this._el | 0
+ var fl = this._fl | 0
+ var gl = this._gl | 0
+ var hl = this._hl | 0
+
+ for (var i = 0; i < 32; i += 2) {
+ W[i] = M.readInt32BE(i * 4)
+ W[i + 1] = M.readInt32BE(i * 4 + 4)
+ }
+ for (; i < 160; i += 2) {
+ var xh = W[i - 15 * 2]
+ var xl = W[i - 15 * 2 + 1]
+ var gamma0 = Gamma0(xh, xl)
+ var gamma0l = Gamma0l(xl, xh)
+
+ xh = W[i - 2 * 2]
+ xl = W[i - 2 * 2 + 1]
+ var gamma1 = Gamma1(xh, xl)
+ var gamma1l = Gamma1l(xl, xh)
+
+ // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
+ var Wi7h = W[i - 7 * 2]
+ var Wi7l = W[i - 7 * 2 + 1]
+
+ var Wi16h = W[i - 16 * 2]
+ var Wi16l = W[i - 16 * 2 + 1]
+
+ var Wil = (gamma0l + Wi7l) | 0
+ var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
+ Wil = (Wil + gamma1l) | 0
+ Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
+ Wil = (Wil + Wi16l) | 0
+ Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
+
+ W[i] = Wih
+ W[i + 1] = Wil
+ }
+
+ for (var j = 0; j < 160; j += 2) {
+ Wih = W[j]
+ Wil = W[j + 1]
+
+ var majh = maj(ah, bh, ch)
+ var majl = maj(al, bl, cl)
+
+ var sigma0h = sigma0(ah, al)
+ var sigma0l = sigma0(al, ah)
+ var sigma1h = sigma1(eh, el)
+ var sigma1l = sigma1(el, eh)
+
+ // t1 = h + sigma1 + ch + K[j] + W[j]
+ var Kih = K[j]
+ var Kil = K[j + 1]
+
+ var chh = Ch(eh, fh, gh)
+ var chl = Ch(el, fl, gl)
+
+ var t1l = (hl + sigma1l) | 0
+ var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
+ t1l = (t1l + chl) | 0
+ t1h = (t1h + chh + getCarry(t1l, chl)) | 0
+ t1l = (t1l + Kil) | 0
+ t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
+ t1l = (t1l + Wil) | 0
+ t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
+
+ // t2 = sigma0 + maj
+ var t2l = (sigma0l + majl) | 0
+ var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
+
+ hh = gh
+ hl = gl
+ gh = fh
+ gl = fl
+ fh = eh
+ fl = el
+ el = (dl + t1l) | 0
+ eh = (dh + t1h + getCarry(el, dl)) | 0
+ dh = ch
+ dl = cl
+ ch = bh
+ cl = bl
+ bh = ah
+ bl = al
+ al = (t1l + t2l) | 0
+ ah = (t1h + t2h + getCarry(al, t1l)) | 0
+ }
+
+ this._al = (this._al + al) | 0
+ this._bl = (this._bl + bl) | 0
+ this._cl = (this._cl + cl) | 0
+ this._dl = (this._dl + dl) | 0
+ this._el = (this._el + el) | 0
+ this._fl = (this._fl + fl) | 0
+ this._gl = (this._gl + gl) | 0
+ this._hl = (this._hl + hl) | 0
+
+ this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
+ this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
+ this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
+ this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
+ this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
+ this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
+ this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
+ this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
+}
+
+Sha512.prototype._hash = function () {
+ var H = new Buffer(64)
+
+ function writeInt64BE (h, l, offset) {
+ H.writeInt32BE(h, offset)
+ H.writeInt32BE(l, offset + 4)
+ }
+
+ writeInt64BE(this._ah, this._al, 0)
+ writeInt64BE(this._bh, this._bl, 8)
+ writeInt64BE(this._ch, this._cl, 16)
+ writeInt64BE(this._dh, this._dl, 24)
+ writeInt64BE(this._eh, this._el, 32)
+ writeInt64BE(this._fh, this._fl, 40)
+ writeInt64BE(this._gh, this._gl, 48)
+ writeInt64BE(this._hh, this._hl, 56)
+
+ return H
+}
+
+module.exports = Sha512
diff --git a/node_modules/sha.js/test/hash.js b/node_modules/sha.js/test/hash.js
new file mode 100644
index 000000000..2f376b4d9
--- /dev/null
+++ b/node_modules/sha.js/test/hash.js
@@ -0,0 +1,86 @@
+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])
+ }
+}
+
+var hexBuf = new Buffer([48, 65, 49, 66, 50, 67, 51, 68, 52, 69, 53, 70, 54, 71, 55, 72])
+var count16 = {
+ strings: ['0A1B2C3D4E5F6G7H'],
+ buffers: [
+ hexBuf,
+ new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128])
+ ]
+}
+
+var empty = {
+ strings: [''],
+ buffers: [
+ new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])
+ ]
+}
+
+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])
+ ]
+ }
+
+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])
+ ]
+}
+
+function makeTest (name, data) {
+ tape(name, function (t) {
+
+ var h = new Hash(16, 8)
+ var hash = new Buffer(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')
+ }
+
+ return hash
+ }
+
+ data.strings.forEach(function (string) {
+ h.update(string, 'ascii')
+ })
+
+ equal(t, h.digest(), hash)
+ t.end()
+ })
+}
+
+makeTest('Hash#update 1 in 1', count16)
+makeTest('empty Hash#update', empty)
+makeTest('Hash#update 1 in 3', multi)
+makeTest('Hash#update 2 in 1', long)
diff --git a/node_modules/sha.js/test/test.js b/node_modules/sha.js/test/test.js
new file mode 100644
index 000000000..0a46e44be
--- /dev/null
+++ b/node_modules/sha.js/test/test.js
@@ -0,0 +1,85 @@
+var crypto = require('crypto')
+var tape = require('tape')
+var Sha1 = require('../').sha1
+
+var inputs = [
+ ['', 'ascii'],
+ ['abc', 'ascii'],
+ ['123', 'ascii'],
+ ['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
+ ['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
+ ['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
+ ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
+ ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
+ ['foobarbaz', 'ascii']
+]
+
+tape("hash is the same as node's crypto", function (t) {
+ inputs.forEach(function (v) {
+ var a = new Sha1().update(v[0], v[1]).digest('hex')
+ var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex')
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+
+ t.end()
+})
+
+tape('call update multiple times', function (t) {
+ inputs.forEach(function (v) {
+ var hash = new Sha1()
+ var _hash = crypto.createHash('sha1')
+
+ for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
+ var s = v[0].substring(i, (i + 1) * 2)
+ hash.update(s, v[1])
+ _hash.update(s, v[1])
+ }
+
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+ t.end()
+})
+
+tape('call update twice', function (t) {
+ var _hash = crypto.createHash('sha1')
+ var hash = new Sha1()
+
+ _hash.update('foo', 'ascii')
+ hash.update('foo', 'ascii')
+
+ _hash.update('bar', 'ascii')
+ hash.update('bar', 'ascii')
+
+ _hash.update('baz', 'ascii')
+ hash.update('baz', 'ascii')
+
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+
+ t.equal(a, e)
+ t.end()
+})
+
+tape('hex encoding', function (t) {
+ inputs.forEach(function (v) {
+ var hash = new Sha1()
+ var _hash = crypto.createHash('sha1')
+
+ 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')
+ }
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+
+ t.end()
+})
diff --git a/node_modules/sha.js/test/vectors.js b/node_modules/sha.js/test/vectors.js
new file mode 100644
index 000000000..4aef39cc3
--- /dev/null
+++ b/node_modules/sha.js/test/vectors.js
@@ -0,0 +1,76 @@
+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 createHash = require('../')
+
+function makeTest (alg, i, verbose) {
+ var v = vectors[i]
+
+ tape(alg + ': NIST vector ' + i, function (t) {
+ if (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'))
+ }
+
+ var buf = new Buffer(v.input, 'base64')
+ t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
+
+ i = ~~(buf.length / 2)
+ var buf1 = buf.slice(0, i)
+ var buf2 = buf.slice(i, buf.length)
+
+ console.log(buf1.length, buf2.length, buf.length)
+ console.log(createHash(alg)._block.length)
+
+ t.equal(
+ createHash(alg)
+ .update(buf1)
+ .update(buf2)
+ .digest('hex'),
+ v[alg]
+ )
+
+ var j, buf3
+
+ i = ~~(buf.length / 3)
+ j = ~~(buf.length * 2 / 3)
+ buf1 = buf.slice(0, i)
+ buf2 = buf.slice(i, j)
+ buf3 = buf.slice(j, buf.length)
+
+ t.equal(
+ createHash(alg)
+ .update(buf1)
+ .update(buf2)
+ .update(buf3)
+ .digest('hex'),
+ v[alg]
+ )
+
+ setTimeout(function () {
+ // avoid "too much recursion" errors in tape in firefox
+ 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)
+ makeTest('sha1', i)
+ makeTest('sha224', i)
+ makeTest('sha256', i)
+ makeTest('sha384', i)
+ makeTest('sha512', i)
+ })
+}