[Pkg-javascript-commits] [node-sha.js] 176/237: sha1: inline _ft, _kt functions

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 3b32ff2b18642d57c069152d0dba2dfdc8f6c3ac
Author: Daniel Cousens <github at dcousens.com>
Date:   Mon Jan 12 17:26:46 2015 +1100

    sha1: inline _ft, _kt functions
---
 sha1.js | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/sha1.js b/sha1.js
index 9e3504c..009f1cf 100644
--- a/sha1.js
+++ b/sha1.js
@@ -32,27 +32,6 @@ Sha1.prototype.init = function () {
 }
 
 /*
- * 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;
-}
-
-/*
- * Determine the appropriate additive constant for the current iteration
- */
-function sha1_kt(t) {
-  if (t < 20) return 1518500249
-  if (t < 40) return 1859775393
-  if (t < 60) return -1894007588
-  return -899497514
-}
-
-/*
  * Bitwise rotate a 32-bit number to the left.
  */
 function rol(num, cnt) {
@@ -73,10 +52,25 @@ Sha1.prototype._update = function (M) {
       ? M.readInt32BE(j * 4)
       : rol(W[j - 3] ^ W[j -  8] ^ W[j - 14] ^ W[j - 16], 1)
 
-    var t = (
-      ((rol(a, 5) + sha1_ft(j, b, c, d)) | 0) +
-      ((((e + w) | 0) + sha1_kt(j)) | 0)
-    )
+    var f, k
+    if (j < 20) {
+      f = (b & c) | ((~b) & d)
+      k = 1518500249
+
+    } else if (j < 40) {
+      f = b ^ c ^ d
+      k = 1859775393
+
+    } else if (j < 60) {
+      f = (b & c) | (b & d) | (c & d)
+      k = -1894007588
+
+    } else {
+      f = b ^ c ^ d
+      k = -899497514
+    }
+
+    var t = (rol(a, 5) + f + e + w + k) | 0
 
     e = d
     d = c

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