Skip to content

Commit

Permalink
Allow rsa.PSSSaltLengthEqualsHash as option
Browse files Browse the repository at this point in the history
This commit adds support to the salt length set to
rsa.PSSSaltLengthEqualsHash when signing with an RSA key. This is
currently supported, but the user must sspecify the length to the digest
size.

Adding rsa.PSSSaltLengthEqualsHash allows using a key generated by the
TPM for TLS client authentication, Go will set this option by default
if an RSA key is used.

Signed-off-by: Mariano Cano <[email protected]>
  • Loading branch information
maraino committed Jan 11, 2024
1 parent 02cf9e2 commit dca66cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions attest/application_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@ func testKeySign(t *testing.T, tpm *TPM) {
},
digest: []byte("1234567890123456789012345678901212345678901234567890123456789012"),
},
{
name: "RSA2048-PSS-SHA256, PSSSaltLengthEqualsHash",
keyOpts: &KeyConfig{
Algorithm: RSA,
Size: 2048,
},
signOpts: &rsa.PSSOptions{
SaltLength: rsa.PSSSaltLengthEqualsHash,
Hash: crypto.SHA256,
},
digest: []byte("12345678901234567890123456789012"),
},
{
name: "RSA2048-PSS-SHA256, explicit salt len",
keyOpts: &KeyConfig{
Expand Down
4 changes: 2 additions & 2 deletions attest/wrapped_tpm20.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ func signRSA(rw io.ReadWriter, key tpmutil.Handle, digest []byte, opts crypto.Si
}

if pss, ok := opts.(*rsa.PSSOptions); ok {
if pss.SaltLength != rsa.PSSSaltLengthAuto && pss.SaltLength != len(digest) {
return nil, fmt.Errorf("PSS salt length %d is incorrect, expected rsa.PSSSaltLengthAuto or %d", pss.SaltLength, len(digest))
if pss.SaltLength != rsa.PSSSaltLengthAuto && pss.SaltLength != rsa.PSSSaltLengthEqualsHash && pss.SaltLength != len(digest) {
return nil, fmt.Errorf("PSS salt length %d is incorrect, expected rsa.PSSSaltLengthAuto, rsa.PSSSaltLengthEqualsHash or %d", pss.SaltLength, len(digest))
}
scheme.Alg = tpm2.AlgRSAPSS
}
Expand Down

0 comments on commit dca66cd

Please sign in to comment.