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

Is there a specified reason to use sha256 in newRandomPrivateKey? #7

Closed
nanmu42 opened this issue Jun 14, 2018 · 2 comments
Closed

Comments

@nanmu42
Copy link

nanmu42 commented Jun 14, 2018

eos-go/ecc/privkey.go

Lines 25 to 40 in fbd70cf

func newRandomPrivateKey(randSource io.Reader) (*PrivateKey, error) {
rawPrivKey := make([]byte, 32)
written, err := io.ReadFull(randSource, rawPrivKey)
if err != nil {
return nil, fmt.Errorf("error feeding crypto-rand numbers to seed ephemeral private key: %s", err)
}
if written != 32 {
return nil, fmt.Errorf("couldn't write 32 bytes of randomness to seed ephemeral private key")
}
h := sha256.New()
h.Write(rawPrivKey)
privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), h.Sum(nil))
return &PrivateKey{Curve: CurveK1, privKey: privKey}, nil
}

Hello, fabulous work, love it. 🚀

Just curious, why not use random bytes directly?

@abourget
Copy link
Contributor

abourget commented Jul 6, 2018

Wow, that's a great question.

It was introduced in 7273b70 which seems unrelated to that change.. seems to have slipped in.

It's pretty much inconsequential, but I took it out. @ellipticasec can you review ae163a3 please ?

@nanmu42 nanmu42 closed this as completed Jul 6, 2018
@nanmu42
Copy link
Author

nanmu42 commented Jul 6, 2018

Thanks for your kind reply, cheers. 🍻

This issue was closed.
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