What version of Go are you using (go version)?
$ go version
go version go1.13.3 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
What did you do?
- Consistency needed: Change GenerateKey() to return only private key with error because it seems awkward that it returns both public key and private key while NewKeyFromSeed() returns only private key. In addition, it is so confused for someone who are not familiar with crypto/ed25519 package
- I know there might be a huge side effect when standard package is changed, but my opinion is that it worth modifying it right now, considering the current increase of gophers. As more gophers mean that more go code will be, this is perfect time to change it
- As-is
// GenerateKey generates a public/private key pair using entropy from rand.
// If rand is nil, crypto/rand.Reader will be used.
func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
if rand == nil {
rand = cryptorand.Reader
}
seed := make([]byte, SeedSize)
if _, err := io.ReadFull(rand, seed); err != nil {
return nil, nil, err
}
privateKey := NewKeyFromSeed(seed)
publicKey := make([]byte, PublicKeySize)
copy(publicKey, privateKey[32:])
return publicKey, privateKey, nil
}
- To-be
// GenerateKey generates a private pair using entropy from rand.
// If rand is nil, crypto/rand.Reader will be used.
func GenerateKey(rand io.Reader) (PrivateKey, error) {
if rand == nil {
rand = cryptorand.Reader
}
seed := make([]byte, SeedSize)
if _, err := io.ReadFull(rand, seed); err != nil {
return nil, nil, err
}
privateKey := NewKeyFromSeed(seed)
return privateKey, nil
}
What did you expect to see?
- Better coding experiment. No more confusion in package document(https://pkg.go.dev/crypto/ed25519?tab=doc)
- Improve code consistency for not only package itself but also codes using it
What did you see instead?
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env)?go envOutputWhat did you do?
What did you expect to see?
What did you see instead?