ecdsa_test.js 625 B

1234567891011121314151617181920212223242526272829
  1. new sjcl.test.TestCase("ECSA test", function (cb) {
  2. if (!sjcl.ecc) {
  3. this.unimplemented();
  4. cb && cb();
  5. return;
  6. }
  7. var keys = sjcl.ecc.ecdsa.generateKeys(192,0),
  8. hash = sjcl.hash.sha256.hash("The quick brown fox jumps over the lazy dog."),
  9. signature = keys.sec.sign(hash,0);
  10. try {
  11. keys.pub.verify(hash, signature);
  12. this.pass();
  13. } catch (e) {
  14. this.fail("good message rejected");
  15. }
  16. hash[1] ^= 8; // minor change to hash
  17. try {
  18. keys.pub.verify(hash, signature);
  19. this.fail();
  20. } catch (e) {
  21. this.pass("bad message accepted");
  22. }
  23. cb && cb();
  24. });