ecdh, ecdsa tests
This commit is contained in:
15
test/ecdh_test.js
Normal file
15
test/ecdh_test.js
Normal file
@@ -0,0 +1,15 @@
|
||||
new sjcl.test.TestCase("ECDH test", function (cb) {
|
||||
if (!sjcl.ecc) {
|
||||
this.unimplemented();
|
||||
cb && cb();
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = sjcl.ecc.elGamal.generateKeys(192,0),
|
||||
keyTag = keys.pub.kem(0),
|
||||
key2 = keys.sec.unkem(keyTag.tag);
|
||||
|
||||
this.require(sjcl.bitArray.equal(keyTag.key, key2));
|
||||
|
||||
cb && cb();
|
||||
});
|
||||
29
test/ecdsa_test.js
Normal file
29
test/ecdsa_test.js
Normal file
@@ -0,0 +1,29 @@
|
||||
new sjcl.test.TestCase("ECSA test", function (cb) {
|
||||
if (!sjcl.ecc) {
|
||||
this.unimplemented();
|
||||
cb && cb();
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = sjcl.ecc.ecdsa.generateKeys(192,0),
|
||||
hash = sjcl.hash.sha256.hash("The quick brown fox jumps over the lazy dog."),
|
||||
signature = keys.sec.sign(hash,0);
|
||||
|
||||
try {
|
||||
keys.pub.verify(hash, signature);
|
||||
this.pass();
|
||||
} catch (e) {
|
||||
this.fail("good message rejected");
|
||||
}
|
||||
|
||||
hash[1] ^= 8; // minor change to hash
|
||||
|
||||
try {
|
||||
keys.pub.verify(hash, signature);
|
||||
this.fail();
|
||||
} catch (e) {
|
||||
this.pass("bad message accepted");
|
||||
}
|
||||
|
||||
cb && cb();
|
||||
});
|
||||
@@ -13,7 +13,9 @@ function testCore(coreName, cb) {
|
||||
"sha256_test_brute_force.js",
|
||||
"hmac_test.js",
|
||||
"hmac_vectors.js",
|
||||
"pbkdf2_test.js"
|
||||
"pbkdf2_test.js",
|
||||
"ecdh_test.js",
|
||||
"ecdsa_test.js"
|
||||
], i;
|
||||
|
||||
for (i=1; i<testFiles.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user