Fixup curve25519 module
Rename methods on the curve25519 interface to be a bit more high level. Cleanup emscripten wrapper class, wrap long lines and such. Also add a grunt task alias for building the emscripten compiled curve implementation.
This commit is contained in:
parent
a1a528ccdd
commit
2f58ea5f3a
6 changed files with 74 additions and 51 deletions
|
@ -20,17 +20,17 @@
|
|||
* We don't run any tests here, just define an abstract test function
|
||||
* that excercises our requirements for curve25519 interface, which are
|
||||
*
|
||||
* privTopub(privateKey)
|
||||
* keyPair(privateKey)
|
||||
* takes a 32-byte private key array buffer and outputs the corresponding
|
||||
* public key as an array buffer
|
||||
*
|
||||
* ECDHE(publicKey, privateKey)
|
||||
* sharedSecret(publicKey, privateKey)
|
||||
* computes a shared secret from two curve25519 keys using the given keys
|
||||
*
|
||||
* Ed25519Sign(privateKey, message)
|
||||
* sign(privateKey, message)
|
||||
* computes a signature for the given message using a private key
|
||||
*
|
||||
* Ed25519Verify(publicKey, message, signature)
|
||||
* verify(publicKey, message, signature)
|
||||
* verifies a signature for the given message using a public key
|
||||
*
|
||||
*/
|
||||
|
@ -45,16 +45,16 @@ var test_curve25519_implementation = function(implementation) {
|
|||
var bob_pub = hexToArrayBuffer("de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f");
|
||||
var shared_sec = hexToArrayBuffer("4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742");
|
||||
|
||||
describe("privToPub", function() {
|
||||
describe("keyPair", function() {
|
||||
it ('converts alice private keys to a keypair', function(done) {
|
||||
implementation.privToPub(alice_bytes).then(function(keypair) {
|
||||
implementation.keyPair(alice_bytes).then(function(keypair) {
|
||||
assertEqualArrayBuffers(keypair.privKey, alice_priv);
|
||||
assertEqualArrayBuffers(keypair.pubKey, alice_pub);
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
it ('converts bob private keys to a keypair', function(done) {
|
||||
implementation.privToPub(bob_bytes).then(function(keypair) {
|
||||
implementation.keyPair(bob_bytes).then(function(keypair) {
|
||||
assertEqualArrayBuffers(keypair.privKey, bob_priv);
|
||||
assertEqualArrayBuffers(keypair.pubKey, bob_pub);
|
||||
done();
|
||||
|
@ -62,15 +62,15 @@ var test_curve25519_implementation = function(implementation) {
|
|||
});
|
||||
});
|
||||
|
||||
describe("ECDHE", function() {
|
||||
describe("sharedSecret", function() {
|
||||
it("computes the shared secret for alice", function(done) {
|
||||
implementation.ECDHE(bob_pub, alice_priv).then(function(secret) {
|
||||
implementation.sharedSecret(bob_pub, alice_priv).then(function(secret) {
|
||||
assertEqualArrayBuffers(shared_sec, secret);
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
it("computes the shared secret for bob", function(done) {
|
||||
implementation.ECDHE(alice_pub, bob_priv).then(function(secret) {
|
||||
implementation.sharedSecret(alice_pub, bob_priv).then(function(secret) {
|
||||
assertEqualArrayBuffers(shared_sec, secret);
|
||||
done();
|
||||
}).catch(done);
|
||||
|
@ -81,21 +81,21 @@ var test_curve25519_implementation = function(implementation) {
|
|||
var pub = hexToArrayBuffer("55f1bfede27b6a03e0dd389478ffb01462e5c52dbbac32cf870f00af1ed9af3a");
|
||||
var msg = hexToArrayBuffer("617364666173646661736466");
|
||||
var sig = hexToArrayBuffer("2bc06c745acb8bae10fbc607ee306084d0c28e2b3bb819133392473431291fd0dfa9c7f11479996cf520730d2901267387e08d85bbf2af941590e3035a545285");
|
||||
describe("Ed25519Sign", function() {
|
||||
describe("sign", function() {
|
||||
it("computes the signature", function(done) {
|
||||
implementation.Ed25519Sign(priv, msg).then(function(signature) {
|
||||
implementation.sign(priv, msg).then(function(signature) {
|
||||
assertEqualArrayBuffers(sig, signature);
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ed25519Verify", function() {
|
||||
describe("verify", function() {
|
||||
it("throws on bad signature", function(done) {
|
||||
var badsig = sig.slice(0);
|
||||
new Uint8Array(badsig).set([0], 0);
|
||||
|
||||
implementation.Ed25519Verify(pub, msg, badsig).catch(function(e) {
|
||||
implementation.verify(pub, msg, badsig).catch(function(e) {
|
||||
if (e.message === 'Invalid signature') {
|
||||
done();
|
||||
} else { throw e; }
|
||||
|
@ -103,7 +103,7 @@ var test_curve25519_implementation = function(implementation) {
|
|||
});
|
||||
|
||||
it("does not throw on good signature", function(done) {
|
||||
implementation.Ed25519Verify(pub, msg, sig).then(done).catch(done);
|
||||
implementation.verify(pub, msg, sig).then(done).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue