1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
new sjcl.test.TestCase("SHA-256 huge zero vector test", function (cb) {
if (!sjcl.hash.sha256) {
this.unimplemented();
cb && cb();
return;
}
var base = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; // 128B
var w = sjcl.bitArray, i, mx, hasher = new sjcl.hash.sha256(), tmpHasher, hash, bl;
var kat = sjcl.test.vector.sha256huge;
base = w.concat(base, base); // 256 B
base = w.concat(base, base); // 512 B
base = w.concat(base, base); // 1024 B
bl = w.bitLength(base)/8;
mx = 312*1024*1024/bl;
for(i=0; i<=mx; ++i){
if ((i*bl) in kat){
tmpHasher = new sjcl.hash.sha256(hasher);
hash = tmpHasher.finalize();
this.require(sjcl.codec.hex.fromBits(hash) == kat[i*bl], i*bl);
}
hasher.update(base);
}
cb && cb();
});
|