@@ -65,13 +65,15 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
6565 WOLFTPM2_KEY storage ; /* SRK */
6666 WOLFTPM2_KEY * primary = NULL ;
6767 WOLFTPM2_KEYBLOB newKey ;
68+ #ifndef WOLFTPM_NO_NV
6869 WOLFTPM2_KEY persistKey ;
70+ int persistent = 0 ;
71+ #endif
6972 TPM_ALG_ID alg ;
7073 TPMI_ALG_PUBLIC srkAlg = TPM_ALG_ECC ; /* prefer ECC, but allow RSA */
7174 TPM_ALG_ID paramEncAlg = TPM_ALG_NULL ;
7275 WOLFTPM2_SESSION tpmSession ;
7376 const char * inputFile = "keyblob.bin" ;
74- int persistent = 0 ;
7577 int endorseKey = 0 ;
7678
7779
@@ -97,9 +99,11 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
9799 else if (XSTRCMP (argv [argc - 1 ], "-xor" ) == 0 ) {
98100 paramEncAlg = TPM_ALG_XOR ;
99101 }
102+ #ifndef WOLFTPM_NO_NV
100103 else if (XSTRCMP (argv [argc - 1 ], "- persistent ") == 0) {
101104 persistent = 1 ;
102105 }
106+ #endif
103107 else {
104108 printf ("Warning: Unrecognized option: %s\n" , argv [argc - 1 ]);
105109 }
@@ -109,7 +113,9 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
109113 XMEMSET (& endorse , 0 , sizeof (endorse ));
110114 XMEMSET (& storage , 0 , sizeof (storage ));
111115 XMEMSET (& newKey , 0 , sizeof (newKey ));
116+ #ifndef WOLFTPM_NO_NV
112117 XMEMSET (& persistKey , 0 , sizeof (persistKey ));
118+ #endif
113119 XMEMSET (& tpmSession , 0 , sizeof (tpmSession ));
114120
115121 printf ("TPM2.0 Key load example\n" );
@@ -151,6 +157,7 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
151157 primary = & storage ;
152158 }
153159
160+ #ifndef WOLFTPM_NO_PCR_POLICY
154161 if (endorseKey ) {
155162 /* Fresh policy session for EK auth */
156163 rc = wolfTPM2_CreateAuthSession_EkPolicy (& dev , & tpmSession );
@@ -159,7 +166,9 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
159166 rc = wolfTPM2_SetAuthSession (& dev , 0 , & tpmSession , 0 );
160167 if (rc != 0 ) goto exit ;
161168 }
162- else if (paramEncAlg != TPM_ALG_NULL ) {
169+ else
170+ #endif
171+ if (paramEncAlg != TPM_ALG_NULL ) {
163172 WOLFTPM2_KEY * bindKey = & storage ;
164173 #ifndef HAVE_ECC
165174 if (srkAlg == TPM_ALG_ECC )
@@ -198,6 +207,7 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
198207 printf ("Loaded key to 0x%x\n" ,
199208 (word32 )newKey .handle .hndl );
200209
210+ #ifndef WOLFTPM_NO_NV
201211 /* Make the TPM key persistent, so it remains loaded after example exit */
202212 if (persistent ) {
203213 /* Prepare key in the format expected by the wolfTPM wrapper */
@@ -213,6 +223,7 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
213223 }
214224 printf ("Key was made persistent at 0x%X\n" , persistKey .handle .hndl );
215225 }
226+ #endif
216227
217228exit :
218229
@@ -222,8 +233,11 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
222233
223234 /* Close key handles */
224235 wolfTPM2_UnloadHandle (& dev , & primary -> handle );
236+ #ifndef WOLFTPM_NO_NV
225237 /* newKey.handle is already flushed by wolfTPM2_NVStoreKey */
226- if (!persistent ) {
238+ if (!persistent )
239+ #endif
240+ {
227241 wolfTPM2_UnloadHandle (& dev , & newKey .handle );
228242 }
229243 /* EK policy is destroyed after use, flush parameter encryption session */
0 commit comments