Skip to content

Commit b3646e2

Browse files
committed
tpm2: Helpers: Have ObjectGetPublicParameters return TPM_RC
Convert ObjectGetPublicParameters to return TPM_RC and have it return TPM_RC_MEMORY in case of a NULL pointer returned from BN_new() and TPM_RC_FAILURE for any other error. Adjust the 2 callers. Signed-off-by: Stefan Berger <[email protected]>
1 parent 5cc5d3e commit b3646e2

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/tpm2/crypto/openssl/Helpers.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -717,38 +717,39 @@ BuildRSAKey(EVP_PKEY **ppkey, // OUT
717717

718718
#endif /* ! OPENSSL_VERSION_NUMBER >= 0x30000000L */
719719

720-
static int
720+
static TPM_RC
721721
ObjectGetPublicParameters(OBJECT *key, // IN
722722
BIGNUM **N, // OUT
723723
BIGNUM **E // OUT
724724
)
725725
{
726+
TPM_RC retVal;
726727
BN_ULONG eval;
727728

728729
*E = BN_new();
729730
if (*E == NULL)
730-
return 0;
731+
return TPM_RC_MEMORY;
731732

732733
if(key->publicArea.parameters.rsaDetail.exponent != 0)
733734
eval = key->publicArea.parameters.rsaDetail.exponent;
734735
else
735736
eval = RSA_DEFAULT_PUBLIC_EXPONENT;
736737

737738
if (BN_set_word(*E, eval) != 1)
738-
goto error;
739+
ERROR_EXIT(TPM_RC_FAILURE);
739740

740741
*N = BN_bin2bn(key->publicArea.unique.rsa.b.buffer,
741742
key->publicArea.unique.rsa.b.size, NULL);
742743
if (*N == NULL)
743-
goto error;
744+
ERROR_EXIT(TPM_RC_FAILURE);
744745

745-
return 1;
746+
return TPM_RC_SUCCESS;
746747

747-
error:
748+
Exit:
748749
BN_free(*E);
749750
*E = NULL;
750751

751-
return 0;
752+
return retVal;
752753
}
753754

754755
LIB_EXPORT TPM_RC
@@ -760,11 +761,12 @@ InitOpenSSLRSAPublicKey(OBJECT *key, // IN
760761
BIGNUM *N = NULL;
761762
BIGNUM *E = NULL;
762763

763-
if (ObjectGetPublicParameters(key, &N, &E) != 1 ||
764-
BuildRSAKey(pkey, N, E, NULL, NULL, NULL, NULL, NULL, NULL) != 1)
765-
ERROR_EXIT(TPM_RC_FAILURE);
764+
retVal = ObjectGetPublicParameters(key, &N, &E);
765+
if (retVal)
766+
return retVal;
766767

767-
retVal = TPM_RC_SUCCESS;
768+
if (BuildRSAKey(pkey, N, E, NULL, NULL, NULL, NULL, NULL, NULL) != 1)
769+
ERROR_EXIT(TPM_RC_FAILURE);
768770

769771
Exit:
770772
BN_free(N);
@@ -869,8 +871,9 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN
869871
if (!dP || !dQ || !qInv)
870872
ERROR_EXIT(TPM_RC_MEMORY);
871873

872-
if (ObjectGetPublicParameters(rsaKey, &N, &E) != 1)
873-
ERROR_EXIT(TPM_RC_FAILURE);
874+
retVal = ObjectGetPublicParameters(rsaKey, &N, &E);
875+
if (retVal)
876+
goto Exit;
874877

875878
if(!rsaKey->attributes.privateExp)
876879
CryptRsaLoadPrivateExponent(&rsaKey->publicArea, &rsaKey->sensitive,

0 commit comments

Comments
 (0)