From 123b38e105342ca65392ba8e20a089fe405b0791 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Mon, 16 Mar 2015 16:42:12 -0700 Subject: [PATCH] crypto/{ecdsa,rsa}: always use io.ReadFull with crypto/rand.Reader. crypto/rand.Reader doesn't ensure that short reads don't happen. This change contains a couple of fixups where io.ReadFull wasn't being used with it. Change-Id: I3855b81f5890f2e703112eeea804aeba07b6a6b8 Reviewed-on: https://go-review.googlesource.com/7645 Reviewed-by: Minux Ma Reviewed-by: Andrew Gerrand --- src/crypto/ecdsa/ecdsa.go | 2 +- src/crypto/rsa/rsa.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/ecdsa/ecdsa.go b/src/crypto/ecdsa/ecdsa.go index 59902014df..d003f9d0b3 100644 --- a/src/crypto/ecdsa/ecdsa.go +++ b/src/crypto/ecdsa/ecdsa.go @@ -140,7 +140,7 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err entropylen = 32 } entropy := make([]byte, entropylen) - _, err = rand.Read(entropy) + _, err = io.ReadFull(rand, entropy) if err != nil { return } diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go index f9f6d25a89..99fa94e58a 100644 --- a/src/crypto/rsa/rsa.go +++ b/src/crypto/rsa/rsa.go @@ -102,7 +102,7 @@ func (priv *PrivateKey) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.D case *PKCS1v15DecryptOptions: if l := opts.SessionKeyLen; l > 0 { plaintext = make([]byte, l) - if _, err := rand.Read(plaintext); err != nil { + if _, err := io.ReadFull(rand, plaintext); err != nil { return nil, err } if err := DecryptPKCS1v15SessionKey(rand, priv, ciphertext, plaintext); err != nil {