Skip to content

Commit 71be877

Browse files
authored
Merge pull request #762 from smallstep/capi/pss
Add support for rsa.PSSSaltLengthAuto on capi
2 parents 57b0893 + 11685e8 commit 71be877

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

kms/capi/capi.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,15 +965,21 @@ func (s *CAPISigner) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) ([
965965

966966
var saltLength int
967967
if rsaOpts, ok := opts.(*rsa.PSSOptions); ok {
968-
if rsaOpts.SaltLength == rsa.PSSSaltLengthEqualsHash {
969-
rsaOpts.SaltLength = rsaOpts.Hash.Size()
968+
switch rsaOpts.SaltLength {
969+
case rsa.PSSSaltLengthAuto:
970+
if k, ok := s.PublicKey.(*rsa.PublicKey); ok {
971+
saltLength = (k.N.BitLen()-1+7)/8 - 2 - rsaOpts.Hash.Size()
972+
} else {
973+
return nil, fmt.Errorf("unexpected RSA key type %T", s.PublicKey)
974+
}
975+
case rsa.PSSSaltLengthEqualsHash:
976+
saltLength = rsaOpts.Hash.Size()
977+
default:
978+
saltLength = rsaOpts.SaltLength
970979
}
971-
972-
saltLength = rsaOpts.SaltLength
973980
}
974981

975982
signatureBytes, err := nCryptSignHash(s.keyHandle, digest, hashAlg, saltLength)
976-
977983
if err != nil {
978984
return nil, fmt.Errorf("NCryptSignHash failed: %w", err)
979985
}

0 commit comments

Comments
 (0)