-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
crypto uses rand.Reader directly. #143
Comments
This commit fixed the notoriously annoying "Malformed Public Key" problem. The issue was that sometimes the byte representation of the points (x,y in big.Int) generated would be one less byte than expected. This is simply because (* big.Int) Write uses the least amount of bytes needed for the int. I instead changed the marshalling/unmarshalling to do exactly what stdlib crypto/tls does: use `ellipctic.Marshal` which marshals according to the ANSI X9.62 standard. http://golang.org/pkg/crypto/elliptic/#Marshal http://golang.org/src/pkg/crypto/tls/key_agreement.go#L214 ```Go // crypto/tls ka.privateKey, x, y, err = elliptic.GenerateKey(ka.curve, config.rand()) ecdhePublic := elliptic.Marshal(ka.curve, x, y) // ipfs/crypto priv, x, y, err := elliptic.GenerateKey(curve, rand.Reader) pubKey := elliptic.Marshal(curve, x, y) ``` ((Warning: we're using `rand.Reader` directly, which we shouldn't do, as it can be seeded. We should use a configured source, as crypto/tls. Flagged in #143)) This makes me think we should re-use a lot of their datastructures and functions directly (e.g. ecdheKeyAgreement) Fixed: #135 cc @Bren2010 @whyrusleeping
👍 |
In http://golang.org/src/pkg/crypto/tls/common.go there is:
and then:
So by default it will use rand.Reader. We could do the same but I am not sure we should add the Rand io.Reader to our Config struct in config/config.go. Our config stuct looks like:
|
Yeah, sounds good to me. Should be configurable, but default to
That's the config var matching the config file, so yeah, let's not put it there. If we want a single random Reader per node, we could add it directly to core/core.IpfsNode. In any case, the random Reader should at some point get to |
I don't think the purpose of having a The default [1] http://www.2uo.de/myths-about-urandom/ |
thanks @rht -- that makes sense. probably still good to do. another reason is to mock it out to run tests faster |
|
@rht but for tests, we dont care about randomness, we just want it to be 'random enough' and fast so our tests can not take forever |
From https://travis-ci.org/ipfs/go-ipfs/jobs/65047346, For the sharness test, I replaced https://github.com/ipfs/go-ipfs/blob/master/test/sharness/lib/test-lib.sh#L250 |
hardware differs. for my macbook air, |
ohh wow, yeah. submit a PR? |
The changes are within standard deviation #1326, so it's not much apparently. The PR only makes the checks more granular. |
closing, if further discussion is warranted open a new issue. |
Fix panic in FindPeersConnectedToPeer
We use
rand.Reader
directly in the crypto package, which makes it depend on the global seed. We should be using a specific, configurablerand.Source
, likecrypto/tls
:http://golang.org/src/pkg/crypto/tls/key_agreement.go#L214
The text was updated successfully, but these errors were encountered: