@@ -4258,9 +4258,10 @@ int wolfTPM2_UnloadHandle(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* handle)
42584258
42594259/* nv is the populated handle and auth */
42604260/* auth and authSz are optional NV authentication */
4261- int wolfTPM2_NVCreateAuth (WOLFTPM2_DEV * dev , WOLFTPM2_HANDLE * parent ,
4261+ /* authPolicy and authPolicySz are optional policy digest */
4262+ int wolfTPM2_NVCreateAuthPolicy (WOLFTPM2_DEV * dev , WOLFTPM2_HANDLE * parent ,
42624263 WOLFTPM2_NV * nv , word32 nvIndex , word32 nvAttributes , word32 maxSize ,
4263- const byte * auth , int authSz )
4264+ const byte * auth , int authSz , const byte * authPolicy , int authPolicySz )
42644265{
42654266 int rc , rctmp , alreadyExists = 0 ;
42664267 NV_DefineSpace_In in ;
@@ -4275,7 +4276,7 @@ int wolfTPM2_NVCreateAuth(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* parent,
42754276
42764277 XMEMSET (& in , 0 , sizeof (in ));
42774278 in .authHandle = parent -> hndl ;
4278- if (auth && authSz > 0 ) {
4279+ if (auth != NULL && authSz > 0 ) {
42794280 if (authSz > (int )sizeof (in .auth .buffer ))
42804281 authSz = (int )sizeof (in .auth .buffer );
42814282 in .auth .size = authSz ;
@@ -4285,6 +4286,14 @@ int wolfTPM2_NVCreateAuth(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* parent,
42854286 in .publicInfo .nvPublic .nameAlg = WOLFTPM2_WRAP_DIGEST ;
42864287 in .publicInfo .nvPublic .attributes = nvAttributes ;
42874288 in .publicInfo .nvPublic .dataSize = (UINT16 )maxSize ;
4289+ if (authPolicy != NULL && authPolicySz > 0 ) {
4290+ if (authPolicySz > (int )sizeof (in .publicInfo .nvPublic .authPolicy .buffer )) {
4291+ authPolicySz = (int )sizeof (in .publicInfo .nvPublic .authPolicy .buffer );
4292+ }
4293+ in .publicInfo .nvPublic .authPolicy .size = authPolicySz ;
4294+ XMEMCPY (in .publicInfo .nvPublic .authPolicy .buffer , authPolicy ,
4295+ in .publicInfo .nvPublic .authPolicy .size );
4296+ }
42884297
42894298 rc = TPM2_NV_DefineSpace (& in );
42904299 if (rc == TPM_RC_NV_DEFINED ) {
@@ -4321,6 +4330,14 @@ int wolfTPM2_NVCreateAuth(WOLFTPM2_DEV* dev, WOLFTPM2_HANDLE* parent,
43214330 return (rc == TPM_RC_SUCCESS && alreadyExists ) ? TPM_RC_NV_DEFINED : rc ;
43224331}
43234332
4333+ int wolfTPM2_NVCreateAuth (WOLFTPM2_DEV * dev , WOLFTPM2_HANDLE * parent ,
4334+ WOLFTPM2_NV * nv , word32 nvIndex , word32 nvAttributes , word32 maxSize ,
4335+ const byte * auth , int authSz )
4336+ {
4337+ return wolfTPM2_NVCreateAuthPolicy (dev , parent , nv , nvIndex , nvAttributes ,
4338+ maxSize , auth , authSz , NULL , 0 );
4339+ }
4340+
43244341/* older API kept for compatibility, recommend using wolfTPM2_NVCreateAuth */
43254342int wolfTPM2_NVCreate (WOLFTPM2_DEV * dev , TPM_HANDLE authHandle ,
43264343 word32 nvIndex , word32 nvAttributes , word32 maxSize ,
0 commit comments