[Pkg-javascript-commits] [node-sha.js] 165/237: clean up factories
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:03:50 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-sha.js.
commit 996be1cb6a62a479dfb4758c5c431c6381c226cd
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date: Mon Nov 17 14:47:46 2014 -0500
clean up factories
---
browserify.js | 12 --
hash.js | 113 ++++++++-------
index.js | 14 +-
sha1.js | 206 +++++++++++++--------------
sha224.js | 66 +++++----
sha256.js | 236 ++++++++++++++++---------------
sha384.js | 86 ++++++------
sha512.js | 443 +++++++++++++++++++++++++++++-----------------------------
test/hash.js | 3 +-
9 files changed, 578 insertions(+), 601 deletions(-)
diff --git a/browserify.js b/browserify.js
deleted file mode 100644
index 7ed7c93..0000000
--- a/browserify.js
+++ /dev/null
@@ -1,12 +0,0 @@
-var exports = module.exports = function (alg) {
- var Alg = exports[alg.toLowerCase()]
- if(!Alg) throw new Error(alg + ' is not supported (we accept pull requests)')
- return new Alg()
-}
-
-var Buffer = require('buffer/').Buffer
-var Hash = require('./hash')(Buffer)
-
-exports.sha =
-exports.sha1 = require('./sha1')(Buffer, Hash)
-exports.sha256 = require('./sha256')(Buffer, Hash)
diff --git a/hash.js b/hash.js
index 0179592..49cb664 100644
--- a/hash.js
+++ b/hash.js
@@ -1,77 +1,76 @@
-module.exports = function (Buffer) {
-
- //prototype class for hash functions
- function Hash (blockSize, finalSize) {
- this._block = new Buffer(blockSize) //new Uint32Array(blockSize/4)
- this._finalSize = finalSize
- this._blockSize = blockSize
- this._len = 0
- this._s = 0
- }
- Hash.prototype.init = function () {
- this._s = 0
- this._len = 0
- }
- Hash.prototype.update = function (data, enc) {
- if ("string" === typeof data) {
- enc = enc || "utf8"
- data = new Buffer(data, enc)
- }
+//prototype class for hash functions
+function Hash (blockSize, finalSize) {
+ this._block = new Buffer(blockSize) //new Uint32Array(blockSize/4)
+ this._finalSize = finalSize
+ this._blockSize = blockSize
+ this._len = 0
+ this._s = 0
+}
- var l = this._len += data.length
- var s = this._s = (this._s || 0)
- var f = 0
- var buffer = this._block
+Hash.prototype.init = function () {
+ this._s = 0
+ this._len = 0
+}
- while (s < l) {
- var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
- var ch = (t - f)
+Hash.prototype.update = function (data, enc) {
+ if ("string" === typeof data) {
+ enc = enc || "utf8"
+ data = new Buffer(data, enc)
+ }
- for (var i = 0; i < ch; i++) {
- buffer[(s % this._blockSize) + i] = data[i + f]
- }
+ var l = this._len += data.length
+ var s = this._s = (this._s || 0)
+ var f = 0
+ var buffer = this._block
- s += ch
- f += ch
+ while (s < l) {
+ var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
+ var ch = (t - f)
- if ((s % this._blockSize) === 0) {
- this._update(buffer)
- }
+ for (var i = 0; i < ch; i++) {
+ buffer[(s % this._blockSize) + i] = data[i + f]
}
- this._s = s
- return this
+ s += ch
+ f += ch
+
+ if ((s % this._blockSize) === 0) {
+ this._update(buffer)
+ }
}
+ this._s = s
- Hash.prototype.digest = function (enc) {
- // Suppose the length of the message M, in bits, is l
- var l = this._len * 8
+ return this
+}
- // Append the bit 1 to the end of the message
- this._block[this._len % this._blockSize] = 0x80
+Hash.prototype.digest = function (enc) {
+ // Suppose the length of the message M, in bits, is l
+ var l = this._len * 8
- // 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)
+ // Append the bit 1 to the end of the message
+ this._block[this._len % this._blockSize] = 0x80
- if (l % (this._blockSize * 8) >= this._finalSize * 8) {
- this._update(this._block)
- this._block.fill(0)
- }
+ // 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)
- // 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)
+ if (l % (this._blockSize * 8) >= this._finalSize * 8) {
+ this._update(this._block)
+ this._block.fill(0)
+ }
- var hash = this._update(this._block) || this._hash()
+ // 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)
- return enc ? hash.toString(enc) : hash
- }
+ var hash = this._update(this._block) || this._hash()
- Hash.prototype._update = function () {
- throw new Error('_update must be implemented by subclass')
- }
+ return enc ? hash.toString(enc) : hash
+}
- return Hash
+Hash.prototype._update = function () {
+ throw new Error('_update must be implemented by subclass')
}
+
+module.exports = Hash
diff --git a/index.js b/index.js
index 6a094af..b156f24 100644
--- a/index.js
+++ b/index.js
@@ -1,14 +1,12 @@
var exports = module.exports = function (alg) {
- var Alg = exports[alg]
+ var Alg = exports[alg.toLowerCase()]
if(!Alg) throw new Error(alg + ' is not supported (we accept pull requests)')
return new Alg()
}
-var Buffer = require('buffer').Buffer
-var Hash = require('./hash')(Buffer)
-exports.sha1 = require('./sha1')(Buffer, Hash)
-exports.sha224 = require('./sha224')(Buffer, Hash)
-exports.sha256 = require('./sha256')(Buffer, Hash)
-exports.sha384 = require('./sha384')(Buffer, Hash)
-exports.sha512 = require('./sha512')(Buffer, Hash)
+exports.sha1 = require('./sha1')
+exports.sha224 = require('./sha224')
+exports.sha256 = require('./sha256')
+exports.sha384 = require('./sha384')
+exports.sha512 = require('./sha512')
diff --git a/sha1.js b/sha1.js
index af87d38..81339b2 100644
--- a/sha1.js
+++ b/sha1.js
@@ -9,130 +9,130 @@
var inherits = require('util').inherits
-module.exports = function (Buffer, Hash) {
+var Hash = require('./hash')
- var A = 0|0
- var B = 4|0
- var C = 8|0
- var D = 12|0
- var E = 16|0
+var A = 0|0
+var B = 4|0
+var C = 8|0
+var D = 12|0
+var E = 16|0
- var W = new (typeof Int32Array === 'undefined' ? Array : Int32Array)(80)
+var W = new (typeof Int32Array === 'undefined' ? Array : Int32Array)(80)
- var POOL = []
+var POOL = []
- function Sha1 () {
- if(POOL.length)
- return POOL.pop().init()
+function Sha1 () {
+ if(POOL.length)
+ return POOL.pop().init()
- if(!(this instanceof Sha1)) return new Sha1()
- this._w = W
- Hash.call(this, 16*4, 14*4)
+ if(!(this instanceof Sha1)) return new Sha1()
+ this._w = W
+ Hash.call(this, 16*4, 14*4)
- this._h = null
- this.init()
- }
-
- inherits(Sha1, Hash)
+ this._h = null
+ this.init()
+}
- Sha1.prototype.init = function () {
- this._a = 0x67452301
- this._b = 0xefcdab89
- this._c = 0x98badcfe
- this._d = 0x10325476
- this._e = 0xc3d2e1f0
+inherits(Sha1, Hash)
- Hash.prototype.init.call(this)
- return this
- }
+Sha1.prototype.init = function () {
+ this._a = 0x67452301
+ this._b = 0xefcdab89
+ this._c = 0x98badcfe
+ this._d = 0x10325476
+ this._e = 0xc3d2e1f0
- Sha1.prototype._POOL = POOL
- Sha1.prototype._update = function (X) {
+ Hash.prototype.init.call(this)
+ return this
+}
- var a, b, c, d, e, _a, _b, _c, _d, _e
+Sha1.prototype._POOL = POOL
+Sha1.prototype._update = function (X) {
- a = _a = this._a
- b = _b = this._b
- c = _c = this._c
- d = _d = this._d
- e = _e = this._e
+ var a, b, c, d, e, _a, _b, _c, _d, _e
- var w = this._w
+ a = _a = this._a
+ b = _b = this._b
+ c = _c = this._c
+ d = _d = this._d
+ e = _e = this._e
- for(var j = 0; j < 80; j++) {
- var W = w[j] = j < 16 ? X.readInt32BE(j*4)
- : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1)
+ var w = this._w
- var t = add(
- add(rol(a, 5), sha1_ft(j, b, c, d)),
- add(add(e, W), sha1_kt(j))
- )
+ for(var j = 0; j < 80; j++) {
+ var W = w[j] = j < 16 ? X.readInt32BE(j*4)
+ : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1)
- e = d
- d = c
- c = rol(b, 30)
- b = a
- a = t
- }
+ var t = add(
+ add(rol(a, 5), sha1_ft(j, b, c, d)),
+ add(add(e, W), sha1_kt(j))
+ )
- this._a = add(a, _a)
- this._b = add(b, _b)
- this._c = add(c, _c)
- this._d = add(d, _d)
- this._e = add(e, _e)
+ e = d
+ d = c
+ c = rol(b, 30)
+ b = a
+ a = t
}
- Sha1.prototype._hash = function () {
- if(POOL.length < 100) POOL.push(this)
- var H = new Buffer(20)
- //console.log(this._a|0, this._b|0, this._c|0, this._d|0, this._e|0)
- H.writeInt32BE(this._a|0, A)
- H.writeInt32BE(this._b|0, B)
- H.writeInt32BE(this._c|0, C)
- H.writeInt32BE(this._d|0, D)
- H.writeInt32BE(this._e|0, E)
- return H
- }
+ this._a = add(a, _a)
+ this._b = add(b, _b)
+ this._c = add(c, _c)
+ this._d = add(d, _d)
+ this._e = add(e, _e)
+}
- /*
- * Perform the appropriate triplet combination function for the current
- * iteration
- */
- function sha1_ft(t, b, c, d) {
- if(t < 20) return (b & c) | ((~b) & d);
- if(t < 40) return b ^ c ^ d;
- if(t < 60) return (b & c) | (b & d) | (c & d);
- return b ^ c ^ d;
- }
+Sha1.prototype._hash = function () {
+ if(POOL.length < 100) POOL.push(this)
+ var H = new Buffer(20)
+ //console.log(this._a|0, this._b|0, this._c|0, this._d|0, this._e|0)
+ H.writeInt32BE(this._a|0, A)
+ H.writeInt32BE(this._b|0, B)
+ H.writeInt32BE(this._c|0, C)
+ H.writeInt32BE(this._d|0, D)
+ H.writeInt32BE(this._e|0, E)
+ return H
+}
- /*
- * Determine the appropriate additive constant for the current iteration
- */
- function sha1_kt(t) {
- return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
- (t < 60) ? -1894007588 : -899497514;
- }
+/*
+ * Perform the appropriate triplet combination function for the current
+ * iteration
+ */
+function sha1_ft(t, b, c, d) {
+ if(t < 20) return (b & c) | ((~b) & d);
+ if(t < 40) return b ^ c ^ d;
+ if(t < 60) return (b & c) | (b & d) | (c & d);
+ return b ^ c ^ d;
+}
- /*
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
- * //dominictarr: this is 10 years old, so maybe this can be dropped?)
- *
- */
- function add(x, y) {
- return (x + y ) | 0
- //lets see how this goes on testling.
- // var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- // var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- // return (msw << 16) | (lsw & 0xFFFF);
- }
+/*
+ * Determine the appropriate additive constant for the current iteration
+ */
+function sha1_kt(t) {
+ return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
+ (t < 60) ? -1894007588 : -899497514;
+}
- /*
- * Bitwise rotate a 32-bit number to the left.
- */
- function rol(num, cnt) {
- return (num << cnt) | (num >>> (32 - cnt));
- }
+/*
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ * //dominictarr: this is 10 years old, so maybe this can be dropped?)
+ *
+ */
+function add(x, y) {
+ return (x + y ) | 0
+//lets see how this goes on testling.
+// var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+// var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+// return (msw << 16) | (lsw & 0xFFFF);
+}
- return Sha1
+/*
+ * Bitwise rotate a 32-bit number to the left.
+ */
+function rol(num, cnt) {
+ return (num << cnt) | (num >>> (32 - cnt));
}
+
+module.exports = Sha1
+
diff --git a/sha224.js b/sha224.js
index f7f3c56..49ad815 100644
--- a/sha224.js
+++ b/sha224.js
@@ -9,51 +9,49 @@
var inherits = require('util').inherits
var SHA256 = require('./sha256')
-module.exports = function (Buffer, Hash) {
+var Hash = require('./hash')
- var W = new Array(64)
+var W = new Array(64)
- function Sha224() {
- this.init()
+function Sha224() {
+ this.init()
- this._w = W //new Array(64)
+ this._w = W //new Array(64)
- Hash.call(this, 16*4, 14*4)
- }
-
- inherits(Sha224, SHA256(Buffer, Hash))
-
- Sha224.prototype.init = function () {
+ Hash.call(this, 16*4, 14*4)
+}
- this._a = 0xc1059ed8|0
- this._b = 0x367cd507|0
- this._c = 0x3070dd17|0
- this._d = 0xf70e5939|0
- this._e = 0xffc00b31|0
- this._f = 0x68581511|0
- this._g = 0x64f98fa7|0
- this._h = 0xbefa4fa4|0
+inherits(Sha224, SHA256)
- this._len = this._s = 0
+Sha224.prototype.init = function () {
- return this
- }
+ this._a = 0xc1059ed8|0
+ this._b = 0x367cd507|0
+ this._c = 0x3070dd17|0
+ this._d = 0xf70e5939|0
+ this._e = 0xffc00b31|0
+ this._f = 0x68581511|0
+ this._g = 0x64f98fa7|0
+ this._h = 0xbefa4fa4|0
+ this._len = this._s = 0
- Sha224.prototype._hash = function () {
- var H = new Buffer(28)
+ return this
+}
- 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
- }
+Sha224.prototype._hash = function () {
+ var H = new Buffer(28)
- return Sha224
+ 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/sha256.js b/sha256.js
index 053355f..57459c0 100644
--- a/sha256.js
+++ b/sha256.js
@@ -9,139 +9,137 @@
var inherits = require('util').inherits
-module.exports = function (Buffer, 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, 16*4, 14*4)
- }
+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, 16*4, 14*4)
+}
- inherits(Sha256, Hash)
+inherits(Sha256, Hash)
- Sha256.prototype.init = function () {
+Sha256.prototype.init = function () {
- this._a = 0x6a09e667|0
- this._b = 0xbb67ae85|0
- this._c = 0x3c6ef372|0
- this._d = 0xa54ff53a|0
- this._e = 0x510e527f|0
- this._f = 0x9b05688c|0
- this._g = 0x1f83d9ab|0
- this._h = 0x5be0cd19|0
+ this._a = 0x6a09e667|0
+ this._b = 0xbb67ae85|0
+ this._c = 0x3c6ef372|0
+ this._d = 0xa54ff53a|0
+ this._e = 0x510e527f|0
+ this._f = 0x9b05688c|0
+ this._g = 0x1f83d9ab|0
+ this._h = 0x5be0cd19|0
- this._len = this._s = 0
+ this._len = this._s = 0
- return this
- }
+ return this
+}
- function S (X, n) {
- return (X >>> n) | (X << (32 - n));
- }
+function S (X, n) {
+ return (X >>> n) | (X << (32 - n));
+}
- function R (X, n) {
- return (X >>> n);
- }
+function R (X, n) {
+ return (X >>> n);
+}
- function Ch (x, y, z) {
- return ((x & y) ^ ((~x) & z));
- }
+function Ch (x, y, z) {
+ return ((x & y) ^ ((~x) & z));
+}
- function Maj (x, y, z) {
- return ((x & y) ^ (x & z) ^ (y & z));
- }
+function Maj (x, y, z) {
+ return ((x & y) ^ (x & z) ^ (y & z));
+}
- function Sigma0256 (x) {
- return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
- }
+function Sigma0256 (x) {
+ return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
+}
- function Sigma1256 (x) {
- return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
- }
+function Sigma1256 (x) {
+ return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
+}
- function Gamma0256 (x) {
- return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
- }
+function Gamma0256 (x) {
+ return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
+}
- function Gamma1256 (x) {
- return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
- }
+function Gamma1256 (x) {
+ return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
+}
- Sha256.prototype._update = function(M) {
-
- var W = this._w
- var a, b, c, d, e, f, g, h
- var T1, T2
-
- a = this._a | 0
- b = this._b | 0
- c = this._c | 0
- d = this._d | 0
- e = this._e | 0
- f = this._f | 0
- g = this._g | 0
- h = this._h | 0
-
- for (var j = 0; j < 64; j++) {
- var w = W[j] = j < 16
- ? M.readInt32BE(j * 4)
- : Gamma1256(W[j - 2]) + W[j - 7] + Gamma0256(W[j - 15]) + W[j - 16]
-
- T1 = h + Sigma1256(e) + Ch(e, f, g) + K[j] + w
-
- T2 = Sigma0256(a) + Maj(a, b, c);
- h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2;
- }
-
- 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
- }
+Sha256.prototype._update = function(M) {
- return Sha256
+ var W = this._w
+ var a, b, c, d, e, f, g, h
+ var T1, T2
+ a = this._a | 0
+ b = this._b | 0
+ c = this._c | 0
+ d = this._d | 0
+ e = this._e | 0
+ f = this._f | 0
+ g = this._g | 0
+ h = this._h | 0
+
+ for (var j = 0; j < 64; j++) {
+ var w = W[j] = j < 16
+ ? M.readInt32BE(j * 4)
+ : Gamma1256(W[j - 2]) + W[j - 7] + Gamma0256(W[j - 15]) + W[j - 16]
+
+ T1 = h + Sigma1256(e) + Ch(e, f, g) + K[j] + w
+
+ T2 = Sigma0256(a) + Maj(a, b, c);
+ h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2;
+ }
+
+ 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/sha384.js b/sha384.js
index 6f6e65e..bb9f3ad 100644
--- a/sha384.js
+++ b/sha384.js
@@ -1,63 +1,61 @@
var inherits = require('util').inherits
var SHA512 = require('./sha512');
-module.exports = function (Buffer, Hash) {
+var Hash = require('./hash')
- var W = new Array(160)
+var W = new Array(160)
- function Sha384() {
- this.init()
- this._w = W
+function Sha384() {
+ this.init()
+ this._w = W
- Hash.call(this, 128, 112)
- }
-
- inherits(Sha384, SHA512(Buffer, Hash))
+ Hash.call(this, 128, 112)
+}
- Sha384.prototype.init = function () {
+inherits(Sha384, SHA512)
- this._a = 0xcbbb9d5d|0
- this._b = 0x629a292a|0
- this._c = 0x9159015a|0
- this._d = 0x152fecd8|0
- this._e = 0x67332667|0
- this._f = 0x8eb44a87|0
- this._g = 0xdb0c2e0d|0
- this._h = 0x47b5481d|0
+Sha384.prototype.init = function () {
- this._al = 0xc1059ed8|0
- this._bl = 0x367cd507|0
- this._cl = 0x3070dd17|0
- this._dl = 0xf70e5939|0
- this._el = 0xffc00b31|0
- this._fl = 0x68581511|0
- this._gl = 0x64f98fa7|0
- this._hl = 0xbefa4fa4|0
+ this._a = 0xcbbb9d5d|0
+ this._b = 0x629a292a|0
+ this._c = 0x9159015a|0
+ this._d = 0x152fecd8|0
+ this._e = 0x67332667|0
+ this._f = 0x8eb44a87|0
+ this._g = 0xdb0c2e0d|0
+ this._h = 0x47b5481d|0
- this._len = this._s = 0
-
- return this
- }
+ this._al = 0xc1059ed8|0
+ this._bl = 0x367cd507|0
+ this._cl = 0x3070dd17|0
+ this._dl = 0xf70e5939|0
+ this._el = 0xffc00b31|0
+ this._fl = 0x68581511|0
+ this._gl = 0x64f98fa7|0
+ this._hl = 0xbefa4fa4|0
+ this._len = this._s = 0
+ 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._a, this._al, 0)
- writeInt64BE(this._b, this._bl, 8)
- writeInt64BE(this._c, this._cl, 16)
- writeInt64BE(this._d, this._dl, 24)
- writeInt64BE(this._e, this._el, 32)
- writeInt64BE(this._f, this._fl, 40)
+Sha384.prototype._hash = function () {
+ var H = new Buffer(48)
- return H
+ function writeInt64BE(h, l, offset) {
+ H.writeInt32BE(h, offset)
+ H.writeInt32BE(l, offset + 4)
}
- return Sha384
+ writeInt64BE(this._a, this._al, 0)
+ writeInt64BE(this._b, this._bl, 8)
+ writeInt64BE(this._c, this._cl, 16)
+ writeInt64BE(this._d, this._dl, 24)
+ writeInt64BE(this._e, this._el, 32)
+ writeInt64BE(this._f, this._fl, 40)
+ return H
}
+
+module.exports = Sha384
diff --git a/sha512.js b/sha512.js
index 1fca318..82b33f8 100644
--- a/sha512.js
+++ b/sha512.js
@@ -1,244 +1,243 @@
var inherits = require('util').inherits
-module.exports = function (Buffer, 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)
- }
+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)
+inherits(Sha512, Hash)
- Sha512.prototype.init = function () {
+Sha512.prototype.init = function () {
- this._a = 0x6a09e667|0
- this._b = 0xbb67ae85|0
- this._c = 0x3c6ef372|0
- this._d = 0xa54ff53a|0
- this._e = 0x510e527f|0
- this._f = 0x9b05688c|0
- this._g = 0x1f83d9ab|0
- this._h = 0x5be0cd19|0
+ this._a = 0x6a09e667|0
+ this._b = 0xbb67ae85|0
+ this._c = 0x3c6ef372|0
+ this._d = 0xa54ff53a|0
+ this._e = 0x510e527f|0
+ this._f = 0x9b05688c|0
+ this._g = 0x1f83d9ab|0
+ this._h = 0x5be0cd19|0
- this._al = 0xf3bcc908|0
- this._bl = 0x84caa73b|0
- this._cl = 0xfe94f82b|0
- this._dl = 0x5f1d36f1|0
- this._el = 0xade682d1|0
- this._fl = 0x2b3e6c1f|0
- this._gl = 0xfb41bd6b|0
- this._hl = 0x137e2179|0
+ this._al = 0xf3bcc908|0
+ this._bl = 0x84caa73b|0
+ this._cl = 0xfe94f82b|0
+ this._dl = 0x5f1d36f1|0
+ this._el = 0xade682d1|0
+ this._fl = 0x2b3e6c1f|0
+ this._gl = 0xfb41bd6b|0
+ this._hl = 0x137e2179|0
- this._len = this._s = 0
+ this._len = this._s = 0
- return this
- }
+ return this
+}
- function S (X, Xl, n) {
- return (X >>> n) | (Xl << (32 - n))
- }
+function S (X, Xl, n) {
+ return (X >>> n) | (Xl << (32 - n))
+}
- function Ch (x, y, z) {
- return ((x & y) ^ ((~x) & z));
- }
+function Ch (x, y, z) {
+ return ((x & y) ^ ((~x) & z));
+}
- function Maj (x, y, z) {
- return ((x & y) ^ (x & z) ^ (y & z));
- }
+function Maj (x, y, z) {
+ return ((x & y) ^ (x & z) ^ (y & z));
+}
- Sha512.prototype._update = function(M) {
-
- var W = this._w
- var a, b, c, d, e, f, g, h
- var al, bl, cl, dl, el, fl, gl, hl
-
- a = this._a | 0
- b = this._b | 0
- c = this._c | 0
- d = this._d | 0
- e = this._e | 0
- f = this._f | 0
- g = this._g | 0
- h = this._h | 0
-
- al = this._al | 0
- bl = this._bl | 0
- cl = this._cl | 0
- dl = this._dl | 0
- el = this._el | 0
- fl = this._fl | 0
- gl = this._gl | 0
- hl = this._hl | 0
-
- for (var i = 0; i < 80; i++) {
- var j = i * 2
-
- var Wi, Wil
-
- if (i < 16) {
- Wi = W[j] = M.readInt32BE(j * 4)
- Wil = W[j + 1] = M.readInt32BE(j * 4 + 4)
-
- } else {
- var x = W[j - 15*2]
- var xl = W[j - 15*2 + 1]
- var gamma0 = S(x, xl, 1) ^ S(x, xl, 8) ^ (x >>> 7)
- var gamma0l = S(xl, x, 1) ^ S(xl, x, 8) ^ S(xl, x, 7)
-
- x = W[j - 2*2]
- xl = W[j - 2*2 + 1]
- var gamma1 = S(x, xl, 19) ^ S(xl, x, 29) ^ (x >>> 6)
- var gamma1l = S(xl, x, 19) ^ S(x, xl, 29) ^ S(xl, x, 6)
-
- // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
- var Wi7 = W[j - 7*2]
- var Wi7l = W[j - 7*2 + 1]
-
- var Wi16 = W[j - 16*2]
- var Wi16l = W[j - 16*2 + 1]
-
- Wil = gamma0l + Wi7l
- Wi = gamma0 + Wi7 + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0)
- Wil = Wil + gamma1l
- Wi = Wi + gamma1 + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0)
- Wil = Wil + Wi16l
- Wi = Wi + Wi16 + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0)
-
- W[j] = Wi
- W[j + 1] = Wil
- }
-
- var maj = Maj(a, b, c)
- var majl = Maj(al, bl, cl)
-
- var sigma0h = S(a, al, 28) ^ S(al, a, 2) ^ S(al, a, 7)
- var sigma0l = S(al, a, 28) ^ S(a, al, 2) ^ S(a, al, 7)
- var sigma1h = S(e, el, 14) ^ S(e, el, 18) ^ S(el, e, 9)
- var sigma1l = S(el, e, 14) ^ S(el, e, 18) ^ S(e, el, 9)
-
- // t1 = h + sigma1 + ch + K[i] + W[i]
- var Ki = K[j]
- var Kil = K[j + 1]
-
- var ch = Ch(e, f, g)
- var chl = Ch(el, fl, gl)
-
- var t1l = hl + sigma1l
- var t1 = h + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0)
- t1l = t1l + chl
- t1 = t1 + ch + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0)
- t1l = t1l + Kil
- t1 = t1 + Ki + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0)
- t1l = t1l + Wil
- t1 = t1 + Wi + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0)
-
- // t2 = sigma0 + maj
- var t2l = sigma0l + majl
- var t2 = sigma0h + maj + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0)
-
- h = g
- hl = gl
- g = f
- gl = fl
- f = e
- fl = el
- el = (dl + t1l) | 0
- e = (d + t1 + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
- d = c
- dl = cl
- c = b
- cl = bl
- b = a
- bl = al
- al = (t1l + t2l) | 0
- a = (t1 + t2 + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0
+Sha512.prototype._update = function(M) {
+
+ var W = this._w
+ var a, b, c, d, e, f, g, h
+ var al, bl, cl, dl, el, fl, gl, hl
+
+ a = this._a | 0
+ b = this._b | 0
+ c = this._c | 0
+ d = this._d | 0
+ e = this._e | 0
+ f = this._f | 0
+ g = this._g | 0
+ h = this._h | 0
+
+ al = this._al | 0
+ bl = this._bl | 0
+ cl = this._cl | 0
+ dl = this._dl | 0
+ el = this._el | 0
+ fl = this._fl | 0
+ gl = this._gl | 0
+ hl = this._hl | 0
+
+ for (var i = 0; i < 80; i++) {
+ var j = i * 2
+
+ var Wi, Wil
+
+ if (i < 16) {
+ Wi = W[j] = M.readInt32BE(j * 4)
+ Wil = W[j + 1] = M.readInt32BE(j * 4 + 4)
+
+ } else {
+ var x = W[j - 15*2]
+ var xl = W[j - 15*2 + 1]
+ var gamma0 = S(x, xl, 1) ^ S(x, xl, 8) ^ (x >>> 7)
+ var gamma0l = S(xl, x, 1) ^ S(xl, x, 8) ^ S(xl, x, 7)
+
+ x = W[j - 2*2]
+ xl = W[j - 2*2 + 1]
+ var gamma1 = S(x, xl, 19) ^ S(xl, x, 29) ^ (x >>> 6)
+ var gamma1l = S(xl, x, 19) ^ S(x, xl, 29) ^ S(xl, x, 6)
+
+ // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
+ var Wi7 = W[j - 7*2]
+ var Wi7l = W[j - 7*2 + 1]
+
+ var Wi16 = W[j - 16*2]
+ var Wi16l = W[j - 16*2 + 1]
+
+ Wil = gamma0l + Wi7l
+ Wi = gamma0 + Wi7 + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0)
+ Wil = Wil + gamma1l
+ Wi = Wi + gamma1 + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0)
+ Wil = Wil + Wi16l
+ Wi = Wi + Wi16 + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0)
+
+ W[j] = Wi
+ W[j + 1] = Wil
}
- 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._a = (this._a + a + ((this._al >>> 0) < (al >>> 0) ? 1 : 0)) | 0
- this._b = (this._b + b + ((this._bl >>> 0) < (bl >>> 0) ? 1 : 0)) | 0
- this._c = (this._c + c + ((this._cl >>> 0) < (cl >>> 0) ? 1 : 0)) | 0
- this._d = (this._d + d + ((this._dl >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
- this._e = (this._e + e + ((this._el >>> 0) < (el >>> 0) ? 1 : 0)) | 0
- this._f = (this._f + f + ((this._fl >>> 0) < (fl >>> 0) ? 1 : 0)) | 0
- this._g = (this._g + g + ((this._gl >>> 0) < (gl >>> 0) ? 1 : 0)) | 0
- this._h = (this._h + h + ((this._hl >>> 0) < (hl >>> 0) ? 1 : 0)) | 0
+ var maj = Maj(a, b, c)
+ var majl = Maj(al, bl, cl)
+
+ var sigma0h = S(a, al, 28) ^ S(al, a, 2) ^ S(al, a, 7)
+ var sigma0l = S(al, a, 28) ^ S(a, al, 2) ^ S(a, al, 7)
+ var sigma1h = S(e, el, 14) ^ S(e, el, 18) ^ S(el, e, 9)
+ var sigma1l = S(el, e, 14) ^ S(el, e, 18) ^ S(e, el, 9)
+
+ // t1 = h + sigma1 + ch + K[i] + W[i]
+ var Ki = K[j]
+ var Kil = K[j + 1]
+
+ var ch = Ch(e, f, g)
+ var chl = Ch(el, fl, gl)
+
+ var t1l = hl + sigma1l
+ var t1 = h + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0)
+ t1l = t1l + chl
+ t1 = t1 + ch + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0)
+ t1l = t1l + Kil
+ t1 = t1 + Ki + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0)
+ t1l = t1l + Wil
+ t1 = t1 + Wi + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0)
+
+ // t2 = sigma0 + maj
+ var t2l = sigma0l + majl
+ var t2 = sigma0h + maj + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0)
+
+ h = g
+ hl = gl
+ g = f
+ gl = fl
+ f = e
+ fl = el
+ el = (dl + t1l) | 0
+ e = (d + t1 + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
+ d = c
+ dl = cl
+ c = b
+ cl = bl
+ b = a
+ bl = al
+ al = (t1l + t2l) | 0
+ a = (t1 + t2 + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0
}
- Sha512.prototype._hash = function () {
- var H = new Buffer(64)
-
- function writeInt64BE(h, l, offset) {
- H.writeInt32BE(h, offset)
- H.writeInt32BE(l, offset + 4)
- }
+ 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._a = (this._a + a + ((this._al >>> 0) < (al >>> 0) ? 1 : 0)) | 0
+ this._b = (this._b + b + ((this._bl >>> 0) < (bl >>> 0) ? 1 : 0)) | 0
+ this._c = (this._c + c + ((this._cl >>> 0) < (cl >>> 0) ? 1 : 0)) | 0
+ this._d = (this._d + d + ((this._dl >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
+ this._e = (this._e + e + ((this._el >>> 0) < (el >>> 0) ? 1 : 0)) | 0
+ this._f = (this._f + f + ((this._fl >>> 0) < (fl >>> 0) ? 1 : 0)) | 0
+ this._g = (this._g + g + ((this._gl >>> 0) < (gl >>> 0) ? 1 : 0)) | 0
+ this._h = (this._h + h + ((this._hl >>> 0) < (hl >>> 0) ? 1 : 0)) | 0
+}
- writeInt64BE(this._a, this._al, 0)
- writeInt64BE(this._b, this._bl, 8)
- writeInt64BE(this._c, this._cl, 16)
- writeInt64BE(this._d, this._dl, 24)
- writeInt64BE(this._e, this._el, 32)
- writeInt64BE(this._f, this._fl, 40)
- writeInt64BE(this._g, this._gl, 48)
- writeInt64BE(this._h, this._hl, 56)
+Sha512.prototype._hash = function () {
+ var H = new Buffer(64)
- return H
+ function writeInt64BE(h, l, offset) {
+ H.writeInt32BE(h, offset)
+ H.writeInt32BE(l, offset + 4)
}
- return Sha512
+ writeInt64BE(this._a, this._al, 0)
+ writeInt64BE(this._b, this._bl, 8)
+ writeInt64BE(this._c, this._cl, 16)
+ writeInt64BE(this._d, this._dl, 24)
+ writeInt64BE(this._e, this._el, 32)
+ writeInt64BE(this._f, this._fl, 40)
+ writeInt64BE(this._g, this._gl, 48)
+ writeInt64BE(this._h, this._hl, 56)
+ return H
}
+
+module.exports = Sha512
diff --git a/test/hash.js b/test/hash.js
index 801ab87..6a369cd 100644
--- a/test/hash.js
+++ b/test/hash.js
@@ -1,7 +1,6 @@
var hexpp = require('../hexpp').defaults({bigendian: false})
var tape = require('tape')
-var Buffer = require('buffer/').Buffer
-var Hash = require('../hash')(Buffer)
+var Hash = require('../hash')
var hex = '0A1B2C3D4E5F6G7H', hexbuf
function equal(t, a, b) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-sha.js.git
More information about the Pkg-javascript-commits
mailing list