Skip to content

Commit

Permalink
rsa digital sign: set pss option salt length equal to digest size
Browse files Browse the repository at this point in the history
  • Loading branch information
wuriyanto48 committed Dec 11, 2022
1 parent eb14e1b commit 9e5b59b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions rsax/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func signWithPSS(privateKey *rsa.PrivateKey,

msgHashSum := d.Sum(nil)

signature, err := rsa.SignPSS(rand.Reader, privateKey, h, msgHashSum, nil)
signature, err := rsa.SignPSS(rand.Reader,
privateKey, h, msgHashSum, &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash})
if err != nil {
return nil, err
}
Expand All @@ -41,7 +42,8 @@ func signWithPSSIO(privateKey *rsa.PrivateKey,

msgHashSum := d.Sum(nil)

signature, err := rsa.SignPSS(rand.Reader, privateKey, h, msgHashSum, nil)
signature, err := rsa.SignPSS(rand.Reader,
privateKey, h, msgHashSum, &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash})
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions rsax/verify_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func verifySignatureWithPSS(publicKey *rsa.PublicKey,

msgHashSum := d.Sum(nil)

return rsa.VerifyPSS(publicKey, h, msgHashSum, signature, nil)
return rsa.VerifyPSS(publicKey, h,
msgHashSum, signature, &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash})
}

func verifySignatureWithPSSIO(publicKey *rsa.PublicKey,
Expand All @@ -35,7 +36,8 @@ func verifySignatureWithPSSIO(publicKey *rsa.PublicKey,

msgHashSum := d.Sum(nil)

return rsa.VerifyPSS(publicKey, h, msgHashSum, signature, nil)
return rsa.VerifyPSS(publicKey, h,
msgHashSum, signature, &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash})
}

// VerifySignatureWithPSSMd5 will verify signature data with RSA PSS and MD5
Expand Down

0 comments on commit 9e5b59b

Please sign in to comment.