use XMALLOC/XFREE and update macro guards

pull/379/head
JacobBarthelmeh 2024-09-20 10:02:45 -07:00
parent a3beae82ee
commit 388e32912e
2 changed files with 14 additions and 5 deletions

View File

@ -72,13 +72,20 @@ The rm switch is optional and remove the cache file NVChip. Alternately you can
```sh ```sh
git clone https://github.com/microsoft/ms-tpm-20-ref git clone https://github.com/microsoft/ms-tpm-20-ref
cd ms-tpm-20-ref cd ms-tpm-20-ref/TPMCmd
./bootstrap ./bootstrap
./configure ./configure
make make
./Simulator/src/tpm2-simulator ./Simulator/src/tpm2-simulator
``` ```
In another terminal power on ms-tpm-20-ref and start NV
```sh
echo -ne "\x00\x00\x00\x01" | nc 127.0.0.1 2322 | exit
echo -ne "\x00\x00\x00\x0B" | nc 127.0.0.1 2322 | exit
```
### swtpm ### swtpm
Build libtpms Build libtpms

View File

@ -148,7 +148,8 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
printf("wolfTPM2_CreateAndLoadAIK: AIK 0x%x (%d bytes)\n", printf("wolfTPM2_CreateAndLoadAIK: AIK 0x%x (%d bytes)\n",
(word32)aik.handle.hndl, aik.pub.size); (word32)aik.handle.hndl, aik.pub.size);
#ifdef HAVE_ECC #if defined(HAVE_ECC) && !defined(WOLFTPM2_NO_HEAP) && \
defined(WOLFSSL_PUBLIC_MP)
if (alg == TPM_ALG_ECC) { if (alg == TPM_ALG_ECC) {
word32 i; word32 i;
@ -160,7 +161,7 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
goto exit; goto exit;
} }
pubKey = (byte*)malloc(pubKeySz); pubKey = (byte*)XMALLOC(pubKeySz, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
if (pubKey == NULL) { if (pubKey == NULL) {
printf("Failed to malloc buffer for public key\n"); printf("Failed to malloc buffer for public key\n");
goto exit; goto exit;
@ -266,7 +267,8 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
cmdOut.quoteResult.signature.signature.rsassa.sig.size); cmdOut.quoteResult.signature.signature.rsassa.sig.size);
#endif #endif
#ifdef HAVE_ECC #if defined(HAVE_ECC) && !defined(WOLFTPM2_NO_HEAP) && \
defined(WOLFSSL_PUBLIC_MP)
if (alg == TPM_ALG_ECC && if (alg == TPM_ALG_ECC &&
cmdOut.quoteResult.signature.signature.ecdsa.hash == TPM_ALG_SHA256) { cmdOut.quoteResult.signature.signature.ecdsa.hash == TPM_ALG_SHA256) {
int res = 0; int res = 0;
@ -331,7 +333,7 @@ exit:
#ifdef HAVE_ECC #ifdef HAVE_ECC
if (pubKey != NULL) { if (pubKey != NULL) {
free(pubKey); XFREE(pubKey, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
} }
#endif #endif
return rc; return rc;