key-encoder-js
key-encoder-js copied to clipboard
separate out curves
Thanks for the PR @mvayngrib! Love how you added a bunch of new curves.
I can merge this in soon but it'd be great if you could add some tests in with at least one of these curves before I do. Would you be up for that?
@shea256 do you remember where you got the OpenSSL reference values?
I don't remember.
Here's one list thought: https://github.com/warner/python-ecdsa/blob/master/ecdsa/curves.py#L43
I think I got it from an RFC but I'm not sure which one at the moment unfortunately.
@mvayngrib Did you see the other curves in there?
@shea256 no, sadly i didn't. For now i'm just testing it by cross sign-verify native<=>elliptic, which passes (the code is non-deterministic, but since we're planning to use openssl references anyway, who cares).
also: i also added lazy-eval for creating instances of elliptic curves. They're very expensive to create so it's better not to pre-create them.
test('elliptic sign => native verify compat', function (t) {
var data = 'some data'
var algorithm = 'sha256'
var hash = crypto.createHash(algorithm).update(data).digest()
for (var name in aliases) {
var curve = curves[name].curve
var encoder = new KeyEncoder(name)
var key = curve.genKeyPair()
var sig = key.sign(hash).toDER('hex')
var pubHex = key.getPublic('hex')
var pub = encoder.encodePublic(pubHex, 'raw', 'pem')
var verified = crypto.createVerify(algorithm).update(data).verify(pub, sig, 'hex')
t.ok(verified)
}
t.end()
})
test('native sign => elliptic verify compat', function (t) {
var data = 'some data'
var algorithm = 'sha256'
var hash = crypto.createHash(algorithm).update(data).digest()
for (var name in aliases) {
var curve = curves[name].curve
var encoder = new KeyEncoder(name)
var ecdh = crypto.createECDH(aliases[name])
ecdh.generateKeys()
var priv = ecdh.getPrivateKey()
var pem = encoder.encodePrivate(priv, 'raw', 'pem')
var sig = crypto.createSign(algorithm).update(data).sign(pem, 'hex')
var verified = curve.keyFromPrivate(priv).verify(hash, sig)
t.ok(verified)
}
t.end()
})
@mvayngrib Thanks, great work!
I just incorporated your 2 commits and your tests in this latest PR: https://github.com/blockstack/key-encoder-js/pull/3
Please let me know what you think.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.