-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Elliptic curve point compression #32
Comments
imo, did-key method spec should probably stick to compressed only... the main reason the NIST curves are uncompressed is that they are commonly represented uncompressed... I did the first version of them and now @troyronda and SecureKey have support for them as well... I am not sure how hard it would be to convert did key for nist curves to compressed, but if we can, we should IMO. |
Yes, because the smaller size URI is a desirable feature.
Let's just stick to compressed form, I don't see a need to support both. |
Some links on P-256 compressed form: https://tools.ietf.org/html/rfc5480 Looks like you simply add the last bit of the Y coordinate to 0x02 (used as the prefix value) such that the prefix will be either 0x02 or 0x03 and then you follow that with the X coordinate and that's it (the rest of the Y coordinate is dropped). |
One issue we have is that we only support did key variants that have some JWK representation, so we won't implement support for this until we can easily convert back and forth.... because we like interoperability with off the shelf JOSE libraries. I will need to take a look at bi-directional transformations to be sure its possible to support. |
You can use a library such as let ec = new require('elliptic').ec('p256')
undefined
> ec.genKeyPair().getPublic(true, 'hex')
'03413029cb9a5a4a0b087a9b8a060116d0d32bb22d14aebf7778215744811bb6ce'
> pub = ec.keyFromPublic('03413029cb9a5a4a0b087a9b8a060116d0d32bb22d14aebf7778215744811bb6ce', 'hex').getPublic(false, 'hex')
'04413029cb9a5a4a0b087a9b8a060116d0d32bb22d14aebf7778215744811bb6ce40780d7bb9e2e068879f443e05b21b8fc0b62c9c811008064d988856077e35e7' |
I have some code over here that supports raw public keys, compressed public keys, and uncompressed public keys for P-256. ceramicnetwork/js-ceramic#1418 |
Anyone on this thread want to take a stab at updating the test vectors in this repo to use the compressed from for P-256, P-384, P-521? just edits to the JSON files. |
I will look at it. I can use (or slightly modify) this [1] to create test vectors (given the raw or uncompressed public key input): By changing about 3 lines of code I believe that this could be written for P-384 and P-521. |
I get the following for the P-256 one:
|
did:key:zDnaeUKTWUXc1HDpGfKbEK31nKLN19yX5aunFd7VK1CUMeyJu Yes. I had one that looked similar in my tests. The length after the key: is 49 for both yours and mine. |
Okay. I started a pull request: #36 . I'll look at this again tomorrow when more awake. |
Awesome. Thanks. I am got the same thing. |
I think this is done, recommend closing. |
👍 |
I remember that P-521 had some problems. I recall writing some code for
P-256 and P-384 NIST curves with a generic wrapper for it. P-521 was
different, IIRC. I haven't touched this code in a while, but I thought I
should get back to that a few days ago. I could open up a PR when I get
to it, or whatever works.
…-Brent
On Thu, Sep 23, 2021 at 12:42 PM Joel Thorstensson ***@***.***> wrote:
👍
Note that multicodec table also have been updated to explicitly state that
keys should be compressed:
https://github.com/multiformats/multicodec/blob/master/table.csv#L136-L138
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#32 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAC4YL7PJKXBRDHPFS743DUDNRJZANCNFSM4YTT4IGA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@bshambaugh please consider raising a separate issue for that if you find anything wrong with P-521... |
The public keys in the test vectors for Secp256k1 are in compressed form (33 bytes), but for P-256 they are uncompressed (64 bytes, untagged). For Ed25519 they are compressed (32 bytes).
did:key
allow either form - compressed or uncompressed - for these key types? Or only a single form is allowed? Or either form allowed but one is preferred?The text was updated successfully, but these errors were encountered: