Skip to content

Commit e5486fd

Browse files
committed
sha256: extract branches out
1 parent b044c10 commit e5486fd

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

sha256.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ function Gamma1256 (x) {
8787

8888
Sha256.prototype._update = function(M) {
8989
var W = this._w
90-
var T1, T2
9190

9291
var a = this._a | 0
9392
var b = this._b | 0
@@ -98,17 +97,30 @@ Sha256.prototype._update = function(M) {
9897
var g = this._g | 0
9998
var h = this._h | 0
10099

101-
for (var j = 0; j < 64; j++) {
102-
var w = W[j] = j < 16
103-
? M.readInt32BE(j * 4)
104-
: Gamma1256(W[j - 2]) + W[j - 7] + Gamma0256(W[j - 15]) + W[j - 16]
100+
var j = 0
105101

106-
T1 = h + Sigma1256(e) + Ch(e, f, g) + K[j] + w
102+
function calcW() { return Gamma1256(W[j - 2]) + W[j - 7] + Gamma0256(W[j - 15]) + W[j - 16] }
103+
function loop(w) {
104+
W[j] = w
107105

108-
T2 = Sigma0256(a) + Maj(a, b, c);
109-
h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2;
106+
var T1 = h + Sigma1256(e) + Ch(e, f, g) + K[j] + w
107+
var T2 = Sigma0256(a) + Maj(a, b, c);
108+
109+
h = g;
110+
g = f;
111+
f = e;
112+
e = d + T1;
113+
d = c;
114+
c = b;
115+
b = a;
116+
a = T1 + T2;
117+
118+
j++
110119
}
111120

121+
while (j < 16) loop(M.readInt32BE(j * 4))
122+
while (j < 64) loop(calcW())
123+
112124
this._a = (a + this._a) | 0
113125
this._b = (b + this._b) | 0
114126
this._c = (c + this._c) | 0

0 commit comments

Comments
 (0)