From 5bfdd8eba42d1203c1ec1037740ff18d4d04e769 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Mon, 25 May 2020 12:05:41 -0400 Subject: [PATCH] tpm2: Set the PSS salt length to the digest length Call EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, -1) when creating an RSA signature to set the PSS salt length to the digest length. Without this call we previously set the salt length to the maximum permissible value, but this is not how TPM 2 implements it. Per interoperability testing between signatures created previously with the max. permissible value and the new code, which does not modify the signature verification code, old signatures still verify. New signatures also verify. This patch may solve interoperability with hardware TPMs that signatures created following this patch now verify on hardware TPMs as well. Signed-off-by: Stefan Berger --- src/tpm2/crypto/openssl/CryptRsa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tpm2/crypto/openssl/CryptRsa.c b/src/tpm2/crypto/openssl/CryptRsa.c index 17e41ffc..ac244f71 100644 --- a/src/tpm2/crypto/openssl/CryptRsa.c +++ b/src/tpm2/crypto/openssl/CryptRsa.c @@ -1459,6 +1459,10 @@ CryptRsaSign( EVP_PKEY_CTX_set_signature_md(ctx, md) <= 0) ERROR_RETURN(TPM_RC_FAILURE); + if (padding == RSA_PKCS1_PSS_PADDING && + EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, -1) <= 0) + ERROR_RETURN(TPM_RC_FAILURE); + outlen = sigOut->signature.rsapss.sig.t.size; if (EVP_PKEY_sign(ctx, sigOut->signature.rsapss.sig.t.buffer, &outlen,