2 * Test SHA-256 using an ad-hoc iterative technique.
3 * This uses a string buffer which has n characters on the nth iteration.
4 * Each iteration, the buffer is hashed and the hash is converted to a string.
5 * The first two characters of the string are prepended to the buffer, then the
6 * last character of the buffer is removed. This way, neither the beginning nor
7 * the end of the buffer is fixed.
9 * The hashes from each output step are also hashed together into one final hash.
10 * This is compared against a final hash which was computed with SSL.
13 new sjcl
.test
.TestCase("SHA-256 iterative", function (cb
) {
14 if (!sjcl
.hash
.sha256
) {
20 var toBeHashed
= "", cumulative
= new sjcl
.hash
.sha256(), hash
, thiz
=this;
21 browserUtil
.cpsIterate(function (i
, cbb
) {
22 for (var n
=100*i
; n
<100*(i
+1); n
++) {
23 hash
= sjcl
.hash
.sha256
.hash(toBeHashed
);
24 hash
= sjcl
.codec
.hex
.fromBits(hash
);
25 cumulative
.update(hash
);
26 toBeHashed
= (hash
.substring(0,2)+toBeHashed
).substring(0,n
+1);
29 }, 0, 10, true, function () {
30 hash
= sjcl
.codec
.hex
.fromBits(cumulative
.finalize());
31 thiz
.require(hash
=== "f305c76d5d457ddf04f1927166f5e13429407049a5c5f29021916321fcdcd8b4");