]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rsa: rsa.SignPSS with opts=nil shouldn't crash.
authorAdam Langley <agl@golang.org>
Mon, 5 Jan 2015 22:29:42 +0000 (14:29 -0800)
committerAdam Langley <agl@golang.org>
Tue, 6 Jan 2015 19:18:28 +0000 (19:18 +0000)
SignPSS is documented as allowing opts to be nil, but actually
crashes in that case. This change fixes that.

Change-Id: Ic48ff5f698c010a336e2bf720e0f44be1aecafa0
Reviewed-on: https://go-review.googlesource.com/2330
Reviewed-by: Minux Ma <minux@golang.org>
src/crypto/rsa/pss.go
src/crypto/rsa/pss_test.go

index e9f2908250cc3a2a9d3f2fc1c1a6cc875ccf6805..0a41814a4b1e7c7a772f5ba3850068cefe88fbe9 100644 (file)
@@ -255,7 +255,7 @@ func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []byte,
                saltLength = hash.Size()
        }
 
-       if opts.Hash != 0 {
+       if opts != nil && opts.Hash != 0 {
                hash = opts.Hash
        }
 
index 32e6fc39d291890bb17357f20d68af83f69aa474..cae24e58c6794ce5db502932f6504934bf4115cc 100644 (file)
@@ -189,6 +189,15 @@ func TestPSSOpenSSL(t *testing.T) {
        }
 }
 
+func TestPSSNilOpts(t *testing.T) {
+       hash := crypto.SHA256
+       h := hash.New()
+       h.Write([]byte("testing"))
+       hashed := h.Sum(nil)
+
+       SignPSS(rand.Reader, rsaPrivateKey, hash, hashed, nil)
+}
+
 func TestPSSSigning(t *testing.T) {
        var saltLengthCombinations = []struct {
                signSaltLength, verifySaltLength int