golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.22k stars 17.7k forks source link

crypto: public X,Y from fixed private key #70407

Closed 3052 closed 4 days ago

3052 commented 4 days ago

Proposal Details

I am seeing no way to return the public X,Y from a fixed private key. this creates a fixed private key:

https://pkg.go.dev/crypto/ecdh#Curve.NewPrivateKey

then you can get the public key:

https://pkg.go.dev/crypto/ecdh#PrivateKey.PublicKey

but it stops after that because they X,Y are not available. you can create a private key like this:

https://pkg.go.dev/crypto/ecdsa#GenerateKey

then get X,Y via

  1. https://pkg.go.dev/crypto/ecdsa#PrivateKey.PublicKey
  2. https://pkg.go.dev/crypto/ecdsa#PublicKey.X
  3. https://pkg.go.dev/crypto/ecdsa#PublicKey.Y

but I see no way to create a fixed private key. even if you constructed a deterministic rand:

func GenerateKey(c elliptic.Curve, rand io.Reader) (*PrivateKey, error)

it seems it wouldnt matter:

Note that the returned key does not depend deterministically on the bytes read from rand, and may change between calls and/or between versions.

for prior art, you can do this with Python:

https://pycryptodome.readthedocs.io/en/latest/src/public_key/ecc.html#Crypto.PublicKey.ECC.EccKey

gabyhelp commented 4 days ago

Related Issues

Related Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

seankhliao commented 4 days ago

the x509 marshal/unmarshal will get you an ecdsa key.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions