[Pkg-javascript-commits] [node-sha.js] 81/237: tidy
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:03:37 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 dce6d28d15672d8c95cfc855b8071398b8aaca67
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date: Mon Jan 6 10:17:51 2014 +0700
tidy
---
sha256.js | 136 ++++++++++++++++----------------------------------------------
1 file changed, 34 insertions(+), 102 deletions(-)
diff --git a/sha256.js b/sha256.js
index 34d7dda..0ac6543 100644
--- a/sha256.js
+++ b/sha256.js
@@ -64,53 +64,45 @@ var safe_add = function(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
-};
+}
-var S = function(X, n) {
+function S (X, n) {
return (X >>> n) | (X << (32 - n));
-};
+}
-var R = function(X, n) {
+function R (X, n) {
return (X >>> n);
-};
+}
-var Ch = function(x, y, z) {
+function Ch (x, y, z) {
return ((x & y) ^ ((~x) & z));
-};
+}
-var Maj = function(x, y, z) {
+function Maj (x, y, z) {
return ((x & y) ^ (x & z) ^ (y & z));
-};
+}
-var Sigma0256 = function(x) {
+function Sigma0256 (x) {
return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
-};
+}
-var Sigma1256 = function(x) {
+function Sigma1256 (x) {
return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
-};
+}
-var Gamma0256 = function(x) {
+function Gamma0256 (x) {
return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
-};
+}
-var Gamma1256 = function(x) {
+function Gamma1256 (x) {
return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
-};
-
-function readUint32BE (a, i) {
- return a[i] | (a[i+1]<<8) | (a[i+2]<<16) | (a[i+3]<<24)
}
Sha256.prototype._update = function(m) {
- var l = this._len
var M = this._dv
- var a, b, c, d, e, f, g, h, i, j;
- var _a, _b, _c, _d, _e, _f, _g, _h
- var T1, T2, t1, t2
var W = this._w
- var i = 0
-
+ var a, b, c, d, e, f, g, h, _a, _b, _c, _d, _e, _f, _g, _h
+ var T1, T2
_a = a = this._a | 0
_b = b = this._b | 0
@@ -121,85 +113,25 @@ Sha256.prototype._update = function(m) {
_g = g = this._g | 0
_h = h = this._h | 0
- if(true) {
-
- for (var j = 0; j < 64; j++) {
- var w = W[j] = j < 16
- ? M.getUint32(j * 4, BE)
- : 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;
- }
-
- } else {
-
- //this bit adapted from forge's sha256, which is faster.
- //although, their sha1 is slower.
- //javascript performance is mysterious.
- for(i = 0; i < 64; ++i) {
-
- if(i < 16) {
- W[i] = M.getUint32(i*4, BE)
- } else {
-
- // XOR word 2 words ago rot right 17, rot right 19, shft right 10
- t1 = W[i - 2];
- t1 =
- ((t1 >>> 17) | (t1 << 15)) ^
- ((t1 >>> 19) | (t1 << 13)) ^
- (t1 >>> 10);
- // XOR word 15 words ago rot right 7, rot right 18, shft right 3
- t2 = W[i - 15];
- t2 =
- ((t2 >>> 7) | (t2 << 25)) ^
- ((t2 >>> 18) | (t2 << 14)) ^
- (t2 >>> 3);
- // sum(t1, word 7 ago, t2, word 16 ago) modulo 2^32
- W[i] = (t1 + W[i - 7] + t2 + W[i - 16]) & 0xFFFFFFFF;
- }
-
- // round function
- // Sum1(e)
- s1 =
- ((e >>> 6) | (e << 26)) ^
- ((e >>> 11) | (e << 21)) ^
- ((e >>> 25) | (e << 7));
- // Ch(e, f, g) (optimized the same way as SHA-1)
- ch = g ^ (e & (f ^ g));
- // Sum0(a)
- s0 =
- ((a >>> 2) | (a << 30)) ^
- ((a >>> 13) | (a << 19)) ^
- ((a >>> 22) | (a << 10));
- // Maj(a, b, c) (optimized the same way as SHA-1)
- maj = (a & b) | (c & (a ^ b));
-
- // main algorithm
- t1 = h + s1 + ch + K[i] + W[i];
- t2 = s0 + maj;
- h = g;
- g = f;
- f = e;
- e = (d + t1) & 0xFFFFFFFF;
- d = c;
- c = b;
- b = a;
- a = (t1 + t2) & 0xFFFFFFFF;
- }
+ for (var j = 0; j < 64; j++) {
+ var w = W[j] = j < 16
+ ? M.getUint32(j * 4, BE)
+ : 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 = safe_add(a, _a) | 0
- this._b = safe_add(b, _b) | 0
- this._c = safe_add(c, _c) | 0
- this._d = safe_add(d, _d) | 0
- this._e = safe_add(e, _e) | 0
- this._f = safe_add(f, _f) | 0
- this._g = safe_add(g, _g) | 0
- this._h = safe_add(h, _h) | 0
+
+ this._a = (a + _a) | 0
+ this._b = (b + _b) | 0
+ this._c = (c + _c) | 0
+ this._d = (d + _d) | 0
+ this._e = (e + _e) | 0
+ this._f = (f + _f) | 0
+ this._g = (g + _g) | 0
+ this._h = (h + _h) | 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