summaryrefslogtreecommitdiffstats
path: root/test/sha512_huge_test.js
blob: e4b1fcbd82915f45ce6f598da5fadba338825433 (plain)
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-512 huge zero vector test", function (cb) {
  if (!sjcl.hash.sha512) {
    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.sha512(), tmpHasher, hash, bl;
  var kat = sjcl.test.vector.sha512huge;

  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.sha512(hasher);
      hash = tmpHasher.finalize();
      this.require(sjcl.codec.hex.fromBits(hash) == kat[i*bl], i*bl);
    }

    hasher.update(base);
  }

  cb && cb();
});