Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail-safe check on RSA #72

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ func (rs *rsaSigner) Algorithm() Algorithm {
return rs.alg
}

// Sign signs digest with the private key, possibly using entropy from rand.
// Sign signs digest with the private key, using entropy from rand.
// The resulting signature should follow RFC 8152 section 8.
//
// Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-8
func (rs *rsaSigner) Sign(rand io.Reader, digest []byte) ([]byte, error) {
hash, _ := rs.alg.hashFunc()
hash, ok := rs.alg.hashFunc()
if !ok {
return nil, ErrInvalidAlgorithm
}
return rs.key.Sign(rand, digest, &rsa.PSSOptions{
SaltLength: rsa.PSSSaltLengthEqualsHash, // defined in RFC 8230 sec 2
Hash: hash,
Expand All @@ -49,7 +52,10 @@ func (rv *rsaVerifier) Algorithm() Algorithm {
//
// Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-8
func (rv *rsaVerifier) Verify(digest []byte, signature []byte) error {
hash, _ := rv.alg.hashFunc()
hash, ok := rv.alg.hashFunc()
if !ok {
return ErrVerification
shizhMSFT marked this conversation as resolved.
Show resolved Hide resolved
}
if err := rsa.VerifyPSS(rv.key, hash, digest, signature, &rsa.PSSOptions{
SaltLength: rsa.PSSSaltLengthEqualsHash, // defined in RFC 8230 sec 2
}); err != nil {
Expand Down