tpm2: Use EVP_PKEY_get1_RSA() rather than EVP_PKEY_get0_RSA (OSSL 3)

OpenSSL 3.0 has changed the signature of EVP_PKEY_get0_RSA() from

struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);

to

const struct rsa_st *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);

We now have to use EVP_PKEY_get1_RSA with this signature so that we can
access the RSA key. The signature of that function hasn't changed between
OpenSSL 1.1.0 and 3.0.0.

struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);

Free the additional reference held on the RSA key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2021-09-14 20:53:15 -04:00 committed by Stefan Berger
parent 9eb9677795
commit c8a7074bb6

View File

@ -492,7 +492,7 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN
BIGNUM *dQ = BN_new();
BIGNUM *qInv = BN_new();
#endif
RSA *key;
RSA *key = NULL;
BN_CTX *ctx = NULL;
TPM_RC retVal = InitOpenSSLRSAPublicKey(rsaKey, pkey);
@ -507,7 +507,7 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN
if (P == NULL)
ERROR_RETURN(TPM_RC_FAILURE)
key = EVP_PKEY_get0_RSA(*pkey);
key = EVP_PKEY_get1_RSA(*pkey);
if (key == NULL)
ERROR_RETURN(TPM_RC_FAILURE);
RSA_get0_key(key, &N, &E, NULL);
@ -554,6 +554,7 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN
BN_clear_free(P);
BN_clear_free(Q);
BN_free(Qr);
RSA_free(key); // undo reference from EVP_PKEY_get1_RSA()
if (retVal != TPM_RC_SUCCESS) {
BN_clear_free(D);