go-libp2p: `GenerateSecp256k1` doesn't use the provided random reader source.

Based on the latest version (33.2).

Currently the GenerateSecp256k1Key(src io.Reader) accepts a io.Reader parameter to use as its source of random ness to generate the new key, however it doesn’t actually use the provided reader, and instead uses the default random reader within the secp256k1 package.

However, the underlying cryptographic package does support using a provided source of randomness as seen here.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

We don’t have to read the extra byte, but I also don’t want to make any guarantees. Otherwise, it becomes hard to change the underlying secp256k1 library.

Agreed on not making any future guarantees on determinism. We may decide to switch to a library that doesn’t even take a reader and that should be fine.

For tests, maybe it makes sense to use a fixed key rather than a fixed seed? It’s not as elegant, but we can and will guarantee a key will always behave the same for a given cipher.

My suggestion would be for us to simply forward the arguments and not add our opinion to what the underlying crypto library does. As well as update the doc comment to assert that we make no guarantees on determinism of the key generation between go-libp2p versions.

That might mean it doesn’t server your use case @jsimnz of using a seed to deterministically generate keys, but that would break if we ever switch to a library that doesn’t support an io.Reader or doesn’t support deterministic generation of keys (which some do in an attempt to be foolproof). Would using a fixed key instead (as suggested earlier in my comment) help?

I’m fine doing the same thing as the Go stdlib’s practice of maybeReadByte