hmac_test.js 468 B

123456789101112131415
  1. new sjcl.test.TestCase("HMAC official test vectors", function (cb) {
  2. if (!sjcl.misc.hmac || !sjcl.hash.sha256) {
  3. this.unimplemented();
  4. cb && cb();
  5. return;
  6. }
  7. var i, kat = sjcl.test.vector.hmac, tv, h=sjcl.codec.hex, out;
  8. for (i=0; i<kat.length; i++) {
  9. tv = kat[i];
  10. out = h.fromBits((new sjcl.misc.hmac(h.toBits(tv.key))).mac(h.toBits(tv.data)));
  11. this.require (out.substr(0,tv.mac.length) == tv.mac, "hmac #"+i);
  12. }
  13. cb && cb();
  14. });