// well-specified number of random bytes is included in the signature, in a
// well-specified way.
+ if opts != nil && opts.Hash != 0 {
+ hash = opts.Hash
+ }
+
if boring.Enabled && rand == boring.RandReader {
bkey, err := boringPrivateKey(priv)
if err != nil {
}
boring.UnreachableExceptTests()
- if opts != nil && opts.Hash != 0 {
- hash = opts.Hash
- }
-
saltLength := opts.saltLength()
switch saltLength {
case PSSSaltLengthAuto:
. "crypto/rsa"
"crypto/sha1"
"crypto/sha256"
+ "crypto/sha512"
"encoding/hex"
"math/big"
"os"
t.Fatal("VerifyPSS unexpected success")
}
}
+
+func TestHashOverride(t *testing.T) {
+ key, err := GenerateKey(rand.Reader, 1024)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ digest := sha512.Sum512([]byte("message"))
+ // opts.Hash overrides the passed hash argument.
+ sig, err := SignPSS(rand.Reader, key, crypto.SHA256, digest[:], &PSSOptions{Hash: crypto.SHA512})
+ if err != nil {
+ t.Fatalf("SignPSS unexpected error: got %v, want nil", err)
+ }
+
+ // VerifyPSS has the inverse behavior, opts.Hash is always ignored, check this is true.
+ if err := VerifyPSS(&key.PublicKey, crypto.SHA512, digest[:], sig, &PSSOptions{Hash: crypto.SHA256}); err != nil {
+ t.Fatalf("VerifyPSS unexpected error: got %v, want nil", err)
+ }
+}