Skip to content

Commit 52cdcdc

Browse files
committed
examples/keygen: align keygen SRK default with keyload/seal
keygen defaulted srkAlg = TPM_ALG_ECC and only switched to RSA for RSA keys, so SYMCIPHER and KEYEDHASH blobs were created under the ECC SRK. After the prior keyload fix made keyload default to RSA (matching seal.c), a sym/keyedhash blob produced by keygen could not round-trip through keyload without a parent mismatch. Invert the default to RSA (matching seal.c and keyload.c) and only switch to the ECC SRK when the stored key itself is ECC. Keeps all three tools aligned so any blob round-trips without callers having to specify a parent.
1 parent 34108a8 commit 52cdcdc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

examples/keygen/keygen.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
132132
WOLFTPM2_KEYBLOB primaryBlob; /* Primary key as WOLFTPM2_KEYBLOB */
133133
TPMT_PUBLIC publicTemplate;
134134
TPMI_ALG_PUBLIC alg = TPM_ALG_RSA; /* default, see usage() for options */
135-
TPMI_ALG_PUBLIC srkAlg = TPM_ALG_ECC; /* prefer ECC, but allow RSA */
135+
TPMI_ALG_PUBLIC srkAlg = TPM_ALG_RSA; /* default matches seal.c / keyload.c */
136136
TPM_ALG_ID algSym = TPM_ALG_CTR; /* default Symmetric Cipher, see usage */
137137
TPM_ALG_ID paramEncAlg = TPM_ALG_NULL;
138138
WOLFTPM2_SESSION tpmSession;
@@ -222,8 +222,10 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
222222
XMEMSET(&tpmSession, 0, sizeof(tpmSession));
223223
XMEMSET(&auth, 0, sizeof(auth));
224224

225-
if (alg == TPM_ALG_RSA)
226-
srkAlg = TPM_ALG_RSA;
225+
/* Only use the ECC SRK for ECC child keys; RSA, SYMCIPHER, KEYEDHASH
226+
* all stay on the RSA SRK so that keyload/seal can round-trip them. */
227+
if (alg == TPM_ALG_ECC)
228+
srkAlg = TPM_ALG_ECC;
227229
if (alg == TPM_ALG_SYMCIPHER) {
228230
rc = symChoice(symMode, &algSym, &keyBits);
229231
if (rc != TPM_RC_SUCCESS) {

0 commit comments

Comments
 (0)