Skip to content

Commit 18de9fc

Browse files
committed
crypto/rsa: add rand initialization for rsa.SignPSS
If nil as random source is being passed to rsa.SignPSS this is going to lead to a nil pointer dereference and invalid memory access. This commit intents to this fix via initializing a secure random source with crypto/rand.Reader
1 parent b137746 commit 18de9fc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/crypto/rsa/pss.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,14 @@ func (opts *PSSOptions) saltLength() int {
260260
//
261261
// digest must be the result of hashing the input message using the given hash
262262
// function. The opts argument may be nil, in which case sensible defaults are
263-
// used. If opts.Hash is set, it overrides hash.
263+
// used. If opts.Hash is set, it overrides hash. The rand argument may be nil
264+
// if nil rand will get initialized via crypto/rand.Reader
264265
func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, digest []byte, opts *PSSOptions) ([]byte, error) {
266+
// if no random source has been passed
267+
// initialize with secure random from crypto/rand.Reader
268+
if rand == nil {
269+
rand = rand.Reader
270+
}
265271
if opts != nil && opts.Hash != 0 {
266272
hash = opts.Hash
267273
}

0 commit comments

Comments
 (0)