/// <summary> /// Create a simple unbound & unseeded session supporting session encryption. /// </summary> public AuthSession CancelSafeStartAuthSession( TpmSe sessionType, TpmAlgId authHash, int nonceCallerSize = 16) { byte[] nonceTpm; var EmptySalt = new byte[0]; TpmHandle hSess; var ctx = new CancelationCtx(this, "FlushContext"); do { _AllowErrors(); hSess = StartAuthSession(TpmRh.Null, TpmRh.Null, GetRandomBytes(nonceCallerSize), EmptySalt, sessionType, new SymDef(), authHash, out nonceTpm); } while (ctx.NeedRetry()); ctx.Done(); AuthSession sess = hSess + SessionAttr.ContinueSession; _InitializeSession(sess); return sess; }
} // class CancelationCtx public bool CancelSafeFlushContext(TpmHandle h) { if (h == null || h.handle == 0 /*|| h.handle == TpmRh.Null*/) return false; var ctx = new CancelationCtx(this, "FlushContext"); do { _AllowErrors().FlushContext(h); } while (ctx.NeedRetry()); return ctx.Done(); }