diff --git a/src/tpm2/TpmEcc_Signature_ECDSA.c b/src/tpm2/TpmEcc_Signature_ECDSA.c index 69cb7010..b8aaed5b 100644 --- a/src/tpm2/TpmEcc_Signature_ECDSA.c +++ b/src/tpm2/TpmEcc_Signature_ECDSA.c @@ -194,6 +194,9 @@ TpmEcc_SignEcdsa(Crypt_Int* bnR, // OUT: 'r' component of the signa const BIGNUM* s; BIGNUM* d = BN_new(); + if (!d) + return TPM_RC_MEMORY; + d = BigInitialized(d, (bigConst)bnD); eckey = EC_KEY_new(); @@ -310,6 +313,9 @@ TpmEcc_ValidateSignatureEcdsa( BIGNUM* s = BN_new(); EC_POINT* q = EcPointInitialized((bn_point_t*)ecQ, E); + if (!r || !s) + ERROR_EXIT(TPM_RC_MEMORY); + if (digest->b.size == CryptHashGetDigestSize(TPM_ALG_SHA1) && RuntimeProfileRequiresAttributeFlags(&g_RuntimeProfile, RUNTIME_ATTRIBUTE_NO_SHA1_VERIFICATION)) diff --git a/src/tpm2/crypto/openssl/CryptSym.c b/src/tpm2/crypto/openssl/CryptSym.c index 1ffae0cf..a0540258 100644 --- a/src/tpm2/crypto/openssl/CryptSym.c +++ b/src/tpm2/crypto/openssl/CryptSym.c @@ -591,7 +591,7 @@ CryptSymmetricEncrypt( buffersize = TPM2_ROUNDUP(dSize, blockSize); buffer = malloc(buffersize); if (buffer == NULL) - ERROR_EXIT(TPM_RC_FAILURE); + ERROR_EXIT(TPM_RC_MEMORY); pOut = buffer; } @@ -714,7 +714,7 @@ CryptSymmetricDecrypt( buffersize = TPM2_ROUNDUP(dSize + blockSize, blockSize); buffer = malloc(buffersize); if (buffer == NULL) - ERROR_EXIT(TPM_RC_FAILURE); + ERROR_EXIT(TPM_RC_MEMORY); #if ALG_TDES && ALG_CTR if (algorithm == TPM_ALG_TDES && mode == TPM_ALG_CTR) { diff --git a/src/tpm2/crypto/openssl/Helpers.c b/src/tpm2/crypto/openssl/Helpers.c index 308b70db..a22747ff 100644 --- a/src/tpm2/crypto/openssl/Helpers.c +++ b/src/tpm2/crypto/openssl/Helpers.c @@ -866,6 +866,9 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN BN_CTX *ctx = NULL; TPM_RC retVal; + if (!dP || !dQ || !qInv) + ERROR_EXIT(TPM_RC_MEMORY); + if (ObjectGetPublicParameters(rsaKey, &N, &E) != 1) ERROR_EXIT(TPM_RC_FAILURE); @@ -884,7 +887,7 @@ InitOpenSSLRSAPrivateKey(OBJECT *rsaKey, // IN Q = BN_new(); Qr = BN_new(); if (ctx == NULL || Q == NULL || Qr == NULL) - ERROR_EXIT(TPM_RC_FAILURE); + ERROR_EXIT(TPM_RC_MEMORY); /* Q = N/P; no remainder */ BN_set_flags(P, BN_FLG_CONSTTIME); // P is secret if (!BN_div(Q, Qr, N, P, ctx) || !BN_is_zero(Qr)) @@ -952,7 +955,9 @@ OpenSSLCryptRsaGenerateKey( EVP_PKEY *pkey = NULL; CRYPT_RSA_VAR(tmp); - if (bnE == NULL || BN_set_word(bnE, e) != 1) + if (bnE == NULL) + return TPM_RC_MEMORY; + if (BN_set_word(bnE, e) != 1) ERROR_EXIT(TPM_RC_FAILURE); if ((ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL)) == NULL || @@ -1016,7 +1021,9 @@ OpenSSLCryptRsaGenerateKey( BIGNUM *bnE = BN_new(); CRYPT_RSA_VAR(tmp); - if (bnE == NULL || BN_set_word(bnE, e) != 1) + if (bnE == NULL) + return TPM_RC_MEMORY; + if (BN_set_word(bnE, e) != 1) ERROR_EXIT(TPM_RC_FAILURE); rsa = RSA_new();