Skip to content

Commit eea8741

Browse files
committed
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.
1 parent 90846ba commit eea8741

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

examples/nvram/read.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,12 @@ int TPM2_NVRAM_Read_Example(void* userCtx, int argc, char *argv[])
267267
nvIndex);
268268

269269
if (!nvExtend && !partialRead) {
270-
/* get SRK */
271-
rc = getPrimaryStoragekey(&dev, &storage, TPM_ALG_RSA);
270+
/* Select the SRK algorithm based on the stored key's type so an
271+
* ECC child isn't loaded under an RSA parent (or vice versa). */
272+
TPMI_ALG_PUBLIC srkAlg =
273+
(keyBlob.pub.publicArea.type == TPM_ALG_ECC)
274+
? TPM_ALG_ECC : TPM_ALG_RSA;
275+
rc = getPrimaryStoragekey(&dev, &storage, srkAlg);
272276
if (rc != 0) goto exit;
273277

274278
printf("Trying to load the key extracted from NVRAM\n");

0 commit comments

Comments
 (0)