@@ -418,7 +418,7 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
418418{
419419 int rc ;
420420 int verifyRes = 0 ;
421- WOLFTPM2_KEY eccKey ;
421+ WOLFTPM2_KEYBLOB eccKey ;
422422 TPMT_PUBLIC publicTemplate ;
423423 byte sigRs [MAX_ECC_BYTES * 2 ];
424424 word32 sigRsSz = (word32 )sizeof (sigRs );
@@ -434,7 +434,7 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
434434
435435 XMEMSET (& tpmCtx , 0 , sizeof (tpmCtx ));
436436 tpmCtx .dev = dev ;
437- tpmCtx .eccKey = & eccKey ;
437+ tpmCtx .ecdsaKey = & eccKey ;
438438 tpmCtx .storageKey = storageKey ;
439439
440440 if (flags & FLAGS_USE_CRYPTO_CB ) {
@@ -451,8 +451,14 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
451451 TPMA_OBJECT_sign | TPMA_OBJECT_noDA ),
452452 curve , TPM_ALG_ECDSA , hashAlg );
453453 AssertIntEQ (rc , 0 );
454- rc = wolfTPM2_CreateAndLoadKey (dev , & eccKey , & storageKey -> handle ,
454+
455+ /* Use create key and load key directly instead to make
456+ * sure the private portion is populated */
457+ rc = wolfTPM2_CreateKey (dev , & eccKey , & storageKey -> handle ,
455458 & publicTemplate , (byte * )gKeyAuth , sizeof (gKeyAuth )- 1 );
459+ if (rc == TPM_RC_SUCCESS ) {
460+ rc = wolfTPM2_LoadKey (dev , & eccKey , & storageKey -> handle );
461+ }
456462 if ((rc & TPM_RC_HASH ) == TPM_RC_HASH ) {
457463 printf ("Hash type not supported... Skipping\n" );
458464 return ;
@@ -464,7 +470,7 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
464470 AssertIntEQ (rc , 0 );
465471
466472 /* Sign with TPM */
467- rc = wolfTPM2_SignHashScheme (dev , & eccKey , digest , digestSz ,
473+ rc = wolfTPM2_SignHashScheme (dev , ( WOLFTPM2_KEY * ) & eccKey , digest , digestSz ,
468474 sigRs , (int * )& sigRsSz , TPM_ALG_ECDSA , hashAlg );
469475 AssertIntEQ (rc , 0 );
470476
@@ -483,7 +489,7 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
483489 AssertIntEQ (rc , 0 );
484490
485491 /* Convert TPM key to wolfCrypt key for verification */
486- rc = wolfTPM2_EccKey_TpmToWolf (dev , & eccKey , & wolfKey );
492+ rc = wolfTPM2_EccKey_TpmToWolf (dev , ( WOLFTPM2_KEY * ) & eccKey , & wolfKey );
487493 AssertIntEQ (rc , 0 );
488494
489495 /* Verify TPM signature with wolfCrypt */
@@ -494,7 +500,9 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
494500 /* Cleanup first wolfCrypt key */
495501 wc_ecc_free (& wolfKey );
496502 wolfTPM2_UnloadHandle (dev , & eccKey .handle );
497-
503+ #ifdef WOLF_CRYPTO_CB
504+ tpmCtx .ecdsaKey = NULL ; /* create new one */
505+ #endif
498506
499507 /* -- Use wolfCrypt key to sign and verify with TPM -- */
500508 /* Initialize new wolfCrypt ECC key */
@@ -516,12 +524,11 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
516524 r = sigRs ;
517525 s = & sigRs [MAX_ECC_BYTES ];
518526 rLen = sLen = MAX_ECC_BYTES ;
519- rc = wc_ecc_sig_to_rs (sig ,
520- sigSz , r , & rLen , s , & sLen );
527+ rc = wc_ecc_sig_to_rs (sig , sigSz , r , & rLen , s , & sLen );
521528 AssertIntEQ (rc , 0 );
522529
523530 /* Convert wolfCrypt key to TPM key for verification */
524- rc = wolfTPM2_EccKey_WolfToTpm (dev , & wolfKey , & eccKey );
531+ rc = wolfTPM2_EccKey_WolfToTpm (dev , & wolfKey , ( WOLFTPM2_KEY * ) & eccKey );
525532 AssertIntEQ (rc , 0 );
526533
527534 /* combine R and S at key size (zero pad leading) */
@@ -531,8 +538,8 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
531538 XMEMSET (& sigRs [curveSize ], 0 , curveSize - sLen );
532539
533540 /* Verify wolfCrypt signature with TPM */
534- rc = wolfTPM2_VerifyHashScheme (dev , & eccKey , sigRs , curveSize * 2 ,
535- digest , digestSz , TPM_ALG_ECDSA , hashAlg );
541+ rc = wolfTPM2_VerifyHashScheme (dev , ( WOLFTPM2_KEY * ) & eccKey , sigRs ,
542+ curveSize * 2 , digest , digestSz , TPM_ALG_ECDSA , hashAlg );
536543 AssertIntEQ (rc , 0 );
537544
538545 /* Cleanup */
@@ -551,7 +558,8 @@ static void test_wolfTPM2_EccSignVerifyDig(WOLFTPM2_DEV* dev,
551558 }
552559}
553560
554- static void test_wolfTPM2_EccSignVerify_All (WOLFTPM2_DEV * dev , WOLFTPM2_KEY * storageKey , int flags )
561+ static void test_wolfTPM2_EccSignVerify_All (WOLFTPM2_DEV * dev ,
562+ WOLFTPM2_KEY * storageKey , int flags )
555563{
556564 int i ;
557565 byte digest [TPM_MAX_DIGEST_SIZE ];
0 commit comments