Skip to content

Commit 34108a8

Browse files
committed
examples/keygen: pick SRK algorithm from stored key type
keyload defaulted srkAlg = TPM_ALG_ECC and only switched to RSA for TPM_ALG_RSA keys. A sealed KEYEDHASH blob (produced by examples/seal, which always uses the RSA SRK) therefore tried to load under the ECC SRK and failed with TPM_RC_INTEGRITY. SYMCIPHER blobs had the same issue. Invert the default to RSA (matching seal.c) and only switch to the ECC SRK when the stored key itself is ECC.
1 parent eea8741 commit 34108a8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

examples/keygen/keyload.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
6767
WOLFTPM2_KEYBLOB newKey;
6868
WOLFTPM2_KEY persistKey;
6969
TPM_ALG_ID alg;
70-
TPMI_ALG_PUBLIC srkAlg = TPM_ALG_ECC; /* prefer ECC, but allow RSA */
70+
TPMI_ALG_PUBLIC srkAlg = TPM_ALG_RSA; /* default matches seal.c */
7171
TPM_ALG_ID paramEncAlg = TPM_ALG_NULL;
7272
WOLFTPM2_SESSION tpmSession;
7373
const char* inputFile = "keyblob.bin";
@@ -133,8 +133,11 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
133133
#endif
134134

135135
alg = newKey.pub.publicArea.type;
136-
if (alg == TPM_ALG_RSA)
137-
srkAlg = TPM_ALG_RSA;
136+
/* Only switch to the ECC SRK when the stored key itself is ECC; other
137+
* child types (RSA, KEYEDHASH from seal, SYMCIPHER) stay on the RSA SRK
138+
* so the parent algorithm matches how those keys were created. */
139+
if (alg == TPM_ALG_ECC)
140+
srkAlg = TPM_ALG_ECC;
138141
printf("Loading %s key\n", TPM2_GetAlgName(alg));
139142

140143
if (endorseKey) {

0 commit comments

Comments
 (0)