Skip to content

Commit

Permalink
use XMALLOC/XFREE and update macro guards
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Sep 20, 2024
1 parent a3beae8 commit 388e329
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 8 additions & 1 deletion docs/SWTPM.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,20 @@ The rm switch is optional and remove the cache file NVChip. Alternately you can

```sh
git clone https://github.com/microsoft/ms-tpm-20-ref
cd ms-tpm-20-ref
cd ms-tpm-20-ref/TPMCmd
./bootstrap
./configure
make
./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

Build libtpms
Expand Down
10 changes: 6 additions & 4 deletions examples/pcr/quote.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
printf("wolfTPM2_CreateAndLoadAIK: AIK 0x%x (%d bytes)\n",
(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) {
word32 i;

Expand All @@ -160,7 +161,7 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
goto exit;
}

pubKey = (byte*)malloc(pubKeySz);
pubKey = (byte*)XMALLOC(pubKeySz, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
if (pubKey == NULL) {
printf("Failed to malloc buffer for public key\n");
goto exit;
Expand Down Expand Up @@ -266,7 +267,8 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])
cmdOut.quoteResult.signature.signature.rsassa.sig.size);
#endif

#ifdef HAVE_ECC
#if defined(HAVE_ECC) && !defined(WOLFTPM2_NO_HEAP) && \
defined(WOLFSSL_PUBLIC_MP)
if (alg == TPM_ALG_ECC &&
cmdOut.quoteResult.signature.signature.ecdsa.hash == TPM_ALG_SHA256) {
int res = 0;
Expand Down Expand Up @@ -331,7 +333,7 @@ int TPM2_PCR_Quote_Test(void* userCtx, int argc, char *argv[])

#ifdef HAVE_ECC
if (pubKey != NULL) {
free(pubKey);
XFREE(pubKey, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
}
#endif
return rc;
Expand Down

0 comments on commit 388e329

Please sign in to comment.