[Pkg-javascript-commits] [node-sha.js] 05/237: tidy

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:02: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 51c40fa0c632c5114b574199063f8366621eaaa8
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Wed Dec 25 01:29:18 2013 +0700

    tidy
---
 index.js | 61 +++++++++++++++++++------------------------------------------
 1 file changed, 19 insertions(+), 42 deletions(-)

diff --git a/index.js b/index.js
index 1122ca9..f25f10d 100644
--- a/index.js
+++ b/index.js
@@ -108,53 +108,30 @@ Sha.prototype.update = function (data, enc) {
 
 Sha.prototype.final = function () {
   //do the sha stuff to the end of the message array.
-  console.log('final', this._len)
   var x = this._x, len = this._len*8
   
-  console.log('length written:', len, this._len, 'too long?', len > 448, 'extra', 448 - (len % 512))
-  //if
-  //if there is *any* space, fill it, and _update that round.
   console.log('--- final ---')
   console.log(hexpp(x))
 
-    if(len === 0) {
-      //try doing nothing? YUSS
-      x[(len % 512) >> 5] |= (0x80 << (24 - len % 32));
-    }
-    else if(len % 512 > 448) {
-      x[(len % 512) >> 5] |= (0x80 << (24 - len % 32));
-      //len = this._len += (len % 512)
-      //compute that hash...
-      //OH, i guess we better append the final bit here!
-      this._update()
-      zeroFill(this._x, 0)
-      //len = this._len += 448
-    }
-    //edge case where message is multiple of 512 bits long
-    else if(len % 512 <= 448) {
-      console.log('REMAINER', (len % 512) - 448)
-      if((len % 512) - 448) {
-        console.log('ZERO FILL', len % 512)
-        zeroFill(this._x, (len % 512))
-        x[(len % 512) >> 5] |= 0x80 << (24 - (len % 512) % 32);
-      }
-        x[(len % 512) >> 5] |= 0x80 << (24 - (len % 512) % 32);
-    }
-    else if(len % 512 === 0) {
-      console.log('FIT TO w')
-      this._update()
-      zeroFill(this._x.buffer, 0)
-      //len = this._len += 448
-    }
-    else {
-      console.log('OH NOES', len, len % 512)
-    }
-
-
-//  x[(((len % 512) + 64 >> 9) << 4) + 15] = len;
-
-  console.log('--- addBit ---')
-  console.log(hexpp(x))
+  var bits = len % 512
+  var append = bits >> 5
+  var bit = (0x80 << (24 - len % 32))
+  if(len === 0 || (bits && bits < 448)) {
+    x[append] |= bit;
+  }
+  else if(bits >= 448) {
+    x[append] |= bit;
+    this._update()
+    zeroFill(this._x, 0)
+  }
+  //edge case where message is multiple of 512 bits long
+  else if(bits === 0) {
+    this._update()
+    zeroFill(this._x.buffer, 0)
+    //len = this._len += 448
+    x[append] |= bit;
+  }
+
   x[15] = len
   console.log('--- addLed ---')
   console.log(hexpp(x))

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