Skip to content

Commit 541a85c

Browse files
committed
Improve crypto callback key gen hash algorithm selection.
1 parent 679020d commit 541a85c

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

examples/wrap/wrap_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
124124
TPM_ALG_ID paramEncAlg = TPM_ALG_NULL;
125125
WOLFTPM2_SESSION tpmSession;
126126

127+
XMEMSET(&rsaKey, 0, sizeof(rsaKey));
128+
XMEMSET(&eccKey, 0, sizeof(eccKey));
127129
XMEMSET(&aesKey, 0, sizeof(aesKey));
128130
XMEMSET(&publicKey, 0, sizeof(publicKey));
129131
#ifndef WOLFTPM2_NO_WOLFCRYPT
@@ -172,11 +174,9 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
172174
/* Setup the wolf crypto device callback */
173175
XMEMSET(&tpmCtx, 0, sizeof(tpmCtx));
174176
#ifndef NO_RSA
175-
XMEMSET(&rsaKey, 0, sizeof(rsaKey));
176177
tpmCtx.rsaKey = &rsaKey;
177178
#endif
178179
#ifdef HAVE_ECC
179-
XMEMSET(&eccKey, 0, sizeof(eccKey));
180180
tpmCtx.eccKey = &eccKey;
181181
#endif
182182
tpmCtx.storageKey = &storageKey;

src/tpm2_cryptocb.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,24 @@ int wolfTPM2_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx)
220220
key->handle.hndl == TPM_RH_NULL
221221
) {
222222
TPMT_PUBLIC publicTemplate;
223-
XMEMSET(&publicTemplate, 0, sizeof(publicTemplate));
223+
TPMI_ALG_HASH hashAlg;
224+
225+
if (curve_id == TPM_ECC_NIST_P521)
226+
hashAlg = TPM_ALG_SHA512;
227+
else if (curve_id == TPM_ECC_NIST_P384)
228+
hashAlg = TPM_ALG_SHA384;
229+
else
230+
hashAlg = TPM_ALG_SHA256;
224231

225-
rc = wolfTPM2_GetKeyTemplate_ECC(&publicTemplate,
232+
XMEMSET(&publicTemplate, 0, sizeof(publicTemplate));
233+
rc = wolfTPM2_GetKeyTemplate_ECC_ex(&publicTemplate, hashAlg,
226234
TPMA_OBJECT_sensitiveDataOrigin | TPMA_OBJECT_userWithAuth |
227235
TPMA_OBJECT_sign | TPMA_OBJECT_noDA,
228-
curve_id, TPM_ALG_ECDSA);
236+
curve_id, TPM_ALG_ECDSA, hashAlg);
229237
if (rc == 0) {
230-
if (curve_id == TPM_ECC_NIST_P521)
231-
publicTemplate.nameAlg = TPM_ALG_SHA512;
232-
else if (curve_id == TPM_ECC_NIST_P384)
233-
publicTemplate.nameAlg = TPM_ALG_SHA384;
234-
else
235-
publicTemplate.nameAlg = TPM_ALG_SHA256;
236-
237238
if (tlsCtx->ecdsaKey != NULL) {
238239
/* Use create key and load key directly instead to make
239-
* sure the private portion is populated */
240+
* sure the private portion is populated */
240241
rc = wolfTPM2_CreateKey(tlsCtx->dev, tlsCtx->ecdsaKey,
241242
&tlsCtx->storageKey->handle, &publicTemplate,
242243
(byte*)key->handle.auth.buffer,

0 commit comments

Comments
 (0)