Skip to content
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

Road to secp256r1 support #2001

Closed
13 tasks done
webmaster128 opened this issue Jan 23, 2024 · 6 comments
Closed
13 tasks done

Road to secp256r1 support #2001

webmaster128 opened this issue Jan 23, 2024 · 6 comments
Milestone

Comments

@webmaster128
Copy link
Member

webmaster128 commented Jan 23, 2024

It has become clear that we want ECDSA secp256r1 signature verification support to allow app level signature verification using a popular industry standard curve. Now that if is answered, let' move on to when and how. Given that adding a new crypto API is something we cannot easily revert once contracts rely on it, we need to ensure that the new API is correct and behaves as desired.

Open Questions

  • Should we accept low-S and high-S signatures? Yes, because this is how ECDSA works and secp256k1_verify behaves today. An app level protocol may further restrict which sigantures are valid. Those extra checks have to be implemented separately, for now in Wasm.
  • Should we implement secp256r1_recover_pubkey? Why not, we have it for the other curve already
  • Do we need a DER decoder for signatures (decoding DER in a way that does not allow malleability is pretty hard)?: I'd say no, since this is not trivial and needed for BTC only

Blockers

@aumetra
Copy link
Member

aumetra commented Mar 18, 2024

The API seems fine. Checking through webauthn-rs, the API is operating on prehashed data, so we don't even assume a message digest. As for the key, that requires a bit more conversion juggling. The EC key has to be converted from its COSE format into SEC1.

This involves:

  • Parsing the CBOR and COSE
  • Parsing the scalars out of the COSE
  • Constructing a non-zero scalar
  • Converting it into an p256 secret key
  • Encoding it into SEC1
  • Passing it to the API

But we can't cover that, really. Unless we want an API that accepts raw scalars (that'd be a big no from me) or implement COSE ourselves (is it worth it? Contracts can do that themselves.)
Otherwise the raw cryptography primitives seem totally usable.

@aumetra
Copy link
Member

aumetra commented Mar 18, 2024

But then again, I haven't implemented WebAuthn/FIDO myself yet, so I'm not 100% sure.

@webmaster128
Copy link
Member Author

That sounds interesting. Can we try to implement all those conversions in an example contract? That way we can show contract developers what needs to be done without having to expose that functionality as part of our APIs.

Converting it into an p256 secret key

Public key, right? On chain we only do signature verification.

@aumetra
Copy link
Member

aumetra commented Mar 18, 2024

Public key, right? On chain we only do signature verification.

Ah, yes, public key. Not private key. Mixed them up in my head for a sec

@aumetra
Copy link
Member

aumetra commented Mar 27, 2024

Seems like the last checklist item is done now. Can we mark this as done? 🎉

@webmaster128
Copy link
Member Author

It is, well done and thanks 🐎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants