[Pkg-javascript-commits] [node-sha.js] 164/237: sha224 and 384
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 56694e5db70844f11a6a4082a549339d3b24ea95
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date: Mon Nov 17 14:34:18 2014 -0500
sha224 and 384
---
index.js | 2 ++
sha224.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
sha384.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/vectors.js | 2 ++
4 files changed, 126 insertions(+)
diff --git a/index.js b/index.js
index c947f3e..6a094af 100644
--- a/index.js
+++ b/index.js
@@ -8,5 +8,7 @@ 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)
diff --git a/sha224.js b/sha224.js
new file mode 100644
index 0000000..f7f3c56
--- /dev/null
+++ b/sha224.js
@@ -0,0 +1,59 @@
+
+/**
+ * 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('util').inherits
+var SHA256 = require('./sha256')
+module.exports = function (Buffer, Hash) {
+
+ var W = new Array(64)
+
+ function Sha224() {
+ this.init()
+
+ this._w = W //new Array(64)
+
+ Hash.call(this, 16*4, 14*4)
+ }
+
+ inherits(Sha224, SHA256(Buffer, Hash))
+
+ Sha224.prototype.init = function () {
+
+ 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
+
+ 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
+ }
+
+ return Sha224
+
+}
diff --git a/sha384.js b/sha384.js
new file mode 100644
index 0000000..6f6e65e
--- /dev/null
+++ b/sha384.js
@@ -0,0 +1,63 @@
+var inherits = require('util').inherits
+var SHA512 = require('./sha512');
+module.exports = function (Buffer, Hash) {
+
+ var W = new Array(160)
+
+ function Sha384() {
+ this.init()
+ this._w = W
+
+ Hash.call(this, 128, 112)
+ }
+
+ inherits(Sha384, SHA512(Buffer, Hash))
+
+ Sha384.prototype.init = function () {
+
+ 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._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)
+
+ return H
+ }
+
+ return Sha384
+
+}
diff --git a/test/vectors.js b/test/vectors.js
index 248e5b9..b718eb6 100644
--- a/test/vectors.js
+++ b/test/vectors.js
@@ -66,7 +66,9 @@ if(process.argv[2])
else
vectors.forEach(function (v, i) {
makeTest('sha1', i)
+ makeTest('sha224', i)
makeTest('sha256', i)
+ makeTest('sha384', i)
makeTest('sha512', i)
})
--
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