Skip to content

crypto/ecdh: provide and/or implement an interface #56052

Closed

Description

@rautammi

I am very sorry for being very late with this one. Would it be possible to expose PrivateKey as an interface, allowing one to create implementations of Curve and PrivateKey which utilizes a static private key from an HSM for ECDH operation? Somewhat following the idiom from crypto.Signer.

Activity

  1. added this to the Proposal milestone on Oct 5, 2022
  2. changed the title [-]proposal: affected/package: crypto/ecdh Support for PKCS#11[/-] [+]proposal: crypto/ecdh: Support for PKCS#11[/+] on Oct 5, 2022
  3. moved this to Incoming in Proposalson Oct 5, 2022
  4. ianlancetaylor commented on Oct 5, 2022

    @ianlancetaylor
    Contributor

    CC @golang/security

  5. ericlagergren commented on Oct 6, 2022

    @ericlagergren
    Contributor

    @rautammi alternatively, APIs that need an ECDH private key could accept an interface instead of requiring *ecdh.PrivateKey. There is already crypto.PrivateKey and crypto.PublicKey.

  6. ericchiang commented on Oct 6, 2022

    @ericchiang
    Contributor

    For reference, go-piv has supported ECDH backed by a YubiKey for a while now:

    https://pkg.go.dev/github.com/go-piv/piv-go/piv?utm_source=godoc#ECDSAPrivateKey.SharedKey

    I don't think crypto/ecdh is the place to support this? E.g. crypto/rsa and crypto/ecdsa don't support out-of-process private keys. If there are packages that want to support both crypto/ecdh and external keys, that interface probably belongs with those packages or in the crypto package (like crypto.Signer/crypto.Decrypter)

  7. rautammi commented on Oct 7, 2022

    @rautammi
    Author

    I think @ericchiang is right.
    It has been awesome, that well-behaving packages are using crypto.Signer, allowing one to, for example, very easily add PKCS#11 support for TLS or SSH authentication, without any changes to those packages at all.
    So, what we need, in addition to this crypto/ecdh, is some kind of crypto.Exchanger interface, which crypto/ecdh then implements, and which usage is recommended for any package agreeing shared secrets using a static private key.

  8. rautammi commented on Oct 7, 2022

    @rautammi
    Author

    I would say the person who invented crypto.Signer was a genius! Let she or he design an equally generic and future proof interface for key exchange too.

  9. rsc commented on Oct 12, 2022

    @rsc
    Contributor

    /cc @golang/security

  10. rsc commented on Oct 12, 2022

    @rsc
    Contributor

    This proposal has been added to the active column of the proposals project
    and will now be reviewed at the weekly proposal review meetings.
    — rsc for the proposal review group

  11. moved this from Incoming to Active in Proposalson Oct 12, 2022
  12. FiloSottile commented on Oct 19, 2022

    @FiloSottile
    Contributor

    I agree that it would be nice to have an interface type for key exchanges, and while it might be too late to come up with one for Go 1.20, we should make sure the crypto/ecdh package design is not hostile to one.

    Looking forward, it would probably be appropriate for it to fit the shape of KEMs, to work with PQC KEMs.

    A KEM has three operations: KeyGen, Encap, and Decap.

    KeyGen() -> public key, secret key
    Encapsulate(public key) -> ciphertext, shared key
    Decapsulate(secret key, ciphertext) -> shared key
    

    With crypto/ecdh,

    • KeyGen is ecdh.P256().GenerateKey()
    • Encap is ecdh.P256().GenerateKey() followed by ecdh.P256().ECDH(privateKey, peerPublicKey)
      • the ciphertext is just the generated public key
    • Decap is ecdh.P256().NewPublicKey() followed by ecdh.P256().ECDH(privateKey, peerPublicKey)

    because ECDH is very symmetrical.

    While thinking about this I also started having doubts on whether ECDH should be a method on Curve or on PrivateKey. My initial thinking was that a method on PrivateKey like KeyExchange(publicKey []byte) would make it possible for it to implement a Signer-like interface, but that only works for DH-like symmetrical KEMs that don't have a separate Encap and Decap. If we had such a method on PrivateKey, it would also make sense to move ECDH to PrivateKey.

    I'd be interested to hear proposals for KEM-friendly interfaces, and how crypto/ecdh might implement them. I went through a few options but found none that I liked so far.

  13. 16 remaining items

  14. changed the title [-]proposal: crypto/ecdh: provide and/or implement an interface[/-] [+]crypto/ecdh: provide and/or implement an interface[/+] on Nov 30, 2022
  15. moved this from Active to Accepted in Proposalson Nov 30, 2022
  16. modified the milestones: Proposal, Backlog on Nov 30, 2022
  17. modified the milestones: Backlog, Go1.20 on Jun 4, 2023
  18. removed this from Proposalson Dec 4, 2023
  19. added a commit that references this issue on Jan 8, 2024
  20. added a commit that references this issue on Feb 20, 2024
    dafc915
  21. locked and limited conversation to collaborators on Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions