@@ -79,6 +79,8 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
7979 TPM2B_ECC_POINT pubPoint ;
8080#ifndef WOLFTPM_WINAPI
8181 word32 nvAttributes = 0 ;
82+ WOLFTPM2_HANDLE parent ;
83+ WOLFTPM2_NV nv ;
8284#endif
8385#ifdef WOLFTPM_CRYPTOCB
8486 TpmCryptoDevCtx tpmCtx ;
@@ -753,47 +755,42 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
753755 /*------------------------------------------------------------------------*/
754756 /* NV with Auth (preferred API's) */
755757#ifndef WOLFTPM_WINAPI
756- {
757- WOLFTPM2_HANDLE parent ;
758- WOLFTPM2_NV nv ;
758+ XMEMSET (& parent , 0 , sizeof (parent ));
759+ parent .hndl = TPM_RH_OWNER ;
759760
760- XMEMSET (& parent , 0 , sizeof (parent ));
761- parent .hndl = TPM_RH_OWNER ;
762-
763- rc = wolfTPM2_GetNvAttributesTemplate (parent .hndl , & nvAttributes );
764- if (rc != 0 ) goto exit ;
765- rc = wolfTPM2_NVCreateAuth (& dev , & parent , & nv , TPM2_DEMO_NV_TEST_AUTH_INDEX ,
766- nvAttributes , TPM2_DEMO_NV_TEST_SIZE , (byte * )gNvAuth , sizeof (gNvAuth )- 1 );
767- if (rc != 0 && rc != TPM_RC_NV_DEFINED ) goto exit ;
768-
769- wolfTPM2_SetAuthHandle (& dev , 0 , & nv .handle );
761+ rc = wolfTPM2_GetNvAttributesTemplate (parent .hndl , & nvAttributes );
762+ if (rc != 0 ) goto exit ;
763+ rc = wolfTPM2_NVCreateAuth (& dev , & parent , & nv , TPM2_DEMO_NV_TEST_AUTH_INDEX ,
764+ nvAttributes , TPM2_DEMO_NV_TEST_SIZE , (byte * )gNvAuth , sizeof (gNvAuth )- 1 );
765+ if (rc != 0 && rc != TPM_RC_NV_DEFINED ) goto exit ;
770766
771- message .size = TPM2_DEMO_NV_TEST_SIZE ; /* test message 0x11,0x11,etc */
772- XMEMSET (message .buffer , 0x11 , message .size );
773- rc = wolfTPM2_NVWriteAuth (& dev , & nv , TPM2_DEMO_NV_TEST_AUTH_INDEX ,
774- message .buffer , message .size , 0 );
775- if (rc != 0 ) goto exit ;
767+ wolfTPM2_SetAuthHandle (& dev , 0 , & nv .handle );
776768
777- plain .size = TPM2_DEMO_NV_TEST_SIZE ;
778- rc = wolfTPM2_NVReadAuth (& dev , & nv , TPM2_DEMO_NV_TEST_AUTH_INDEX ,
779- plain .buffer , (word32 * )& plain .size , 0 );
780- if (rc != 0 ) goto exit ;
769+ message .size = TPM2_DEMO_NV_TEST_SIZE ; /* test message 0x11,0x11,etc */
770+ XMEMSET (message .buffer , 0x11 , message .size );
771+ rc = wolfTPM2_NVWriteAuth (& dev , & nv , TPM2_DEMO_NV_TEST_AUTH_INDEX ,
772+ message .buffer , message .size , 0 );
773+ if (rc != 0 ) goto exit ;
781774
782- rc = wolfTPM2_NVReadPublic (& dev , TPM2_DEMO_NV_TEST_AUTH_INDEX , NULL );
783- if (rc != 0 ) goto exit ;
775+ plain .size = TPM2_DEMO_NV_TEST_SIZE ;
776+ rc = wolfTPM2_NVReadAuth (& dev , & nv , TPM2_DEMO_NV_TEST_AUTH_INDEX ,
777+ plain .buffer , (word32 * )& plain .size , 0 );
778+ if (rc != 0 ) goto exit ;
784779
785- rc = wolfTPM2_NVDeleteAuth (& dev , & parent , TPM2_DEMO_NV_TEST_AUTH_INDEX );
786- if (rc != 0 ) goto exit ;
780+ rc = wolfTPM2_NVReadPublic (& dev , TPM2_DEMO_NV_TEST_AUTH_INDEX , NULL );
781+ if (rc != 0 ) goto exit ;
787782
788- if (message .size != plain .size ||
789- XMEMCMP (message .buffer , plain .buffer , message .size ) != 0 ) {
790- rc = TPM_RC_TESTING ; goto exit ;
791- }
783+ rc = wolfTPM2_NVDeleteAuth (& dev , & parent , TPM2_DEMO_NV_TEST_AUTH_INDEX );
784+ if (rc != 0 ) goto exit ;
792785
793- printf ("NV Test (with auth) on index 0x%x with %d bytes passed\n" ,
794- TPM2_DEMO_NV_TEST_AUTH_INDEX , TPM2_DEMO_NV_TEST_SIZE );
786+ if (message .size != plain .size ||
787+ XMEMCMP (message .buffer , plain .buffer , message .size ) != 0 ) {
788+ rc = TPM_RC_TESTING ; goto exit ;
795789 }
796790
791+ printf ("NV Test (with auth) on index 0x%x with %d bytes passed\n" ,
792+ TPM2_DEMO_NV_TEST_AUTH_INDEX , TPM2_DEMO_NV_TEST_SIZE );
793+
797794 /* NV Tests (older API's without auth) */
798795 rc = wolfTPM2_GetNvAttributesTemplate (TPM_RH_OWNER , & nvAttributes );
799796 if (rc != 0 ) goto exit ;
0 commit comments