]> Cypherpunks repositories - gostls13.git/commit
crypto: randomly read an extra byte of randomness in some places.
authorAdam Langley <agl@golang.org>
Mon, 18 Sep 2017 21:49:21 +0000 (14:49 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 7 Jun 2018 15:09:25 +0000 (15:09 +0000)
commit6269dcdc24d74379d8a609ce886149811020b2cc
tree93fd7b86f497fbd87dd1cfbecb409454d3a8a456
parentdb4675f2de3a09d198cbc9bbf5120eec4fb54338
crypto: randomly read an extra byte of randomness in some places.

Code has ended up depending on things like RSA's key generation being
deterministic given a fixed random Reader. This was never guaranteed and
would prevent us from ever changing anything about it.

This change makes certain calls randomly (based on the internal
fastrand) read an extra byte from the random Reader. This helps to
ensure that code does not depend on internal details.

I've not added this call in the key generation of ECDSA and DSA because,
in those cases, key generation is so obvious that it probably is
acceptable to do the obvious thing and not worry about code that depends
on that.

This does not affect tests that use a Reader of constant bytes (e.g. a
zeroReader) because shifting such a stream is a no-op. The stdlib uses
this internally (which is fine because it can be atomically updated if
the crypto libraries change).

It is possible that external tests could be doing the same and would
thus break if we ever, say, tweaked the way RSA key generation worked.
I feel that addressing that would be more effort than it's worth.

Fixes #21915

Change-Id: I84cff2e249acc921ad6eb5527171e02e6d39c530
Reviewed-on: https://go-review.googlesource.com/64451
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
src/crypto/dsa/dsa.go
src/crypto/ecdsa/ecdsa.go
src/crypto/internal/randutil/randutil.go [new file with mode: 0644]
src/crypto/rsa/pkcs1v15.go
src/crypto/rsa/rsa.go
src/go/build/deps_test.go