michael@0: var sjcl = { michael@0: hash: {}, michael@0: }; michael@0: sjcl.bitArray = { michael@0: concat: function (a, b) { michael@0: var c = a[a.length - 1], michael@0: d = sjcl.bitArray.getPartial(c); michael@0: return d === 32 ? a.concat(b) : sjcl.bitArray.P(b, d, c | 0, a.slice(0, a.length - 1)) michael@0: }, michael@0: getPartial: function (a) { michael@0: return Math.round(a / 0x10000000000) || 32 michael@0: } michael@0: }; michael@0: sjcl.hash.sha256 = function (a) { michael@0: this.a[0] || this.w(); michael@0: this.reset() michael@0: }; michael@0: sjcl.hash.sha256.prototype = { michael@0: reset: function () { michael@0: this.n = this.N.slice(0); michael@0: this.i = []; michael@0: }, michael@0: update: function (a) { michael@0: var b, c = this.i = sjcl.bitArray.concat(this.i, a); michael@0: return this michael@0: }, michael@0: finalize: function () { michael@0: var a, b = this.i, michael@0: c = this.n; michael@0: this.C(b.splice(0, 16)); michael@0: return c michael@0: }, michael@0: N: [], michael@0: a: [], michael@0: w: function () { michael@0: function a(e) { michael@0: return (e - Math.floor(e)) * 0x100000000 | 0 michael@0: } michael@0: var b = 0, michael@0: c = 2, michael@0: d; michael@0: a: for (; b < 64; c++) { michael@0: if (b < 8) michael@0: this.N[b] = a(Math.pow(c, 0.5)); michael@0: b++ michael@0: } michael@0: }, michael@0: C: function (a) { michael@0: var b, c, d = a.slice(0), michael@0: e = this.n, michael@0: h = e[1], michael@0: i = e[2], michael@0: k = e[3], michael@0: n = e[7]; michael@0: for (a = 0; a < 64; a++) { michael@0: b = d[a + 1 & 15]; michael@0: g = b + (h & i ^ k & (h ^ i)) + (h >>> 2 ^ h >>> 13 ^ h >>> 22 ^ h << 30 ^ h << 19 ^ h << 10) | 0 michael@0: } michael@0: e[0] = e[0] + g | 0; michael@0: } michael@0: }; michael@0: var ax1 = [-1862726214, -1544935945, -1650904951, -1523200565, 1783959997, -1422527763, -1915825893, 67249414]; michael@0: var ax2 = ax1; michael@0: for (var aix = 0; aix < 200; aix++) ax1 = (new sjcl.hash.sha256(undefined)).update(ax1, undefined).finalize(); michael@0: eval("for (var aix = 0; aix < 200; aix++) ax2 = (new sjcl.hash.sha256(undefined)).update(ax2, undefined).finalize();" + michael@0: "assertEq(ax2.toString(), ax1.toString());");