aes_test.js 534 B

123456789101112131415161718
  1. new sjcl.test.TestCase("AES official known-answer tests", function (cb) {
  2. if (!sjcl.cipher.aes) {
  3. this.unimplemented();
  4. cb && cb();
  5. return;
  6. }
  7. var i, kat = sjcl.test.vector.aes, tv, len, aes;
  8. for (i=0; i<kat.length; i++) {
  9. tv = kat[i];
  10. len = 32 * tv.key.length;
  11. aes = new sjcl.cipher.aes(tv.key);
  12. this.require(sjcl.bitArray.equal(aes.encrypt(tv.pt), tv.ct), "encrypt "+len+" #"+i);
  13. this.require(sjcl.bitArray.equal(aes.decrypt(tv.ct), tv.pt), "decrypt "+len+" #"+i);
  14. }
  15. cb && cb();
  16. });