examples/nvram: pick SRK algorithm from stored key type

nvram/read hardcoded the RSA SRK, so an ECC child key retrieved
  from NV would be loaded under the RSA parent and fail with
  TPM_RC_INTEGRITY. Switch the SRK selection to mirror the approach
  already used in keygen/keyload: inspect keyBlob.pub.publicArea.type
  and load the matching RSA or ECC SRK.
pull/494/head
Aidan Garske 2026-04-24 22:28:25 +01:00
parent 90846ba49f
commit eea8741248
1 changed files with 6 additions and 2 deletions

View File

@ -267,8 +267,12 @@ int TPM2_NVRAM_Read_Example(void* userCtx, int argc, char *argv[])
nvIndex);
if (!nvExtend && !partialRead) {
/* get SRK */
rc = getPrimaryStoragekey(&dev, &storage, TPM_ALG_RSA);
/* Select the SRK algorithm based on the stored key's type so an
* ECC child isn't loaded under an RSA parent (or vice versa). */
TPMI_ALG_PUBLIC srkAlg =
(keyBlob.pub.publicArea.type == TPM_ALG_ECC)
? TPM_ALG_ECC : TPM_ALG_RSA;
rc = getPrimaryStoragekey(&dev, &storage, srkAlg);
if (rc != 0) goto exit;
printf("Trying to load the key extracted from NVRAM\n");