Skip to content

Commit c240625

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 c240625

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/crypto/rsa/pss.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ func (opts *PSSOptions) saltLength() int {
262262
// function. The opts argument may be nil, in which case sensible defaults are
263263
// used. If opts.Hash is set, it overrides hash.
264264
func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, digest []byte, opts *PSSOptions) ([]byte, error) {
265+
// if no random source has been passed
266+
// initialize with secure random from crypto/rand.Reader
267+
if rand == nil {
268+
rand = rand.Reader
269+
}
265270
if opts != nil && opts.Hash != 0 {
266271
hash = opts.Hash
267272
}

0 commit comments

Comments
 (0)