srp_test.js 722 B

12345678910111213141516171819202122
  1. new sjcl.test.TestCase("SRP known-answer (RFC 5054) tests", function (cb) {
  2. if (!sjcl.keyexchange.srp) {
  3. this.unimplemented();
  4. cb && cb();
  5. return;
  6. }
  7. var i, kat = sjcl.test.vector.srp, tv, N, g, v, x;
  8. for (i=0; i<kat.length; i++) {
  9. tv = kat[i];
  10. N = sjcl.keyexchange.srp.knownGroup(tv.known_group_size).N;
  11. g = sjcl.keyexchange.srp.knownGroup(tv.known_group_size).g;
  12. tv.s = sjcl.codec.hex.toBits(tv.s);
  13. x = sjcl.keyexchange.srp.makeX(tv.I, tv.P, tv.s);
  14. this.require(sjcl.codec.hex.fromBits(x).toUpperCase() === tv.x, "srpx #"+i);
  15. v = sjcl.keyexchange.srp.makeVerifier(tv.I, tv.P, tv.s, N, g);
  16. this.require(v.equals(new sjcl.bn(tv.v)), "srpv #"+i);
  17. }
  18. cb && cb();
  19. });