This fails for parameterized RSASSA-PSS keys, where the public key
encodes any restrictions, e.g. for the digest algorithm, or salt length.
Setting RSA_PSS_SALTLEN_AUTO explicitly is unnecessary for verification
as the length will be auto-detected by default [1]:
> EVP_PKEY_CTX_set_rsa_pss_saltlen() sets the RSA PSS salt length to
> saltlen. As its name implies it is only supported for PSS padding.
> If this function is not called then the salt length is maximized up
> to the digest length when signing and auto detection when verifying.
But setting this value also causes the verification to fail for
parameterized keys as the OpenSSL docs note [2]:
> The EVP_PKEY_CTX_set_rsa_pss_saltlen() macro is used to set the salt
> length. If the key has usage restrictions then an error is returned
> if an attempt is made to set the salt length below the minimum value.
> It is otherwise similar to the RSA operation except detection of the
> salt length (using RSA_PSS_SALTLEN_AUTO) is not supported for
> verification if the key has usage restrictions.
So remove that call and let OpenSSL do the right thing automatically.
[1] https://docs.openssl.org/3.5/man3/EVP_PKEY_CTX_ctrl/#rsa-parameters
[2] https://docs.openssl.org/3.5/man3/EVP_PKEY_CTX_set_rsa_pss_keygen_md
Link: https://groups.google.com/g/swupdate/c/FMRY6rtuKW8
Signed-off-by: Oliver Kästner <okae...@rosen-nxt.com>
---
crypto/swupdate_rsa_verify_openssl.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/crypto/swupdate_rsa_verify_openssl.c b/crypto/swupdate_rsa_verify_openssl.c
index fac102ce..195a0f44 100644
--- a/crypto/swupdate_rsa_verify_openssl.c
+++ b/crypto/swupdate_rsa_verify_openssl.c
@@ -71,11 +71,6 @@ static int dgst_verify_init(struct openssl_digest *dgst)
ERROR("EVP_PKEY_CTX_set_rsa_padding failed, error 0x%lx", ERR_get_error());
return -EFAULT; /* failed */
}
- rc = EVP_PKEY_CTX_set_rsa_pss_saltlen(dgst->ckey, -2);
- if (rc <= 0) {
- ERROR("EVP_PKEY_CTX_set_rsa_pss_saltlen failed, error 0x%lx", ERR_get_error());
- return -EFAULT; /* failed */
- }
}
return 0;
--
2.43.0