[Pkg-javascript-commits] [node-sha.js] 178/237: sha1: use a closure over seperate loops

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:03:52 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 bf46619c437f14c8aec95049fc054a13ee42c779
Author: Daniel Cousens <github at dcousens.com>
Date:   Mon Jan 12 20:30:06 2015 +1100

    sha1: use a closure over seperate loops
---
 sha1.js | 78 ++++++++++++-----------------------------------------------------
 1 file changed, 14 insertions(+), 64 deletions(-)

diff --git a/sha1.js b/sha1.js
index 753686e..42c2a8c 100644
--- a/sha1.js
+++ b/sha1.js
@@ -47,81 +47,31 @@ Sha1.prototype._update = function (M) {
   var d = this._d
   var e = this._e
 
-  var w, f, k, t, j = 0
-  while (j < 16) {
-    w = W[j] = M.readInt32BE(j * 4)
-    f = (b & c) | ((~b) & d)
-    k = 1518500249
-    t = (rol(a, 5) + f + e + w + k) | 0
+  var j = 0, k
 
-    e = d
-    d = c
-    c = rol(b, 30)
-    b = a
-    a = t
-
-    j++
-  }
-
-  while (j < 20) {
-    w = W[j] = rol(W[j - 3] ^ W[j -  8] ^ W[j - 14] ^ W[j - 16], 1)
-    f = (b & c) | ((~b) & d)
-    k = 1518500249
-    t = (rol(a, 5) + f + e + w + k) | 0
-
-    e = d
-    d = c
-    c = rol(b, 30)
-    b = a
-    a = t
-
-    j++
-  }
-
-  while (j < 40) {
-    w = W[j] = rol(W[j - 3] ^ W[j -  8] ^ W[j - 14] ^ W[j - 16], 1)
-    f = b ^ c ^ d
-    k = 1859775393
-    t = (rol(a, 5) + f + e + w + k) | 0
+  function calcW() { return rol(W[j - 3] ^ W[j -  8] ^ W[j - 14] ^ W[j - 16], 1) }
+  function loop(w, f) {
+    W[j] = w
 
-    e = d
-    d = c
-    c = rol(b, 30)
-    b = a
-    a = t
-
-    j++
-  }
-
-  while (j < 60) {
-    w = W[j] = rol(W[j - 3] ^ W[j -  8] ^ W[j - 14] ^ W[j - 16], 1)
-    f = (b & c) | (b & d) | (c & d)
-    k = -1894007588
-    t = (rol(a, 5) + f + e + w + k) | 0
+    var t = rol(a, 5) + f + e + w + k
 
     e = d
     d = c
     c = rol(b, 30)
     b = a
     a = t
-
     j++
   }
 
-  while (j < 80) {
-    w = W[j] = rol(W[j - 3] ^ W[j -  8] ^ W[j - 14] ^ W[j - 16], 1)
-    f = b ^ c ^ d
-    k = -899497514
-    t = (rol(a, 5) + f + e + w + k) | 0
-
-    e = d
-    d = c
-    c = rol(b, 30)
-    b = a
-    a = t
-
-    j++
-  }
+  k = 1518500249
+  while (j < 16) loop(M.readInt32BE(j * 4), (b & c) | ((~b) & d))
+  while (j < 20) loop(calcW(), (b & c) | ((~b) & d))
+  k = 1859775393
+  while (j < 40) loop(calcW(), b ^ c ^ d)
+  k = -1894007588
+  while (j < 60) loop(calcW(), (b & c) | (b & d) | (c & d))
+  k = -899497514
+  while (j < 80) loop(calcW(), b ^ c ^ d)
 
   this._a = (a + this._a) | 0
   this._b = (b + this._b) | 0

-- 
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