Description
There are a few crypto APIs that take an io.Reader
as a source of random bytes, but that don't commit to how those bytes are used. This caused issues over and over, for example any time we wanted to change the algorithm. These days we both document that they are not deterministic, and use randutil.MaybeReadByte
to somewhat enforce it. See #58637.
Now that we have GODEBUGs, it might be time to rip the band-aid off. I propose we start ignoring the random io.Reader
parameter of the following APIs, and always use the system random source (crypto/internal/sysrand.Read
, not crypto/rand.Reader
which may be overridden by the application).
rsa.GenerateKey
andrsa.GenerateMultiPrimeKey
rsa.EncryptPKCS1v15
ecdsa.GenerateKey
ecdsa.SignASN1
,ecdsa.Sign
, andecdsa.PrivateKey.Sign
ecdh.Curve.GenerateKey
Using GODEBUG=cryptocustomrand=1
restores the old behavior. (Suggestions for a better name welcome.) This is a GODEBUG that I would like to remove in a few releases.
rsa.SignPKCS1v15
is not randomized, while rsa.SignPSS
and rsa.EncryptOAEP
have a fairly well-specified way to use random bytes. Aside from those and ed25519.GenerateKey
(see below), I think I listed all APIs in non-deprecated packages that take a random io.Reader
.
This might be an issue for the crypto/tls tests, which defuse MaybeReadByte
by producing a stream of identical bytes. That's an abuse of GenerateKey anyway, because there is no guarantee that algorithms that expect random inputs will work with constant repeating streams. See for example #70643.
ed25519.GenerateKey
is a weird exception in that it is well defined, but also documented to use crypto/rand.Reader
if nil is passed. This is annoying because it forces a dependency on crypto/rand
and therefore on math/big
. We can't just use crypto/internal/sysrand.Read
because the user might have overridden crypto/rand.Reader
. I am tempted to also propose replacing "crypto/rand.Reader
" with "the system random source" but it's probably not worth the risk.
/cc @golang/security
Metadata
Metadata
Assignees
Type
Projects
Status