Debian Codegraph @

tpm2/tpm2.go

raw
1 // Package tpm2 contains TPM 2.0 commands and structures.
2 package tpm2
3
4 import (
5 "bytes"
6 "encoding/binary"
7
8 "github.com/google/go-tpm/tpm2/transport"
9 )
10
11 // handle represents a TPM handle as comprehended in Part 3: Commands.
12 // In the context of TPM commands, handles are special parameters for which
13 // there is a known associated name.
14 // This is not an exported interface, because the reflection logic has special
15 // behavior for AuthHandle, due to the fact that referencing Session from this
16 // interface would break the ability to make TPMHandle implement it.
17 type handle interface {
18 // HandleValue is the numeric concrete handle value in the TPM.
19 HandleValue() uint32
20 // KnownName is the TPM Name of the associated entity. See Part 1, section 16.
21 KnownName() *TPM2BName
22 }
23
24 // NamedHandle represents an associated pairing of TPM handle and known Name.
25 type NamedHandle struct {
26 Handle TPMHandle
27 Name TPM2BName
28 }
29
30 // HandleValue implements the handle interface.
31 func (h NamedHandle) HandleValue() uint32 {
32 return h.Handle.HandleValue()
33 }
34
35 // KnownName implements the handle interface.
36 func (h NamedHandle) KnownName() *TPM2BName {
37 return &h.Name
38 }
39
40 // AuthHandle allows the caller to add an authorization session onto a handle.
41 type AuthHandle struct {
42 Handle TPMHandle
43 Name TPM2BName
44 Auth Session
45 }
46
47 // HandleValue implements the handle interface.
48 func (h AuthHandle) HandleValue() uint32 {
49 return h.Handle.HandleValue()
50 }
51
52 // KnownName implements the handle interface.
53 // If Name is not provided (i.e., only Auth), then rely on the underlying
54 // TPMHandle.
55 func (h AuthHandle) KnownName() *TPM2BName {
56 if len(h.Name.Buffer) != 0 {
57 return &h.Name
58 }
59 return h.Handle.KnownName()
60 }
61
62 // invalidHandleValue is the sentinel value used for handles that have been
63 // reconstructed from unmarshalling.
64 // This value is intentionally invalid to prevent accidental use with a real TPM.
65 const invalidHandleValue TPMHandle = 0xFFFFFFFF
66
67 // UnmarshalledHandle represents a handle reconstructed from unmarshalling.
68 // This type is used for audit and inspection purposes where only the Name is
69 // available, not the actual TPM handle value.
70 //
71 // The HandleValue() method returns [invalidHandleValue] to prevent accidental
72 // use of these handles with a real TPM.
73 type UnmarshalledHandle struct {
74 Name TPM2BName
75 }
76
77 // HandleValue implements the handle interface.
78 // Returns invalidHandleValue since unmarshalled handles don't have real TPM handle values.
79 func (h UnmarshalledHandle) HandleValue() uint32 {
80 return uint32(invalidHandleValue)
81 }
82
83 // KnownName implements the handle interface.
84 func (h UnmarshalledHandle) KnownName() *TPM2BName {
85 return &h.Name
86 }
87
88 // Command is an interface for any TPM command, parameterized by its response
89 // type.
90 type Command[R any, PR *R] interface {
91 // The TPM command code associated with this command.
92 Command() TPMCC
93 // Executes the command and returns the response.
94 Execute(t transport.TPM, s ...Session) (PR, error)
95 }
96
97 // PolicyCommand is a TPM command that can be part of a TPM policy.
98 type PolicyCommand interface {
99 // Update updates the given policy hash according to the command
100 // parameters.
101 Update(policy *PolicyCalculator) error
102 }
103
104 // Shutdown is the input to TPM2_Shutdown.
105 // See definition in Part 3, Commands, section 9.4.
106 type Shutdown struct {
107 // TPM_SU_CLEAR or TPM_SU_STATE
108 ShutdownType TPMSU
109 }
110
111 // Command implements the Command interface.
112 func (Shutdown) Command() TPMCC { return TPMCCShutdown }
113
114 // Execute executes the command and returns the response.
115 func (cmd Shutdown) Execute(t transport.TPM, s ...Session) (*ShutdownResponse, error) {
116 var rsp ShutdownResponse
117 err := execute[ShutdownResponse](t, cmd, &rsp, s...)
118 if err != nil {
119 return nil, err
120 }
121 return &rsp, nil
122 }
123
124 // ShutdownResponse is the response from TPM2_Shutdown.
125 type ShutdownResponse struct{}
126
127 // Startup is the input to TPM2_Startup.
128 // See definition in Part 3, Commands, section 9.3.
129 type Startup struct {
130 // TPM_SU_CLEAR or TPM_SU_STATE
131 StartupType TPMSU
132 }
133
134 // Command implements the Command interface.
135 func (Startup) Command() TPMCC { return TPMCCStartup }
136
137 // Execute executes the command and returns the response.
138 func (cmd Startup) Execute(t transport.TPM, s ...Session) (*StartupResponse, error) {
139 var rsp StartupResponse
140 err := execute[StartupResponse](t, cmd, &rsp, s...)
141 if err != nil {
142 return nil, err
143 }
144 return &rsp, nil
145 }
146
147 // StartupResponse is the response from TPM2_Startup.
148 type StartupResponse struct{}
149
150 // StartAuthSession is the input to TPM2_StartAuthSession.
151 // See definition in Part 3, Commands, section 11.1
152 type StartAuthSession struct {
153 // handle of a loaded decrypt key used to encrypt salt
154 // may be TPM_RH_NULL
155 TPMKey handle `gotpm:"handle"`
156 // entity providing the authValue
157 // may be TPM_RH_NULL
158 Bind handle `gotpm:"handle"`
159 // initial nonceCaller, sets nonceTPM size for the session
160 // shall be at least 16 octets
161 NonceCaller TPM2BNonce
162 // value encrypted according to the type of tpmKey
163 // If tpmKey is TPM_RH_NULL, this shall be the Empty Buffer.
164 EncryptedSalt TPM2BEncryptedSecret
165 // indicates the type of the session; simple HMAC or policy (including
166 // a trial policy)
167 SessionType TPMSE
168 // the algorithm and key size for parameter encryption
169 // may select transport.TPM_ALG_NULL
170 Symmetric TPMTSymDef
171 // hash algorithm to use for the session
172 // Shall be a hash algorithm supported by the TPM and not transport.TPM_ALG_NULL
173 AuthHash TPMIAlgHash
174 }
175
176 // Command implements the Command interface.
177 func (StartAuthSession) Command() TPMCC { return TPMCCStartAuthSession }
178
179 // Execute executes the command and returns the response.
180 func (cmd StartAuthSession) Execute(t transport.TPM, s ...Session) (*StartAuthSessionResponse, error) {
181 var rsp StartAuthSessionResponse
182 if err := execute[StartAuthSessionResponse](t, cmd, &rsp, s...); err != nil {
183 return nil, err
184 }
185 return &rsp, nil
186 }
187
188 // StartAuthSessionResponse is the response from TPM2_StartAuthSession.
189 type StartAuthSessionResponse struct {
190 // handle for the newly created session
191 SessionHandle TPMISHAuthSession `gotpm:"handle"`
192 // the initial nonce from the TPM, used in the computation of the sessionKey
193 NonceTPM TPM2BNonce
194 }
195
196 // Create is the input to TPM2_Create.
197 // See definition in Part 3, Commands, section 12.1
198 type Create struct {
199 // handle of parent for new object
200 ParentHandle handle `gotpm:"handle,auth"`
201 // the sensitive data
202 InSensitive TPM2BSensitiveCreate
203 // the public template
204 InPublic TPM2BPublic
205 // data that will be included in the creation data for this
206 // object to provide permanent, verifiable linkage between this
207 // object and some object owner data
208 OutsideInfo TPM2BData
209 // PCR that will be used in creation data
210 CreationPCR TPMLPCRSelection
211 }
212
213 // Command implements the Command interface.
214 func (Create) Command() TPMCC { return TPMCCCreate }
215
216 // Execute executes the command and returns the response.
217 func (cmd Create) Execute(t transport.TPM, s ...Session) (*CreateResponse, error) {
218 var rsp CreateResponse
219 if err := execute[CreateResponse](t, cmd, &rsp, s...); err != nil {
220 return nil, err
221 }
222 return &rsp, nil
223 }
224
225 // CreateResponse is the response from TPM2_Create.
226 type CreateResponse struct {
227 // the private portion of the object
228 OutPrivate TPM2BPrivate
229 // the public portion of the created object
230 OutPublic TPM2BPublic
231 // contains a TPMS_CREATION_DATA
232 CreationData tpm2bCreationData
233 // digest of creationData using nameAlg of outPublic
234 CreationHash TPM2BDigest
235 // ticket used by TPM2_CertifyCreation() to validate that the
236 // creation data was produced by the TPM.
237 CreationTicket TPMTTKCreation
238 }
239
240 // Load is the input to TPM2_Load.
241 // See definition in Part 3, Commands, section 12.2
242 type Load struct {
243 // handle of parent for new object
244 ParentHandle handle `gotpm:"handle,auth"`
245 // the private portion of the object
246 InPrivate TPM2BPrivate
247 // the public portion of the object
248 InPublic TPM2BPublic
249 }
250
251 // Command implements the Command interface.
252 func (Load) Command() TPMCC { return TPMCCLoad }
253
254 // Execute executes the command and returns the response.
255 func (cmd Load) Execute(t transport.TPM, s ...Session) (*LoadResponse, error) {
256 var rsp LoadResponse
257 if err := execute[LoadResponse](t, cmd, &rsp, s...); err != nil {
258 return nil, err
259 }
260 return &rsp, nil
261 }
262
263 // LoadResponse is the response from TPM2_Load.
264 type LoadResponse struct {
265 // handle of type TPM_HT_TRANSIENT for loaded object
266 ObjectHandle TPMHandle `gotpm:"handle"`
267 // Name of the loaded object
268 Name TPM2BName
269 }
270
271 // LoadExternal is the input to TPM2_LoadExternal.
272 // See definition in Part 3, Commands, section 12.3
273 type LoadExternal struct {
274 // the sensitive portion of the object (optional)
275 InPrivate TPM2BSensitive `gotpm:"optional"`
276 // the public portion of the object
277 InPublic TPM2BPublic
278 // hierarchy with which the object area is associated
279 Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
280 }
281
282 // Command implements the Command interface.
283 func (LoadExternal) Command() TPMCC { return TPMCCLoadExternal }
284
285 // Execute executes the command and returns the response.
286 func (cmd LoadExternal) Execute(t transport.TPM, s ...Session) (*LoadExternalResponse, error) {
287 var rsp LoadExternalResponse
288 if err := execute[LoadExternalResponse](t, cmd, &rsp, s...); err != nil {
289 return nil, err
290 }
291 return &rsp, nil
292 }
293
294 // LoadExternalResponse is the response from TPM2_LoadExternal.
295 type LoadExternalResponse struct {
296 // handle of type TPM_HT_TRANSIENT for loaded object
297 ObjectHandle TPMHandle `gotpm:"handle"`
298 // Name of the loaded object
299 Name TPM2BName
300 }
301
302 // ReadPublic is the input to TPM2_ReadPublic.
303 // See definition in Part 3, Commands, section 12.4
304 type ReadPublic struct {
305 // TPM handle of an object
306 ObjectHandle handle `gotpm:"handle"`
307 }
308
309 // Command implements the Command interface.
310 func (ReadPublic) Command() TPMCC { return TPMCCReadPublic }
311
312 // Execute executes the command and returns the response.
313 func (cmd ReadPublic) Execute(t transport.TPM, s ...Session) (*ReadPublicResponse, error) {
314 var rsp ReadPublicResponse
315 if err := execute[ReadPublicResponse](t, cmd, &rsp, s...); err != nil {
316 return nil, err
317 }
318 return &rsp, nil
319 }
320
321 // ReadPublicResponse is the response from TPM2_ReadPublic.
322 type ReadPublicResponse struct {
323 // structure containing the public area of an object
324 OutPublic TPM2BPublic
325 // name of object
326 Name TPM2BName
327 // the Qualified Name of the object
328 QualifiedName TPM2BName
329 }
330
331 // ActivateCredential is the input to TPM2_ActivateCredential.
332 // See definition in Part 3, Commands, section 12.5.
333 type ActivateCredential struct {
334 // handle of the object associated with certificate in credentialBlob
335 ActivateHandle handle `gotpm:"handle,auth"`
336 // loaded key used to decrypt the TPMS_SENSITIVE in credentialBlob
337 KeyHandle handle `gotpm:"handle,auth"`
338 // the credential
339 CredentialBlob TPM2BIDObject
340 // keyHandle algorithm-dependent encrypted seed that protects credentialBlob
341 Secret TPM2BEncryptedSecret
342 }
343
344 // Command implements the Command interface.
345 func (ActivateCredential) Command() TPMCC { return TPMCCActivateCredential }
346
347 // Execute executes the command and returns the response.
348 func (cmd ActivateCredential) Execute(t transport.TPM, s ...Session) (*ActivateCredentialResponse, error) {
349 var rsp ActivateCredentialResponse
350 if err := execute[ActivateCredentialResponse](t, cmd, &rsp, s...); err != nil {
351 return nil, err
352 }
353 return &rsp, nil
354 }
355
356 // ActivateCredentialResponse is the response from TPM2_ActivateCredential.
357 type ActivateCredentialResponse struct {
358 // the decrypted certificate information
359 CertInfo TPM2BDigest
360 }
361
362 // MakeCredential is the input to TPM2_MakeCredential.
363 // See definition in Part 3, Commands, section 12.6.
364 type MakeCredential struct {
365 // loaded public area, used to encrypt the sensitive area containing the credential key
366 Handle TPMIDHObject `gotpm:"handle"`
367 // the credential information
368 Credential TPM2BDigest
369 // Name of the object to which the credential applies
370 ObjectName TPM2BName
371 }
372
373 // Command implements the Command interface.
374 func (MakeCredential) Command() TPMCC { return TPMCCMakeCredential }
375
376 // Execute executes the command and returns the response.
377 func (cmd MakeCredential) Execute(t transport.TPM, s ...Session) (*MakeCredentialResponse, error) {
378 var rsp MakeCredentialResponse
379 if err := execute[MakeCredentialResponse](t, cmd, &rsp, s...); err != nil {
380 return nil, err
381 }
382 return &rsp, nil
383 }
384
385 // MakeCredentialResponse is the response from TPM2_MakeCredential.
386 type MakeCredentialResponse struct {
387 // the credential
388 CredentialBlob TPM2BIDObject
389 // handle algorithm-dependent data that wraps the key that encrypts credentialBlob
390 Secret TPM2BEncryptedSecret
391 }
392
393 // Unseal is the input to TPM2_Unseal.
394 // See definition in Part 3, Commands, section 12.7
395 type Unseal struct {
396 ItemHandle handle `gotpm:"handle,auth"`
397 }
398
399 // Command implements the Command interface.
400 func (Unseal) Command() TPMCC { return TPMCCUnseal }
401
402 // Execute executes the command and returns the response.
403 func (cmd Unseal) Execute(t transport.TPM, s ...Session) (*UnsealResponse, error) {
404 var rsp UnsealResponse
405 if err := execute[UnsealResponse](t, cmd, &rsp, s...); err != nil {
406 return nil, err
407 }
408 return &rsp, nil
409 }
410
411 // UnsealResponse is the response from TPM2_Unseal.
412 type UnsealResponse struct {
413 OutData TPM2BSensitiveData
414 }
415
416 // ObjectChangeAuth is the input to TPM2_ObjectChangeAuth.
417 // See definition in Part 3, Commands, section 12.8
418 type ObjectChangeAuth struct {
419 // TPM handle of an object
420 ObjectHandle handle `gotpm:"handle,auth"`
421 // handle of the parent
422 ParentHandle handle `gotpm:"handle"`
423 // new authorization value
424 NewAuth TPM2BAuth
425 }
426
427 // Command implements the Command interface.
428 func (ObjectChangeAuth) Command() TPMCC { return TPMCCObjectChangeAuth }
429
430 // Execute executes the command and returns the response.
431 func (cmd ObjectChangeAuth) Execute(t transport.TPM, s ...Session) (*ObjectChangeAuthResponse, error) {
432 var rsp ObjectChangeAuthResponse
433 if err := execute[ObjectChangeAuthResponse](t, cmd, &rsp, s...); err != nil {
434 return nil, err
435 }
436 return &rsp, nil
437 }
438
439 // ObjectChangeAuthResponse the response from TPM2_ObjectChangeAuth.
440 type ObjectChangeAuthResponse struct {
441 // private area containing the new authorization value
442 OutPrivate TPM2BPrivate
443 }
444
445 // CreateLoaded is the input to TPM2_CreateLoaded.
446 // See definition in Part 3, Commands, section 12.9
447 type CreateLoaded struct {
448 // Handle of a transient storage key, a persistent storage key,
449 // TPM_RH_ENDORSEMENT, TPM_RH_OWNER, TPM_RH_PLATFORM+{PP}, or TPM_RH_NULL
450 ParentHandle handle `gotpm:"handle,auth"`
451 // the sensitive data, see TPM 2.0 Part 1 Sensitive Values
452 InSensitive TPM2BSensitiveCreate
453 // the public template
454 InPublic TPM2BTemplate
455 }
456
457 // Command implements the Command interface.
458 func (CreateLoaded) Command() TPMCC { return TPMCCCreateLoaded }
459
460 // Execute executes the command and returns the response.
461 func (cmd CreateLoaded) Execute(t transport.TPM, s ...Session) (*CreateLoadedResponse, error) {
462 var rsp CreateLoadedResponse
463 if err := execute[CreateLoadedResponse](t, cmd, &rsp, s...); err != nil {
464 return nil, err
465 }
466 return &rsp, nil
467 }
468
469 // CreateLoadedResponse is the response from TPM2_CreateLoaded.
470 type CreateLoadedResponse struct {
471 // handle of type TPM_HT_TRANSIENT for loaded object
472 ObjectHandle TPMHandle `gotpm:"handle"`
473 // the sensitive area of the object (optional)
474 OutPrivate TPM2BPrivate `gotpm:"optional"`
475 // the public portion of the created object
476 OutPublic TPM2BPublic
477 // the name of the created object
478 Name TPM2BName
479 }
480
481 // EncryptDecrypt2 is the input to TPM2_EncryptDecrypt2
482 type EncryptDecrypt2 struct {
483 // reference to public portion of symmetric key to use for encryption
484 KeyHandle handle `gotpm:"handle,auth"`
485 Message TPM2BMaxBuffer
486 Decrypt TPMIYesNo
487 Mode TPMIAlgSymMode `gotpm:"nullable"`
488 IV TPM2BIV
489 }
490
491 // Command implements the Command interface.
492 func (EncryptDecrypt2) Command() TPMCC { return TPMCCEncryptDecrypt2 }
493
494 // Execute executes the command and returns the response.
495 func (cmd EncryptDecrypt2) Execute(t transport.TPM, s ...Session) (*EncryptDecrypt2Response, error) {
496 var rsp EncryptDecrypt2Response
497 err := execute[EncryptDecrypt2Response](t, cmd, &rsp, s...)
498 if err != nil {
499 return nil, err
500 }
501 return &rsp, nil
502 }
503
504 // EncryptDecrypt2Response is the response from TPM2_EncryptDecrypt2.
505 type EncryptDecrypt2Response struct {
506 OutData TPM2BMaxBuffer
507 IV TPM2BIV
508 }
509
510 // RSAEncrypt is the input to TPM2_RSA_Encrypt
511 // See definition in Part 3, Commands, section 14.2.
512 type RSAEncrypt struct {
513 // reference to public portion of RSA key to use for encryption
514 KeyHandle handle `gotpm:"handle"`
515 // message to be encrypted
516 Message TPM2BPublicKeyRSA
517 // the padding scheme to use if scheme associated with keyHandle is TPM_ALG_NULL
518 InScheme TPMTRSADecrypt `gotpm:"nullable"`
519 // optional label L to be associated with the message
520 Label TPM2BData `gotpm:"optional"`
521 }
522
523 // Command implements the Command interface.
524 func (RSAEncrypt) Command() TPMCC { return TPMCCRSAEncrypt }
525
526 // Execute executes the command and returns the response.
527 func (cmd RSAEncrypt) Execute(t transport.TPM, s ...Session) (*RSAEncryptResponse, error) {
528 var rsp RSAEncryptResponse
529 if err := execute[RSAEncryptResponse](t, cmd, &rsp, s...); err != nil {
530 return nil, err
531 }
532 return &rsp, nil
533 }
534
535 // RSAEncryptResponse is the response from TPM2_RSA_Encrypt
536 type RSAEncryptResponse struct {
537 // encrypted output
538 OutData TPM2BPublicKeyRSA
539 }
540
541 // RSADecrypt is the input to TPM2_RSA_Decrypt
542 // See definition in Part 3, Commands, section 14.3.
543 type RSADecrypt struct {
544 // RSA key to use for decryption
545 KeyHandle handle `gotpm:"handle,auth"`
546 // cipher text to be decrypted
547 CipherText TPM2BPublicKeyRSA
548 // the padding scheme to use if scheme associated with keyHandle is TPM_ALG_NULL
549 InScheme TPMTRSADecrypt `gotpm:"nullable"`
550 // label whose association with the message is to be verified
551 Label TPM2BData `gotpm:"optional"`
552 }
553
554 // Command implements the Command interface.
555 func (RSADecrypt) Command() TPMCC { return TPMCCRSADecrypt }
556
557 // Execute executes the command and returns the response.
558 func (cmd RSADecrypt) Execute(t transport.TPM, s ...Session) (*RSADecryptResponse, error) {
559 var rsp RSADecryptResponse
560 if err := execute[RSADecryptResponse](t, cmd, &rsp, s...); err != nil {
561 return nil, err
562 }
563 return &rsp, nil
564 }
565
566 // RSADecryptResponse is the response from TPM2_RSA_Decrypt
567 type RSADecryptResponse struct {
568 // decrypted output
569 Message TPM2BPublicKeyRSA
570 }
571
572 // ECDHZGen is the input to TPM2_ECDHZGen.
573 // See definition in Part 3, Commands, section 14.5
574 type ECDHZGen struct {
575 // handle of a loaded ECC key
576 KeyHandle handle `gotpm:"handle,auth"`
577 // a public key
578 InPoint TPM2BECCPoint
579 }
580
581 // Command implements the Command interface.
582 func (ECDHZGen) Command() TPMCC { return TPMCCECDHZGen }
583
584 // Execute executes the command and returns the response.
585 func (cmd ECDHZGen) Execute(t transport.TPM, s ...Session) (*ECDHZGenResponse, error) {
586 var rsp ECDHZGenResponse
587 if err := execute[ECDHZGenResponse](t, cmd, &rsp, s...); err != nil {
588 return nil, err
589 }
590 return &rsp, nil
591 }
592
593 // ECDHZGenResponse is the response from TPM2_ECDHZGen.
594 type ECDHZGenResponse struct {
595 // X and Y coordinates of the product of the multiplication
596 OutPoint TPM2BECCPoint
597 }
598
599 // Hash is the input to TPM2_Hash.
600 // See definition in Part 3, Commands, section 15.4
601 type Hash struct {
602 //data to be hashed
603 Data TPM2BMaxBuffer
604 // algorithm for the hash being computed - shall not be TPM_ALH_NULL
605 HashAlg TPMIAlgHash
606 // hierarchy to use for the ticket (TPM_RH_NULL_allowed)
607 Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
608 }
609
610 // Command implements the Command interface.
611 func (Hash) Command() TPMCC { return TPMCCHash }
612
613 // Execute executes the command and returns the response.
614 func (cmd Hash) Execute(t transport.TPM, s ...Session) (*HashResponse, error) {
615 var rsp HashResponse
616 if err := execute[HashResponse](t, cmd, &rsp, s...); err != nil {
617 return nil, err
618 }
619 return &rsp, nil
620 }
621
622 // HashResponse is the response from TPM2_Hash.
623 type HashResponse struct {
624 // results
625 OutHash TPM2BDigest
626 // ticket indicating that the sequence of octets used to
627 // compute outDigest did not start with TPM_GENERATED_VALUE
628 Validation TPMTTKHashCheck
629 }
630
631 // Hmac is the input to TPM2_HMAC.
632 // See definition in Part 3, Commands, section 15.5.
633 type Hmac struct {
634 // HMAC key handle requiring an authorization session for the USER role
635 Handle AuthHandle `gotpm:"handle,auth"`
636 // HMAC data
637 Buffer TPM2BMaxBuffer
638 // Algorithm to use for HMAC
639 HashAlg TPMIAlgHash
640 }
641
642 // Command implements the Command interface.
643 func (Hmac) Command() TPMCC { return TPMCCHMAC }
644
645 // Execute executes the command and returns the response.
646 func (cmd Hmac) Execute(t transport.TPM, s ...Session) (*HmacResponse, error) {
647 var rsp HmacResponse
648 if err := execute[HmacResponse](t, cmd, &rsp, s...); err != nil {
649 return nil, err
650 }
651 return &rsp, nil
652 }
653
654 // HmacResponse is the response from TPM2_HMAC.
655 type HmacResponse struct {
656 // the returned HMAC in a sized buffer
657 OutHMAC TPM2BDigest
658 }
659
660 // GetRandom is the input to TPM2_GetRandom.
661 // See definition in Part 3, Commands, section 16.1
662 type GetRandom struct {
663 // number of octets to return
664 BytesRequested uint16
665 }
666
667 // Command implements the Command interface.
668 func (GetRandom) Command() TPMCC { return TPMCCGetRandom }
669
670 // Execute executes the command and returns the response.
671 func (cmd GetRandom) Execute(t transport.TPM, s ...Session) (*GetRandomResponse, error) {
672 var rsp GetRandomResponse
673 if err := execute[GetRandomResponse](t, cmd, &rsp, s...); err != nil {
674 return nil, err
675 }
676 return &rsp, nil
677 }
678
679 // GetRandomResponse is the response from TPM2_GetRandom.
680 type GetRandomResponse struct {
681 // the random octets
682 RandomBytes TPM2BDigest
683 }
684
685 // HashSequenceStart is the input to TPM2_HashSequenceStart.
686 // See definition in Part 3, Commands, section 17.3
687 type HashSequenceStart struct {
688 // authorization value for subsequent use of the sequence
689 Auth TPM2BAuth
690 // the hash algorithm to use for the hash sequence
691 // An Event Sequence starts if this is TPM_ALG_NULL.
692 HashAlg TPMIAlgHash
693 }
694
695 // Command implements the Command interface.
696 func (HashSequenceStart) Command() TPMCC { return TPMCCHashSequenceStart }
697
698 // Execute executes the command and returns the response.
699 func (cmd HashSequenceStart) Execute(t transport.TPM, s ...Session) (*HashSequenceStartResponse, error) {
700 var rsp HashSequenceStartResponse
701 if err := execute[HashSequenceStartResponse](t, cmd, &rsp, s...); err != nil {
702 return nil, err
703 }
704 return &rsp, nil
705 }
706
707 // HashSequenceStartResponse is the response from TPM2_StartHashSequence.
708 type HashSequenceStartResponse struct {
709 // a handle to reference the sequence
710 SequenceHandle TPMIDHObject
711 }
712
713 // HmacStart is the input to TPM2_HMAC_Start.
714 // See definition in Part 3, Commands, section 17.2.2
715 type HmacStart struct {
716 // HMAC key handle
717 Handle handle `gotpm:"handle,auth"`
718 // authorization value for subsequent use of the sequence
719 Auth TPM2BAuth
720 // the hash algorithm to use for the hmac sequence
721 HashAlg TPMIAlgHash `gotpm:"nullable"`
722 }
723
724 // Command implements the Command interface.
725 func (HmacStart) Command() TPMCC { return TPMCCHMACStart }
726
727 // Execute executes the command and returns the response.
728 func (cmd HmacStart) Execute(t transport.TPM, s ...Session) (*HmacStartResponse, error) {
729 var rsp HmacStartResponse
730 if err := execute[HmacStartResponse](t, cmd, &rsp, s...); err != nil {
731 return nil, err
732 }
733 return &rsp, nil
734 }
735
736 // HmacStartResponse is the response from TPM2_HMAC_Start.
737 // See definition in Part 3, Commands, section 17.2.2
738 type HmacStartResponse struct {
739 // a handle to reference the sequence
740 SequenceHandle TPMIDHObject `gotpm:"handle"`
741 }
742
743 // SequenceUpdate is the input to TPM2_SequenceUpdate.
744 // See definition in Part 3, Commands, section 17.4
745 type SequenceUpdate struct {
746 // handle for the sequence object
747 SequenceHandle handle `gotpm:"handle,auth,anon"`
748 // data to be added to hash
749 Buffer TPM2BMaxBuffer
750 }
751
752 // Command implements the Command interface.
753 func (SequenceUpdate) Command() TPMCC { return TPMCCSequenceUpdate }
754
755 // Execute executes the command and returns the response.
756 func (cmd SequenceUpdate) Execute(t transport.TPM, s ...Session) (*SequenceUpdateResponse, error) {
757 var rsp SequenceUpdateResponse
758 if err := execute[SequenceUpdateResponse](t, cmd, &rsp, s...); err != nil {
759 return nil, err
760 }
761 return &rsp, nil
762 }
763
764 // SequenceUpdateResponse is the response from TPM2_SequenceUpdate.
765 type SequenceUpdateResponse struct{}
766
767 // SequenceComplete is the input to TPM2_SequenceComplete.
768 // See definition in Part 3, Commands, section 17.5
769 type SequenceComplete struct {
770 // authorization for the sequence
771 SequenceHandle handle `gotpm:"handle,auth,anon"`
772 // data to be added to the hash/HMAC
773 Buffer TPM2BMaxBuffer
774 // hierarchy of the ticket for a hash
775 Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
776 }
777
778 // Command implements the Command interface.
779 func (SequenceComplete) Command() TPMCC { return TPMCCSequenceComplete }
780
781 // Execute executes the command and returns the response.
782 func (cmd SequenceComplete) Execute(t transport.TPM, s ...Session) (*SequenceCompleteResponse, error) {
783 var rsp SequenceCompleteResponse
784 if err := execute[SequenceCompleteResponse](t, cmd, &rsp, s...); err != nil {
785 return nil, err
786 }
787 return &rsp, nil
788 }
789
790 // SequenceCompleteResponse is the response from TPM2_SequenceComplete.
791 type SequenceCompleteResponse struct {
792 // the returned HMAC or digest in a sized buffer
793 Result TPM2BDigest
794 // ticket indicating that the sequence of octets used to
795 // compute outDigest did not start with TPM_GENERATED_VALUE
796 Validation TPMTTKHashCheck
797 }
798
799 // Certify is the input to TPM2_Certify.
800 // See definition in Part 3, Commands, section 18.2.
801 type Certify struct {
802 // handle of the object to be certified
803 ObjectHandle handle `gotpm:"handle,auth"`
804 // handle of the key used to sign the attestation structure
805 SignHandle handle `gotpm:"handle,auth"`
806 // user provided qualifying data
807 QualifyingData TPM2BData
808 // signing scheme to use if the scheme for signHandle is TPM_ALG_NULL
809 InScheme TPMTSigScheme
810 }
811
812 // Command implements the Command interface.
813 func (Certify) Command() TPMCC { return TPMCCCertify }
814
815 // Execute executes the command and returns the response.
816 func (cmd Certify) Execute(t transport.TPM, s ...Session) (*CertifyResponse, error) {
817 var rsp CertifyResponse
818 if err := execute[CertifyResponse](t, cmd, &rsp, s...); err != nil {
819 return nil, err
820 }
821 return &rsp, nil
822 }
823
824 // CertifyResponse is the response from TPM2_Certify.
825 type CertifyResponse struct {
826 // the structure that was signed
827 CertifyInfo TPM2BAttest
828 // the asymmetric signature over certifyInfo using the key referenced by signHandle
829 Signature TPMTSignature
830 }
831
832 // CertifyCreation is the input to TPM2_CertifyCreation.
833 // See definition in Part 3, Commands, section 18.3.
834 type CertifyCreation struct {
835 // handle of the key that will sign the attestation block
836 SignHandle handle `gotpm:"handle,auth"`
837 // the object associated with the creation data
838 ObjectHandle handle `gotpm:"handle"`
839 // user-provided qualifying data
840 QualifyingData TPM2BData
841 // hash of the creation data produced by TPM2_Create() or TPM2_CreatePrimary()
842 CreationHash TPM2BDigest
843 // signing scheme to use if the scheme for signHandle is TPM_ALG_NULL
844 InScheme TPMTSigScheme
845 // ticket produced by TPM2_Create() or TPM2_CreatePrimary()
846 CreationTicket TPMTTKCreation
847 }
848
849 // Command implements the Command interface.
850 func (CertifyCreation) Command() TPMCC { return TPMCCCertifyCreation }
851
852 // Execute executes the command and returns the response.
853 func (cmd CertifyCreation) Execute(t transport.TPM, s ...Session) (*CertifyCreationResponse, error) {
854 var rsp CertifyCreationResponse
855 if err := execute[CertifyCreationResponse](t, cmd, &rsp, s...); err != nil {
856 return nil, err
857 }
858 return &rsp, nil
859 }
860
861 // CertifyCreationResponse is the response from TPM2_CertifyCreation.
862 type CertifyCreationResponse struct {
863 // the structure that was signed
864 CertifyInfo TPM2BAttest
865 // the signature over certifyInfo
866 Signature TPMTSignature
867 }
868
869 // Quote is the input to TPM2_Quote.
870 // See definition in Part 3, Commands, section 18.4
871 type Quote struct {
872 // handle of key that will perform signature
873 SignHandle handle `gotpm:"handle,auth"`
874 // data supplied by the caller
875 QualifyingData TPM2BData
876 // signing scheme to use if the scheme for signHandle is TPM_ALG_NULL
877 InScheme TPMTSigScheme
878 // PCR set to quote
879 PCRSelect TPMLPCRSelection
880 }
881
882 // Command implements the Command interface.
883 func (Quote) Command() TPMCC { return TPMCCQuote }
884
885 // Execute executes the command and returns the response.
886 func (cmd Quote) Execute(t transport.TPM, s ...Session) (*QuoteResponse, error) {
887 var rsp QuoteResponse
888 if err := execute[QuoteResponse](t, cmd, &rsp, s...); err != nil {
889 return nil, err
890 }
891 return &rsp, nil
892 }
893
894 // QuoteResponse is the response from TPM2_Quote.
895 type QuoteResponse struct {
896 // the quoted information
897 Quoted TPM2BAttest
898 // the signature over quoted
899 Signature TPMTSignature
900 }
901
902 // GetSessionAuditDigest is the input to TPM2_GetSessionAuditDigest.
903 // See definition in Part 3, Commands, section 18.5
904 type GetSessionAuditDigest struct {
905 // handle of the privacy administrator (TPM_RH_ENDORSEMENT)
906 PrivacyAdminHandle handle `gotpm:"handle,auth"`
907 // handle of the signing key
908 SignHandle handle `gotpm:"handle,auth"`
909 // handle of the audit session
910 SessionHandle handle `gotpm:"handle"`
911 // user-provided qualifying data – may be zero-length
912 QualifyingData TPM2BData
913 // signing scheme to use if the scheme for signHandle is TPM_ALG_NULL
914 InScheme TPMTSigScheme
915 }
916
917 // Command implements the Command interface.
918 func (GetSessionAuditDigest) Command() TPMCC { return TPMCCGetSessionAuditDigest }
919
920 // Execute executes the command and returns the response.
921 func (cmd GetSessionAuditDigest) Execute(t transport.TPM, s ...Session) (*GetSessionAuditDigestResponse, error) {
922 var rsp GetSessionAuditDigestResponse
923 if err := execute[GetSessionAuditDigestResponse](t, cmd, &rsp, s...); err != nil {
924 return nil, err
925 }
926 return &rsp, nil
927 }
928
929 // GetSessionAuditDigestResponse is the response from
930 // TPM2_GetSessionAuditDigest.
931 type GetSessionAuditDigestResponse struct {
932 // the audit information that was signed
933 AuditInfo TPM2BAttest
934 // the signature over auditInfo
935 Signature TPMTSignature
936 }
937
938 // Commit is the input to TPM2_Commit.
939 // See definition in Part 3, Commands, section 19.2.
940 type Commit struct {
941 // handle of the key that will be used in the signing operation
942 SignHandle handle `gotpm:"handle,auth"`
943 // a point (M) on the curve used by signHandle
944 P1 TPM2BECCPoint
945 // octet array used to derive x-coordinate of a base point
946 S2 TPM2BSensitiveData
947 // y coordinate of the point associated with s2
948 Y2 TPM2BECCParameter
949 }
950
951 // Command implements the Command interface.
952 func (Commit) Command() TPMCC { return TPMCCCommit }
953
954 // Execute executes the command and returns the response.
955 func (cmd Commit) Execute(t transport.TPM, s ...Session) (*CommitResponse, error) {
956 var rsp CommitResponse
957 if err := execute[CommitResponse](t, cmd, &rsp, s...); err != nil {
958 return nil, err
959 }
960
961 return &rsp, nil
962 }
963
964 // CommitResponse is the response from TPM2_Commit.
965 type CommitResponse struct {
966 // ECC point K ≔ [ds](x2, y2)
967 K TPM2BECCPoint
968 // ECC point L ≔ [r](x2, y2)
969 L TPM2BECCPoint
970 // ECC point E ≔ [r]P1
971 E TPM2BECCPoint
972 // least-significant 16 bits of commitCount
973 Counter uint16
974 }
975
976 // VerifySignature is the input to TPM2_VerifySignature.
977 // See definition in Part 3, Commands, section 20.1
978 type VerifySignature struct {
979 // handle of public key that will be used in the validation
980 KeyHandle handle `gotpm:"handle"`
981 // digest of the signed message
982 Digest TPM2BDigest
983 // signature to be tested
984 Signature TPMTSignature
985 }
986
987 // Command implements the Command interface.
988 func (VerifySignature) Command() TPMCC { return TPMCCVerifySignature }
989
990 // Execute executes the command and returns the response.
991 func (cmd VerifySignature) Execute(t transport.TPM, s ...Session) (*VerifySignatureResponse, error) {
992 var rsp VerifySignatureResponse
993 if err := execute[VerifySignatureResponse](t, cmd, &rsp, s...); err != nil {
994 return nil, err
995 }
996 return &rsp, nil
997 }
998
999 // VerifySignatureResponse is the response from TPM2_VerifySignature.
1000 type VerifySignatureResponse struct {
1001 Validation TPMTTKVerified
1002 }
1003
1004 // Sign is the input to TPM2_Sign.
1005 // See definition in Part 3, Commands, section 20.2.
1006 type Sign struct {
1007 // Handle of key that will perform signing
1008 KeyHandle handle `gotpm:"handle,auth"`
1009 // digest to be signed
1010 Digest TPM2BDigest
1011 // signing scheme to use if the scheme for keyHandle is TPM_ALG_NULL
1012 InScheme TPMTSigScheme `gotpm:"nullable"`
1013 // proof that digest was created by the TPM.
1014 // If keyHandle is not a restricted signing key, then this
1015 // may be a NULL Ticket with tag = TPM_ST_CHECKHASH.
1016 Validation TPMTTKHashCheck
1017 }
1018
1019 // Command implements the Command interface.
1020 func (Sign) Command() TPMCC { return TPMCCSign }
1021
1022 // Execute executes the command and returns the response.
1023 func (cmd Sign) Execute(t transport.TPM, s ...Session) (*SignResponse, error) {
1024 var rsp SignResponse
1025 if err := execute[SignResponse](t, cmd, &rsp, s...); err != nil {
1026 return nil, err
1027 }
1028 return &rsp, nil
1029 }
1030
1031 // SignResponse is the response from TPM2_Sign.
1032 type SignResponse struct {
1033 // the signature
1034 Signature TPMTSignature
1035 }
1036
1037 // PCRExtend is the input to TPM2_PCR_Extend.
1038 // See definition in Part 3, Commands, section 22.2
1039 type PCRExtend struct {
1040 // handle of the PCR
1041 PCRHandle handle `gotpm:"handle,auth"`
1042 // list of tagged digest values to be extended
1043 Digests TPMLDigestValues
1044 }
1045
1046 // Command implements the Command interface.
1047 func (PCRExtend) Command() TPMCC { return TPMCCPCRExtend }
1048
1049 // Execute executes the command and returns the response.
1050 func (cmd PCRExtend) Execute(t transport.TPM, s ...Session) (*PCRExtendResponse, error) {
1051 var rsp PCRExtendResponse
1052 err := execute[PCRExtendResponse](t, cmd, &rsp, s...)
1053 if err != nil {
1054 return nil, err
1055 }
1056 return &rsp, nil
1057 }
1058
1059 // PCRExtendResponse is the response from TPM2_PCR_Extend.
1060 type PCRExtendResponse struct{}
1061
1062 // PCREvent is the input to TPM2_PCR_Event.
1063 // See definition in Part 3, Commands, section 22.3
1064 type PCREvent struct {
1065 // Handle of the PCR
1066 PCRHandle handle `gotpm:"handle,auth"`
1067 // Event data in sized buffer
1068 EventData TPM2BEvent
1069 }
1070
1071 // Command implements the Command interface.
1072 func (PCREvent) Command() TPMCC { return TPMCCPCREvent }
1073
1074 // Execute executes the command and returns the response.
1075 func (cmd PCREvent) Execute(t transport.TPM, s ...Session) (*PCREventResponse, error) {
1076 var rsp PCREventResponse
1077 err := execute[PCREventResponse](t, cmd, &rsp, s...)
1078 if err != nil {
1079 return nil, err
1080 }
1081 return &rsp, nil
1082 }
1083
1084 // PCREventResponse is the response from TPM2_PCR_Event.
1085 type PCREventResponse struct{}
1086
1087 // PCRRead is the input to TPM2_PCR_Read.
1088 // See definition in Part 3, Commands, section 22.4
1089 type PCRRead struct {
1090 // The selection of PCR to read
1091 PCRSelectionIn TPMLPCRSelection
1092 }
1093
1094 // Command implements the Command interface.
1095 func (PCRRead) Command() TPMCC { return TPMCCPCRRead }
1096
1097 // Execute executes the command and returns the response.
1098 func (cmd PCRRead) Execute(t transport.TPM, s ...Session) (*PCRReadResponse, error) {
1099 var rsp PCRReadResponse
1100 if err := execute[PCRReadResponse](t, cmd, &rsp, s...); err != nil {
1101 return nil, err
1102 }
1103 return &rsp, nil
1104 }
1105
1106 // PCRReadResponse is the response from TPM2_PCR_Read.
1107 type PCRReadResponse struct {
1108 // the current value of the PCR update counter
1109 PCRUpdateCounter uint32
1110 // the PCR in the returned list
1111 PCRSelectionOut TPMLPCRSelection
1112 // the contents of the PCR indicated in pcrSelectOut-> pcrSelection[] as tagged digests
1113 PCRValues TPMLDigest
1114 }
1115
1116 // PCRReset is the input to TPM2_PCRReset.
1117 // See definition in Part 3, Commands, section 22.8.
1118 type PCRReset struct {
1119 // the PCR to reset
1120 PCRHandle handle `gotpm:"handle,auth"`
1121 }
1122
1123 // Command implements the Command interface.
1124 func (PCRReset) Command() TPMCC { return TPMCCPCRReset }
1125
1126 // Execute executes the command and returns the response.
1127 func (cmd PCRReset) Execute(t transport.TPM, s ...Session) (*PCRResetResponse, error) {
1128 var rsp PCRResetResponse
1129 if err := execute[PCRResetResponse](t, cmd, &rsp, s...); err != nil {
1130 return nil, err
1131 }
1132 return &rsp, nil
1133 }
1134
1135 // PCRResetResponse is the response from TPM2_PCRReset.
1136 type PCRResetResponse struct{}
1137
1138 // PolicySigned is the input to TPM2_PolicySigned.
1139 // See definition in Part 3, Commands, section 23.3.
1140 type PolicySigned struct {
1141 // handle for an entity providing the authorization
1142 AuthObject handle `gotpm:"handle"`
1143 // handle for the policy session being extended
1144 PolicySession handle `gotpm:"handle"`
1145 // the policy nonce for the session
1146 NonceTPM TPM2BNonce
1147 // digest of the command parameters to which this authorization is limited
1148 CPHashA TPM2BDigest
1149 // a reference to a policy relating to the authorization – may be the Empty Buffer
1150 PolicyRef TPM2BNonce
1151 // time when authorization will expire, measured in seconds from the time
1152 // that nonceTPM was generated
1153 Expiration int32
1154 // signed authorization (not optional)
1155 Auth TPMTSignature
1156 }
1157
1158 // Command implements the Command interface.
1159 func (PolicySigned) Command() TPMCC { return TPMCCPolicySigned }
1160
1161 // Execute executes the command and returns the response.
1162 func (cmd PolicySigned) Execute(t transport.TPM, s ...Session) (*PolicySignedResponse, error) {
1163 var rsp PolicySignedResponse
1164 if err := execute[PolicySignedResponse](t, cmd, &rsp, s...); err != nil {
1165 return nil, err
1166 }
1167 return &rsp, nil
1168 }
1169
1170 // policyUpdate implements the PolicyUpdate helper for the several TPM policy
1171 // commands as described in Part 3, 23.2.3.
1172 func policyUpdate(policy *PolicyCalculator, cc TPMCC, arg2, arg3 []byte) error {
1173 if err := policy.Update(cc, arg2); err != nil {
1174 return err
1175 }
1176 return policy.Update(arg3)
1177 }
1178
1179 // Update implements the PolicyCommand interface.
1180 func (cmd PolicySigned) Update(policy *PolicyCalculator) error {
1181 return policyUpdate(policy, TPMCCPolicySigned, cmd.AuthObject.KnownName().Buffer, cmd.PolicyRef.Buffer)
1182 }
1183
1184 // PolicySignedResponse is the response from TPM2_PolicySigned.
1185 type PolicySignedResponse struct {
1186 // implementation-specific time value used to indicate to the TPM when the ticket expires
1187 Timeout TPM2BTimeout
1188 // produced if the command succeeds and expiration in the command was non-zero
1189 PolicyTicket TPMTTKAuth
1190 }
1191
1192 // PolicySecret is the input to TPM2_PolicySecret.
1193 // See definition in Part 3, Commands, section 23.4.
1194 type PolicySecret struct {
1195 // handle for an entity providing the authorization
1196 AuthHandle handle `gotpm:"handle,auth"`
1197 // handle for the policy session being extended
1198 PolicySession handle `gotpm:"handle"`
1199 // the policy nonce for the session
1200 NonceTPM TPM2BNonce
1201 // digest of the command parameters to which this authorization is limited
1202 CPHashA TPM2BDigest
1203 // a reference to a policy relating to the authorization – may be the Empty Buffer
1204 PolicyRef TPM2BNonce
1205 // time when authorization will expire, measured in seconds from the time
1206 // that nonceTPM was generated
1207 Expiration int32
1208 }
1209
1210 // Command implements the Command interface.
1211 func (PolicySecret) Command() TPMCC { return TPMCCPolicySecret }
1212
1213 // Execute executes the command and returns the response.
1214 func (cmd PolicySecret) Execute(t transport.TPM, s ...Session) (*PolicySecretResponse, error) {
1215 var rsp PolicySecretResponse
1216 if err := execute[PolicySecretResponse](t, cmd, &rsp, s...); err != nil {
1217 return nil, err
1218 }
1219 return &rsp, nil
1220 }
1221
1222 // Update implements the PolicyCommand interface.
1223 func (cmd PolicySecret) Update(policy *PolicyCalculator) error {
1224 return policyUpdate(policy, TPMCCPolicySecret, cmd.AuthHandle.KnownName().Buffer, cmd.PolicyRef.Buffer)
1225 }
1226
1227 // PolicySecretResponse is the response from TPM2_PolicySecret.
1228 type PolicySecretResponse struct {
1229 // implementation-specific time value used to indicate to the TPM when the ticket expires
1230 Timeout TPM2BTimeout
1231 // produced if the command succeeds and expiration in the command was non-zero
1232 PolicyTicket TPMTTKAuth
1233 }
1234
1235 // PolicyOr is the input to TPM2_PolicyOR.
1236 // See definition in Part 3, Commands, section 23.6.
1237 type PolicyOr struct {
1238 // handle for the policy session being extended
1239 PolicySession handle `gotpm:"handle"`
1240 // the list of hashes to check for a match
1241 PHashList TPMLDigest
1242 }
1243
1244 // Command implements the Command interface.
1245 func (PolicyOr) Command() TPMCC { return TPMCCPolicyOR }
1246
1247 // Execute executes the command and returns the response.
1248 func (cmd PolicyOr) Execute(t transport.TPM, s ...Session) (*PolicyOrResponse, error) {
1249 var rsp PolicyOrResponse
1250 err := execute[PolicyOrResponse](t, cmd, &rsp, s...)
1251 if err != nil {
1252 return nil, err
1253 }
1254 return &rsp, nil
1255 }
1256
1257 // Update implements the PolicyCommand interface.
1258 func (cmd PolicyOr) Update(policy *PolicyCalculator) error {
1259 policy.Reset()
1260 var digests bytes.Buffer
1261 for _, digest := range cmd.PHashList.Digests {
1262 digests.Write(digest.Buffer)
1263 }
1264 return policy.Update(TPMCCPolicyOR, digests.Bytes())
1265 }
1266
1267 // PolicyOrResponse is the response from TPM2_PolicyOr.
1268 type PolicyOrResponse struct{}
1269
1270 // PolicyPCR is the input to TPM2_PolicyPCR.
1271 // See definition in Part 3, Commands, section 23.7.
1272 type PolicyPCR struct {
1273 // handle for the policy session being extended
1274 PolicySession handle `gotpm:"handle"`
1275 // expected digest value of the selected PCR using the
1276 // hash algorithm of the session; may be zero length
1277 PcrDigest TPM2BDigest
1278 // the PCR to include in the check digest
1279 Pcrs TPMLPCRSelection
1280 }
1281
1282 // Command implements the Command interface.
1283 func (PolicyPCR) Command() TPMCC { return TPMCCPolicyPCR }
1284
1285 // Execute executes the command and returns the response.
1286 func (cmd PolicyPCR) Execute(t transport.TPM, s ...Session) (*PolicyPCRResponse, error) {
1287 var rsp PolicyPCRResponse
1288 err := execute[PolicyPCRResponse](t, cmd, &rsp, s...)
1289 if err != nil {
1290 return nil, err
1291 }
1292 return &rsp, nil
1293 }
1294
1295 // Update implements the PolicyCommand interface.
1296 func (cmd PolicyPCR) Update(policy *PolicyCalculator) error {
1297 return policy.Update(TPMCCPolicyPCR, cmd.Pcrs, cmd.PcrDigest.Buffer)
1298 }
1299
1300 // PolicyPCRResponse is the response from TPM2_PolicyPCR.
1301 type PolicyPCRResponse struct{}
1302
1303 // PolicyAuthValue is the input to TPM2_PolicyAuthValue.
1304 // See definition in Part 3, Commands, section 23.17.
1305 type PolicyAuthValue struct {
1306 // handle for the policy session being extended
1307 PolicySession handle `gotpm:"handle"`
1308 }
1309
1310 // Command implements the Command interface.
1311 func (PolicyAuthValue) Command() TPMCC { return TPMCCPolicyAuthValue }
1312
1313 // Execute executes the command and returns the response.
1314 func (cmd PolicyAuthValue) Execute(t transport.TPM, s ...Session) (*PolicyAuthValueResponse, error) {
1315 var rsp PolicyAuthValueResponse
1316 err := execute[PolicyAuthValueResponse](t, cmd, &rsp, s...)
1317 if err != nil {
1318 return nil, err
1319 }
1320 return &rsp, nil
1321 }
1322
1323 // Update implements the PolicyAuthValue interface.
1324 func (cmd PolicyAuthValue) Update(policy *PolicyCalculator) error {
1325 return policy.Update(TPMCCPolicyAuthValue)
1326 }
1327
1328 // PolicyAuthValueResponse is the response from TPM2_PolicyAuthValue.
1329 type PolicyAuthValueResponse struct{}
1330
1331 // PolicyDuplicationSelect is the input to TPM2_PolicyDuplicationSelect.
1332 // See definition in Part 3, Commands, section 23.15.
1333 type PolicyDuplicationSelect struct {
1334 // handle for the policy session being extended
1335 PolicySession handle `gotpm:"handle"`
1336 ObjectName TPM2BName
1337 NewParentName TPM2BName
1338 IncludeObject TPMIYesNo
1339 }
1340
1341 // Command implements the Command interface.
1342 func (PolicyDuplicationSelect) Command() TPMCC { return TPMCCPolicyDuplicationSelect }
1343
1344 // Execute executes the command and returns the response.
1345 func (cmd PolicyDuplicationSelect) Execute(t transport.TPM, s ...Session) (*PolicyDuplicationSelectResponse, error) {
1346 var rsp PolicyDuplicationSelectResponse
1347 err := execute[PolicyDuplicationSelectResponse](t, cmd, &rsp, s...)
1348 if err != nil {
1349 return nil, err
1350 }
1351 return &rsp, nil
1352 }
1353
1354 // Update implements the PolicyDuplicationSelect interface.
1355 func (cmd PolicyDuplicationSelect) Update(policy *PolicyCalculator) error {
1356 if cmd.IncludeObject {
1357 return policy.Update(TPMCCPolicyDuplicationSelect, cmd.ObjectName.Buffer, cmd.NewParentName.Buffer, cmd.IncludeObject)
1358 }
1359 return policy.Update(TPMCCPolicyDuplicationSelect, cmd.NewParentName.Buffer, cmd.IncludeObject)
1360 }
1361
1362 // PolicyDuplicationSelectResponse is the response from TPM2_PolicyDuplicationSelect.
1363 type PolicyDuplicationSelectResponse struct{}
1364
1365 // PolicyNV is the input to TPM2_PolicyNV.
1366 // See definition in Part 3, Commands, section 23.9.
1367 type PolicyNV struct {
1368 // handle indicating the source of the authorization value
1369 AuthHandle handle `gotpm:"handle,auth"`
1370 // the NV Index of the area to read
1371 NVIndex handle `gotpm:"handle"`
1372 // handle for the policy session being extended
1373 PolicySession handle `gotpm:"handle"`
1374 // the second operand
1375 OperandB TPM2BOperand
1376 // the octet offset in the NV Index for the start of operand A
1377 Offset uint16
1378 // the comparison to make
1379 Operation TPMEO
1380 }
1381
1382 // Command implements the Command interface.
1383 func (PolicyNV) Command() TPMCC { return TPMCCPolicyNV }
1384
1385 // Execute executes the command and returns the response.
1386 func (cmd PolicyNV) Execute(t transport.TPM, s ...Session) (*PolicyNVResponse, error) {
1387 var rsp PolicyNVResponse
1388 err := execute[PolicyNVResponse](t, cmd, &rsp, s...)
1389 if err != nil {
1390 return nil, err
1391 }
1392 return &rsp, nil
1393 }
1394
1395 // Update implements the PolicyCommand interface.
1396 func (cmd PolicyNV) Update(policy *PolicyCalculator) error {
1397 alg, err := policy.alg.Hash()
1398 if err != nil {
1399 return err
1400 }
1401 h := alg.New()
1402 h.Write(cmd.OperandB.Buffer)
1403 binary.Write(h, binary.BigEndian, cmd.Offset)
1404 binary.Write(h, binary.BigEndian, cmd.Operation)
1405 args := h.Sum(nil)
1406 return policy.Update(TPMCCPolicyNV, args, cmd.NVIndex.KnownName().Buffer)
1407 }
1408
1409 // PolicyNVResponse is the response from TPM2_PolicyPCR.
1410 type PolicyNVResponse struct{}
1411
1412 // PolicyCommandCode is the input to TPM2_PolicyCommandCode.
1413 // See definition in Part 3, Commands, section 23.11.
1414 type PolicyCommandCode struct {
1415 // handle for the policy session being extended
1416 PolicySession handle `gotpm:"handle"`
1417 // the allowed commandCode
1418 Code TPMCC
1419 }
1420
1421 // Command implements the Command interface.
1422 func (PolicyCommandCode) Command() TPMCC { return TPMCCPolicyCommandCode }
1423
1424 // Execute executes the command and returns the response.
1425 func (cmd PolicyCommandCode) Execute(t transport.TPM, s ...Session) (*PolicyCommandCodeResponse, error) {
1426 var rsp PolicyCommandCodeResponse
1427 err := execute[PolicyCommandCodeResponse](t, cmd, &rsp, s...)
1428 if err != nil {
1429 return nil, err
1430 }
1431 return &rsp, nil
1432 }
1433
1434 // Update implements the PolicyCommand interface.
1435 func (cmd PolicyCommandCode) Update(policy *PolicyCalculator) error {
1436 return policy.Update(TPMCCPolicyCommandCode, cmd.Code)
1437 }
1438
1439 // PolicyCommandCodeResponse is the response from TPM2_PolicyCommandCode.
1440 type PolicyCommandCodeResponse struct{}
1441
1442 // PolicyCPHash is the input to TPM2_PolicyCpHash.
1443 // See definition in Part 3, Commands, section 23.13.
1444 type PolicyCPHash struct {
1445 // handle for the policy session being extended
1446 PolicySession handle `gotpm:"handle"`
1447 // the cpHash added to the policy
1448 CPHashA TPM2BDigest
1449 }
1450
1451 // Command implements the Command interface.
1452 func (PolicyCPHash) Command() TPMCC { return TPMCCPolicyCpHash }
1453
1454 // Execute executes the command and returns the response.
1455 func (cmd PolicyCPHash) Execute(t transport.TPM, s ...Session) (*PolicyCPHashResponse, error) {
1456 var rsp PolicyCPHashResponse
1457 err := execute[PolicyCPHashResponse](t, cmd, &rsp, s...)
1458 if err != nil {
1459 return nil, err
1460 }
1461 return &rsp, nil
1462 }
1463
1464 // Update implements the PolicyCommand interface.
1465 func (cmd PolicyCPHash) Update(policy *PolicyCalculator) error {
1466 return policy.Update(TPMCCPolicyCpHash, cmd.CPHashA.Buffer)
1467 }
1468
1469 // PolicyCPHashResponse is the response from TPM2_PolicyCpHash.
1470 type PolicyCPHashResponse struct{}
1471
1472 // PolicyAuthorize is the input to TPM2_PolicySigned.
1473 // See definition in Part 3, Commands, section 23.16.
1474 type PolicyAuthorize struct {
1475 // handle for the policy session being extended
1476 PolicySession handle `gotpm:"handle"`
1477 // digest of the policy being approved
1478 ApprovedPolicy TPM2BDigest
1479 // a policy qualifier
1480 PolicyRef TPM2BDigest
1481 // Name of a key that can sign a policy addition
1482 KeySign TPM2BName
1483 // ticket validating that approvedPolicy and policyRef were signed by keySign
1484 CheckTicket TPMTTKVerified
1485 }
1486
1487 // Command implements the Command interface.
1488 func (PolicyAuthorize) Command() TPMCC { return TPMCCPolicyAuthorize }
1489
1490 // Execute executes the command and returns the response.
1491 func (cmd PolicyAuthorize) Execute(t transport.TPM, s ...Session) (*PolicyAuthorizeResponse, error) {
1492 var rsp PolicyAuthorizeResponse
1493 err := execute[PolicyAuthorizeResponse](t, cmd, &rsp, s...)
1494 if err != nil {
1495 return nil, err
1496 }
1497 return &rsp, nil
1498 }
1499
1500 // Update implements the PolicyCommand interface.
1501 func (cmd PolicyAuthorize) Update(policy *PolicyCalculator) error {
1502 return policyUpdate(policy, TPMCCPolicyAuthorize, cmd.KeySign.Buffer, cmd.PolicyRef.Buffer)
1503 }
1504
1505 // PolicyAuthorizeResponse is the response from TPM2_PolicyAuthorize.
1506 type PolicyAuthorizeResponse struct{}
1507
1508 // PolicyGetDigest is the input to TPM2_PolicyGetDigest.
1509 // See definition in Part 3, Commands, section 23.19.
1510 type PolicyGetDigest struct {
1511 // handle for the policy session
1512 PolicySession handle `gotpm:"handle"`
1513 }
1514
1515 // Command implements the Command interface.
1516 func (PolicyGetDigest) Command() TPMCC { return TPMCCPolicyGetDigest }
1517
1518 // Execute executes the command and returns the response.
1519 func (cmd PolicyGetDigest) Execute(t transport.TPM, s ...Session) (*PolicyGetDigestResponse, error) {
1520 var rsp PolicyGetDigestResponse
1521 if err := execute[PolicyGetDigestResponse](t, cmd, &rsp, s...); err != nil {
1522 return nil, err
1523 }
1524 return &rsp, nil
1525 }
1526
1527 // PolicyGetDigestResponse is the response from TPM2_PolicyGetDigest.
1528 type PolicyGetDigestResponse struct {
1529 // the current value of the policySession→policyDigest
1530 PolicyDigest TPM2BDigest
1531 }
1532
1533 // PolicyNVWritten is the input to TPM2_PolicyNvWritten.
1534 // See definition in Part 3, Commands, section 23.20.
1535 type PolicyNVWritten struct {
1536 // handle for the policy session being extended
1537 PolicySession handle `gotpm:"handle"`
1538 // YES if NV Index is required to have been written
1539 // NO if NV Index is required not to have been written
1540 WrittenSet TPMIYesNo
1541 }
1542
1543 // Command implements the Command interface.
1544 func (PolicyNVWritten) Command() TPMCC { return TPMCCPolicyNvWritten }
1545
1546 // Execute executes the command and returns the response.
1547 func (cmd PolicyNVWritten) Execute(t transport.TPM, s ...Session) (*PolicyNVWrittenResponse, error) {
1548 var rsp PolicyNVWrittenResponse
1549 if err := execute[PolicyNVWrittenResponse](t, cmd, &rsp, s...); err != nil {
1550 return nil, err
1551 }
1552 return &rsp, nil
1553 }
1554
1555 // Update implements the PolicyCommand interface.
1556 func (cmd PolicyNVWritten) Update(policy *PolicyCalculator) error {
1557 return policy.Update(TPMCCPolicyNvWritten, cmd.WrittenSet)
1558 }
1559
1560 // PolicyNVWrittenResponse is the response from TPM2_PolicyNvWritten.
1561 type PolicyNVWrittenResponse struct {
1562 }
1563
1564 // PolicyAuthorizeNV is the input to TPM2_PolicyAuthorizeNV.
1565 // See definition in Part 3, Commands, section 23.22.
1566 type PolicyAuthorizeNV struct {
1567 // handle indicating the source of the authorization value
1568 AuthHandle handle `gotpm:"handle,auth"`
1569 // the NV Index of the area to read
1570 NVIndex handle `gotpm:"handle"`
1571 // handle for the policy session being extended
1572 PolicySession handle `gotpm:"handle"`
1573 }
1574
1575 // Command implements the Command interface.
1576 func (PolicyAuthorizeNV) Command() TPMCC { return TPMCCPolicyAuthorizeNV }
1577
1578 // Execute executes the command and returns the response.
1579 func (cmd PolicyAuthorizeNV) Execute(t transport.TPM, s ...Session) (*PolicyAuthorizeNVResponse, error) {
1580 var rsp PolicyAuthorizeNVResponse
1581 err := execute[PolicyAuthorizeNVResponse](t, cmd, &rsp, s...)
1582 if err != nil {
1583 return nil, err
1584 }
1585 return &rsp, nil
1586 }
1587
1588 // Update implements the PolicyCommand interface.
1589 func (cmd PolicyAuthorizeNV) Update(policy *PolicyCalculator) error {
1590 policy.Reset()
1591 return policy.Update(TPMCCPolicyAuthorizeNV, cmd.NVIndex.KnownName().Buffer)
1592 }
1593
1594 // PolicyAuthorizeNVResponse is the response from TPM2_PolicyAuthorizeNV.
1595 type PolicyAuthorizeNVResponse struct{}
1596
1597 // CreatePrimary is the input to TPM2_CreatePrimary.
1598 // See definition in Part 3, Commands, section 24.1
1599 type CreatePrimary struct {
1600 // TPM_RH_ENDORSEMENT, TPM_RH_OWNER, TPM_RH_PLATFORM+{PP},
1601 // TPM_RH_NULL, TPM_RH_FW_ENDORSEMENT, TPM_RH_FW_OWNER
1602 // TPM_RH_FW_PLATFORM+{PP} or TPM_RH_FW_NULL
1603 PrimaryHandle handle `gotpm:"handle,auth"`
1604 // the sensitive data
1605 InSensitive TPM2BSensitiveCreate
1606 // the public template
1607 InPublic TPM2BPublic
1608 // data that will be included in the creation data for this
1609 // object to provide permanent, verifiable linkage between this
1610 // object and some object owner data
1611 OutsideInfo TPM2BData
1612 // PCR that will be used in creation data
1613 CreationPCR TPMLPCRSelection
1614 }
1615
1616 // Command implements the Command interface.
1617 func (CreatePrimary) Command() TPMCC { return TPMCCCreatePrimary }
1618
1619 // Execute executes the command and returns the response.
1620 func (cmd CreatePrimary) Execute(t transport.TPM, s ...Session) (*CreatePrimaryResponse, error) {
1621 var rsp CreatePrimaryResponse
1622 if err := execute[CreatePrimaryResponse](t, cmd, &rsp, s...); err != nil {
1623 return nil, err
1624 }
1625 return &rsp, nil
1626 }
1627
1628 // CreatePrimaryResponse is the response from TPM2_CreatePrimary.
1629 type CreatePrimaryResponse struct {
1630 // handle of type TPM_HT_TRANSIENT for created Primary Object
1631 ObjectHandle TPMHandle `gotpm:"handle"`
1632 // the public portion of the created object
1633 OutPublic TPM2BPublic
1634 // contains a TPMS_CREATION_DATA
1635 CreationData tpm2bCreationData
1636 // digest of creationData using nameAlg of outPublic
1637 CreationHash TPM2BDigest
1638 // ticket used by TPM2_CertifyCreation() to validate that the
1639 // creation data was produced by the TPM.
1640 CreationTicket TPMTTKCreation
1641 // the name of the created object
1642 Name TPM2BName
1643 }
1644
1645 // Clear is the input to TPM2_Clear.
1646 // See definition in Part 3, Commands, section 24.6
1647 type Clear struct {
1648 // TPM_RH_LOCKOUT or TPM_RH_PLATFORM+{PP}
1649 AuthHandle handle `gotpm:"handle,auth"`
1650 }
1651
1652 // Command implements the Command interface.
1653 func (Clear) Command() TPMCC { return TPMCCClear }
1654
1655 // Execute executes the command and returns the response.
1656 func (cmd Clear) Execute(t transport.TPM, s ...Session) (*ClearResponse, error) {
1657 var rsp ClearResponse
1658 err := execute[ClearResponse](t, cmd, &rsp, s...)
1659 if err != nil {
1660 return nil, err
1661 }
1662 return &rsp, nil
1663 }
1664
1665 // ClearResponse is the response from TPM2_Clear.
1666 type ClearResponse struct{}
1667
1668 // HierarchyChangeAuth is the input to TPM2_HierarchyChangeAuth.
1669 // See definition in Part 3, Commands, section 24.8
1670 type HierarchyChangeAuth struct {
1671 // TPM_RH_ENDORSEMENT, TPM_RH_LOCKOUT, TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
1672 AuthHandle handle `gotpm:"handle,auth"`
1673 // new authorization value
1674 NewAuth TPM2BAuth
1675 }
1676
1677 // Command implements the Command interface.
1678 func (HierarchyChangeAuth) Command() TPMCC { return TPMCCHierarchyChanegAuth }
1679
1680 // Execute executes the command and returns the response.
1681 func (cmd HierarchyChangeAuth) Execute(t transport.TPM, s ...Session) (*HierarchyChangeAuthResponse, error) {
1682 var rsp HierarchyChangeAuthResponse
1683 if err := execute[HierarchyChangeAuthResponse](t, cmd, &rsp, s...); err != nil {
1684 return nil, err
1685 }
1686 return &rsp, nil
1687 }
1688
1689 // HierarchyChangeAuthResponse is the response from TPM2_HierarchyChangeAuth.
1690 type HierarchyChangeAuthResponse struct{}
1691
1692 // ContextSave is the input to TPM2_ContextSave.
1693 // See definition in Part 3, Commands, section 28.2
1694 type ContextSave struct {
1695 // handle of the resource to save
1696 SaveHandle TPMIDHContext
1697 }
1698
1699 // Command implements the Command interface.
1700 func (ContextSave) Command() TPMCC { return TPMCCContextSave }
1701
1702 // Execute executes the command and returns the response.
1703 func (cmd ContextSave) Execute(t transport.TPM, s ...Session) (*ContextSaveResponse, error) {
1704 var rsp ContextSaveResponse
1705 if err := execute[ContextSaveResponse](t, cmd, &rsp, s...); err != nil {
1706 return nil, err
1707 }
1708 return &rsp, nil
1709 }
1710
1711 // ContextSaveResponse is the response from TPM2_ContextSave.
1712 type ContextSaveResponse struct {
1713 Context TPMSContext
1714 }
1715
1716 // ContextLoad is the input to TPM2_ContextLoad.
1717 // See definition in Part 3, Commands, section 28.3
1718 type ContextLoad struct {
1719 // the context blob
1720 Context TPMSContext
1721 }
1722
1723 // Command implements the Command interface.
1724 func (ContextLoad) Command() TPMCC { return TPMCCContextLoad }
1725
1726 // Execute executes the command and returns the response.
1727 func (cmd ContextLoad) Execute(t transport.TPM, s ...Session) (*ContextLoadResponse, error) {
1728 var rsp ContextLoadResponse
1729 if err := execute[ContextLoadResponse](t, cmd, &rsp, s...); err != nil {
1730 return nil, err
1731 }
1732 return &rsp, nil
1733 }
1734
1735 // ContextLoadResponse is the response from TPM2_ContextLoad.
1736 type ContextLoadResponse struct {
1737 // the handle assigned to the resource after it has been successfully loaded
1738 LoadedHandle TPMIDHContext
1739 }
1740
1741 // FlushContext is the input to TPM2_FlushContext.
1742 // See definition in Part 3, Commands, section 28.4
1743 type FlushContext struct {
1744 // the handle of the item to flush
1745 FlushHandle handle `gotpm:"handle"`
1746 }
1747
1748 // Command implements the Command interface.
1749 func (FlushContext) Command() TPMCC { return TPMCCFlushContext }
1750
1751 // Execute executes the command and returns the response.
1752 func (cmd FlushContext) Execute(t transport.TPM, s ...Session) (*FlushContextResponse, error) {
1753 var rsp FlushContextResponse
1754 err := execute[FlushContextResponse](t, cmd, &rsp, s...)
1755 if err != nil {
1756 return nil, err
1757 }
1758 return &rsp, nil
1759 }
1760
1761 // FlushContextResponse is the response from TPM2_FlushContext.
1762 type FlushContextResponse struct{}
1763
1764 // EvictControl is the input to TPM2_EvictControl.
1765 // See definition in Part 3, Commands, section 28.5
1766 type EvictControl struct {
1767 // TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
1768 Auth handle `gotpm:"handle,auth"`
1769 ObjectHandle handle `gotpm:"handle"`
1770 PersistentHandle TPMIDHPersistent
1771 }
1772
1773 // EvictControlResponse is the response from TPM2_EvictControl.
1774 type EvictControlResponse struct{}
1775
1776 // Command implements the Command interface.
1777 func (EvictControl) Command() TPMCC { return TPMCCEvictControl }
1778
1779 // Execute executes the command and returns the response.
1780 func (cmd EvictControl) Execute(t transport.TPM, s ...Session) (*EvictControlResponse, error) {
1781 var rsp EvictControlResponse
1782 if err := execute[EvictControlResponse](t, cmd, &rsp, s...); err != nil {
1783 return nil, err
1784 }
1785 return &rsp, nil
1786 }
1787
1788 // Duplicate is the input to TPM2_Duplicate.
1789 // See definition in Part 3, Commands, section 13.1
1790 type Duplicate struct {
1791 // ObjectHandle is the handle of the object to dupliate.
1792 ObjectHandle handle `gotpm:"handle,auth"`
1793
1794 // NewParentHandle is the handle of the new parent.
1795 NewParentHandle handle `gotpm:"handle"`
1796
1797 // EncryptionKeyIn is the optional symmetric encryption key used as the
1798 // inner wrapper. If SymmetricAlg is TPM_ALG_NULL, then this parameter
1799 // shall be the Empty Buffer.
1800 EncryptionKeyIn TPM2BData
1801
1802 // Definition of the symmetric algorithm to use for the inner wrapper.
1803 // It may be TPM_ALG_NULL if no inner wrapper is applied.
1804 Symmetric TPMTSymDef
1805 }
1806
1807 // DuplicateResponse is the response from TPM2_Duplicate.
1808 type DuplicateResponse struct {
1809 // EncryptionKeyOut is the symmetric encryption key used as the
1810 // inner wrapper. If SymmetricAlg is TPM_ALG_NULL, this value
1811 // shall be the Empty Buffer.
1812 EncryptionKeyOut TPM2BData
1813
1814 // Duplicate is the private area of the object. It may be encrypted by
1815 // EncryptionKeyIn and may be doubly encrypted.
1816 Duplicate TPM2BPrivate
1817
1818 // OutSymSeed is the seed protected by the asymmetric algorithms of new
1819 // parent.
1820 OutSymSeed TPM2BEncryptedSecret
1821 }
1822
1823 // Command implements the Command interface.
1824 func (Duplicate) Command() TPMCC { return TPMCCDuplicate }
1825
1826 // Execute executes the command and returns the response.
1827 func (cmd Duplicate) Execute(t transport.TPM, s ...Session) (*DuplicateResponse, error) {
1828 var rsp DuplicateResponse
1829 if err := execute[DuplicateResponse](t, cmd, &rsp, s...); err != nil {
1830 return nil, err
1831 }
1832 return &rsp, nil
1833 }
1834
1835 // Import is the input to TPM2_Import.
1836 // See definition in Part 3, Commands, section 13.3
1837 type Import struct {
1838 // handle of parent for new object
1839 ParentHandle handle `gotpm:"handle,auth"`
1840
1841 // The optional symmetric encryption key used as the inner wrapper for duplicate
1842 // If SymmetricAlg is TPM_ALG_NULL, then this parametert shall be the Empty Buffer
1843 EncryptionKey TPM2BData
1844
1845 // The public area of the object to be imported
1846 ObjectPublic TPM2BPublic
1847
1848 // The symmetrically encrypted duplicate object that may contain an inner
1849 // symmetric wrapper
1850 Duplicate TPM2BPrivate
1851
1852 // The seed for the symmetric key and HMAC key
1853 InSymSeed TPM2BEncryptedSecret
1854
1855 // Definition of the symmetric algorithm to use for the inner wrapper
1856 Symmetric TPMTSymDef
1857 }
1858
1859 // ImportResponse is the response from TPM2_Import.
1860 type ImportResponse struct {
1861 // the private portion of the object
1862 OutPrivate TPM2BPrivate
1863 }
1864
1865 // Command implements the Command interface.
1866 func (Import) Command() TPMCC { return TPMCCImport }
1867
1868 // Execute executes the command and returns the response.
1869 func (cmd Import) Execute(t transport.TPM, s ...Session) (*ImportResponse, error) {
1870 var rsp ImportResponse
1871 if err := execute[ImportResponse](t, cmd, &rsp, s...); err != nil {
1872 return nil, err
1873 }
1874 return &rsp, nil
1875 }
1876
1877 // ReadClock is the input to TPM2_ReadClock.
1878 // See definition in Part 3, Commands, section 29.1
1879 type ReadClock struct{}
1880
1881 // Command implements the Command interface.
1882 func (ReadClock) Command() TPMCC { return TPMCCReadClock }
1883
1884 // Execute executes the command and returns the response.
1885 func (cmd ReadClock) Execute(t transport.TPM, s ...Session) (*ReadClockResponse, error) {
1886 var rsp ReadClockResponse
1887 if err := execute[ReadClockResponse](t, cmd, &rsp, s...); err != nil {
1888 return nil, err
1889 }
1890 return &rsp, nil
1891 }
1892
1893 // ReadClockResponse is the response from TPM2_ReadClock.
1894 type ReadClockResponse struct {
1895 CurrentTime TPMSTimeInfo
1896 }
1897
1898 // GetCapability is the input to TPM2_GetCapability.
1899 // See definition in Part 3, Commands, section 30.2
1900 type GetCapability struct {
1901 // group selection; determines the format of the response
1902 Capability TPMCap
1903 // further definition of information
1904 Property uint32
1905 // number of properties of the indicated type to return
1906 PropertyCount uint32
1907 }
1908
1909 // Command implements the Command interface.
1910 func (GetCapability) Command() TPMCC { return TPMCCGetCapability }
1911
1912 // Execute executes the command and returns the response.
1913 func (cmd GetCapability) Execute(t transport.TPM, s ...Session) (*GetCapabilityResponse, error) {
1914 var rsp GetCapabilityResponse
1915 if err := execute[GetCapabilityResponse](t, cmd, &rsp, s...); err != nil {
1916 return nil, err
1917 }
1918 return &rsp, nil
1919 }
1920
1921 // GetCapabilityResponse is the response from TPM2_GetCapability.
1922 type GetCapabilityResponse struct {
1923 // flag to indicate if there are more values of this type
1924 MoreData TPMIYesNo
1925 // the capability data
1926 CapabilityData TPMSCapabilityData
1927 }
1928
1929 // TestParms is the input to TPM2_TestParms.
1930 // See definition in Part 3, Commands, section 30.3
1931 type TestParms struct {
1932 // Algorithms parameters to be validates
1933 Parameters TPMTPublicParms
1934 }
1935
1936 // Command implements the Command interface.
1937 func (TestParms) Command() TPMCC { return TPMCCTestParms }
1938
1939 // Execute executes the command and returns the response.
1940 func (cmd TestParms) Execute(t transport.TPM, s ...Session) (*TestParmsResponse, error) {
1941 var rsp TestParmsResponse
1942 if err := execute[TestParmsResponse](t, cmd, &rsp, s...); err != nil {
1943 return nil, err
1944 }
1945 return &rsp, nil
1946 }
1947
1948 // TestParmsResponse is the response from TPM2_TestParms.
1949 type TestParmsResponse struct{}
1950
1951 // NVDefineSpace is the input to TPM2_NV_DefineSpace.
1952 // See definition in Part 3, Commands, section 31.3.
1953 type NVDefineSpace struct {
1954 // TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
1955 AuthHandle handle `gotpm:"handle,auth"`
1956 // the authorization value
1957 Auth TPM2BAuth
1958 // the public parameters of the NV area
1959 PublicInfo TPM2BNVPublic
1960 }
1961
1962 // Command implements the Command interface.
1963 func (NVDefineSpace) Command() TPMCC { return TPMCCNVDefineSpace }
1964
1965 // Execute executes the command and returns the response.
1966 func (cmd NVDefineSpace) Execute(t transport.TPM, s ...Session) (*NVDefineSpaceResponse, error) {
1967 var rsp NVDefineSpaceResponse
1968 err := execute[NVDefineSpaceResponse](t, cmd, &rsp, s...)
1969 if err != nil {
1970 return nil, err
1971 }
1972 return &rsp, nil
1973 }
1974
1975 // NVDefineSpaceResponse is the response from TPM2_NV_DefineSpace.
1976 type NVDefineSpaceResponse struct{}
1977
1978 // NVUndefineSpace is the input to TPM2_NV_UndefineSpace.
1979 // See definition in Part 3, Commands, section 31.4.
1980 type NVUndefineSpace struct {
1981 // TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
1982 AuthHandle handle `gotpm:"handle,auth"`
1983 // the NV Index to remove from NV space
1984 NVIndex handle `gotpm:"handle"`
1985 }
1986
1987 // Command implements the Command interface.
1988 func (NVUndefineSpace) Command() TPMCC { return TPMCCNVUndefineSpace }
1989
1990 // Execute executes the command and returns the response.
1991 func (cmd NVUndefineSpace) Execute(t transport.TPM, s ...Session) (*NVUndefineSpaceResponse, error) {
1992 var rsp NVUndefineSpaceResponse
1993 err := execute[NVUndefineSpaceResponse](t, cmd, &rsp, s...)
1994 if err != nil {
1995 return nil, err
1996 }
1997 return &rsp, nil
1998 }
1999
2000 // NVUndefineSpaceResponse is the response from TPM2_NV_UndefineSpace.
2001 type NVUndefineSpaceResponse struct{}
2002
2003 // NVUndefineSpaceSpecial is the input to TPM2_NV_UndefineSpaceSpecial.
2004 // See definition in Part 3, Commands, section 31.5.
2005 type NVUndefineSpaceSpecial struct {
2006 // Index to be deleted
2007 NVIndex handle `gotpm:"handle,auth"`
2008 // TPM_RH_PLATFORM+{PP}
2009 Platform handle `gotpm:"handle,auth"`
2010 }
2011
2012 // Command implements the Command interface.
2013 func (NVUndefineSpaceSpecial) Command() TPMCC { return TPMCCNVUndefineSpaceSpecial }
2014
2015 // Execute executes the command and returns the response.
2016 func (cmd NVUndefineSpaceSpecial) Execute(t transport.TPM, s ...Session) (*NVUndefineSpaceSpecialResponse, error) {
2017 var rsp NVUndefineSpaceSpecialResponse
2018 err := execute[NVUndefineSpaceSpecialResponse](t, cmd, &rsp, s...)
2019 if err != nil {
2020 return nil, err
2021 }
2022 return &rsp, nil
2023 }
2024
2025 // NVUndefineSpaceSpecialResponse is the response from TPM2_NV_UndefineSpaceSpecial.
2026 type NVUndefineSpaceSpecialResponse struct{}
2027
2028 // NVReadPublic is the input to TPM2_NV_ReadPublic.
2029 // See definition in Part 3, Commands, section 31.6.
2030 type NVReadPublic struct {
2031 // the NV index
2032 NVIndex handle `gotpm:"handle"`
2033 }
2034
2035 // Command implements the Command interface.
2036 func (NVReadPublic) Command() TPMCC { return TPMCCNVReadPublic }
2037
2038 // Execute executes the command and returns the response.
2039 func (cmd NVReadPublic) Execute(t transport.TPM, s ...Session) (*NVReadPublicResponse, error) {
2040 var rsp NVReadPublicResponse
2041 if err := execute[NVReadPublicResponse](t, cmd, &rsp, s...); err != nil {
2042 return nil, err
2043 }
2044 return &rsp, nil
2045 }
2046
2047 // NVReadPublicResponse is the response from TPM2_NV_ReadPublic.
2048 type NVReadPublicResponse struct {
2049 NVPublic TPM2BNVPublic
2050 NVName TPM2BName
2051 }
2052
2053 // NVWrite is the input to TPM2_NV_Write.
2054 // See definition in Part 3, Commands, section 31.7.
2055 type NVWrite struct {
2056 // handle indicating the source of the authorization value
2057 AuthHandle handle `gotpm:"handle,auth"`
2058 // the NV index of the area to write
2059 NVIndex handle `gotpm:"handle"`
2060 // the data to write
2061 Data TPM2BMaxNVBuffer
2062 // the octet offset into the NV Area
2063 Offset uint16
2064 }
2065
2066 // Command implements the Command interface.
2067 func (NVWrite) Command() TPMCC { return TPMCCNVWrite }
2068
2069 // Execute executes the command and returns the response.
2070 func (cmd NVWrite) Execute(t transport.TPM, s ...Session) (*NVWriteResponse, error) {
2071 var rsp NVWriteResponse
2072 err := execute[NVWriteResponse](t, cmd, &rsp, s...)
2073 if err != nil {
2074 return nil, err
2075 }
2076 return &rsp, nil
2077 }
2078
2079 // NVWriteResponse is the response from TPM2_NV_Write.
2080 type NVWriteResponse struct{}
2081
2082 // NVIncrement is the input to TPM2_NV_Increment.
2083 // See definition in Part 3, Commands, section 31.8.
2084 type NVIncrement struct {
2085 // handle indicating the source of the authorization value
2086 AuthHandle handle `gotpm:"handle,auth"`
2087 // the NV index of the area to write
2088 NVIndex handle `gotpm:"handle"`
2089 }
2090
2091 // Command implements the Command interface.
2092 func (NVIncrement) Command() TPMCC { return TPMCCNVIncrement }
2093
2094 // Execute executes the command and returns the response.
2095 func (cmd NVIncrement) Execute(t transport.TPM, s ...Session) (*NVIncrementResponse, error) {
2096 var rsp NVIncrementResponse
2097 err := execute[NVIncrementResponse](t, cmd, &rsp, s...)
2098 if err != nil {
2099 return nil, err
2100 }
2101 return &rsp, nil
2102 }
2103
2104 // NVIncrementResponse is the response from TPM2_NV_Increment.
2105 type NVIncrementResponse struct{}
2106
2107 // NVWriteLock is the input to TPM2_NV_WriteLock.
2108 // See definition in Part 3, Commands, section 31.11.
2109 type NVWriteLock struct {
2110 // handle indicating the source of the authorization value
2111 AuthHandle handle `gotpm:"handle,auth"`
2112 // the NV index of the area to lock
2113 NVIndex handle `gotpm:"handle"`
2114 }
2115
2116 // Command implements the Command interface.
2117 func (NVWriteLock) Command() TPMCC { return TPMCCNVWriteLock }
2118
2119 // Execute executes the command and returns the response.
2120 func (cmd NVWriteLock) Execute(t transport.TPM, s ...Session) (*NVWriteLockResponse, error) {
2121 var rsp NVWriteLockResponse
2122 err := execute[NVWriteLockResponse](t, cmd, &rsp, s...)
2123 if err != nil {
2124 return nil, err
2125 }
2126 return &rsp, nil
2127 }
2128
2129 // NVWriteLockResponse is the response from TPM2_NV_WriteLock.
2130 type NVWriteLockResponse struct{}
2131
2132 // NVRead is the input to TPM2_NV_Read.
2133 // See definition in Part 3, Commands, section 31.13.
2134 type NVRead struct {
2135 // handle indicating the source of the authorization value
2136 AuthHandle handle `gotpm:"handle,auth"`
2137 // the NV index to read
2138 NVIndex handle `gotpm:"handle"`
2139 // number of octets to read
2140 Size uint16
2141 // octet offset into the NV area
2142 Offset uint16
2143 }
2144
2145 // Command implements the Command interface.
2146 func (NVRead) Command() TPMCC { return TPMCCNVRead }
2147
2148 // Execute executes the command and returns the response.
2149 func (cmd NVRead) Execute(t transport.TPM, s ...Session) (*NVReadResponse, error) {
2150 var rsp NVReadResponse
2151 if err := execute[NVReadResponse](t, cmd, &rsp, s...); err != nil {
2152 return nil, err
2153 }
2154 return &rsp, nil
2155 }
2156
2157 // NVReadResponse is the response from TPM2_NV_Read.
2158 type NVReadResponse struct {
2159 // the data read
2160 Data TPM2BMaxNVBuffer
2161 }
2162
2163 // NVReadLock is the input to TPM2_NV_NVReadLock.
2164 // See definition in Part 3, Commands, section 31.14.
2165 type NVReadLock struct {
2166 // handle indicating the source of the authorization value
2167 AuthHandle handle `gotpm:"handle,auth"`
2168 // the NV index of the area to lock
2169 NVIndex handle `gotpm:"handle"`
2170 }
2171
2172 // Command implements the Command interface.
2173 func (NVReadLock) Command() TPMCC { return TPMCCNVReadLock }
2174
2175 // Execute executes the command and returns the response.
2176 func (cmd NVReadLock) Execute(t transport.TPM, s ...Session) (*NVReadLockResponse, error) {
2177 var rsp NVReadLockResponse
2178 err := execute[NVReadLockResponse](t, cmd, &rsp, s...)
2179 if err != nil {
2180 return nil, err
2181 }
2182 return &rsp, nil
2183 }
2184
2185 // NVReadLockResponse is the response from TPM2_NV_ReadLock.
2186 type NVReadLockResponse struct{}
2187
2188 // NVCertify is the input to TPM2_NV_Certify.
2189 // See definition in Part 3, Commands, section 31.16.
2190 type NVCertify struct {
2191 // handle of the key used to sign the attestation structure
2192 SignHandle handle `gotpm:"handle,auth"`
2193 // handle indicating the source of the authorization value
2194 AuthHandle handle `gotpm:"handle,auth"`
2195 // Index for the area to be certified
2196 NVIndex handle `gotpm:"handle"`
2197 // user-provided qualifying data
2198 QualifyingData TPM2BData
2199 // signing scheme to use if the scheme for signHandle is TPM_ALG_NULL
2200 InScheme TPMTSigScheme `gotpm:"nullable"`
2201 // number of octets to certify
2202 Size uint16
2203 // octet offset into the NV area
2204 Offset uint16
2205 }
2206
2207 // Command implements the Command interface.
2208 func (NVCertify) Command() TPMCC { return TPMCCNVCertify }
2209
2210 // Execute executes the command and returns the response.
2211 func (cmd NVCertify) Execute(t transport.TPM, s ...Session) (*NVCertifyResponse, error) {
2212 var rsp NVCertifyResponse
2213 if err := execute[NVCertifyResponse](t, cmd, &rsp, s...); err != nil {
2214 return nil, err
2215 }
2216 return &rsp, nil
2217 }
2218
2219 // NVCertifyResponse is the response from TPM2_NV_Read.
2220 type NVCertifyResponse struct {
2221 // the structure that was signed
2222 CertifyInfo TPM2BAttest
2223 // the asymmetric signature over certifyInfo using the key referenced by signHandle
2224 Signature TPMTSignature
2225 }
2226
2227 // GetTime is the input to TPM2_GetTime.
2228 // See definition in Part 3, Commands, section 18.7.
2229 type GetTime struct {
2230 // handle of the privacy administrator (Must be the value TPM_RH_ENDORSEMENT or command will fail)
2231 PrivacyAdminHandle TPMIRHEndorsement `gotpm:"handle,auth"`
2232 // the keyHandle identifier of a loaded key that can perform digital signatures
2233 SignHandle handle `gotpm:"handle,auth"`
2234 // data to "tick stamp"
2235 QualifyingData TPM2BData
2236 // signing scheme to use if the scheme for signHandle is TPM_ALG_NULL
2237 InScheme TPMTSigScheme `gotpm:"nullable"`
2238 }
2239
2240 // Command implements the Command interface.
2241 func (GetTime) Command() TPMCC { return TPMCCGetTime }
2242
2243 // Execute executes the command and returns the response.
2244 func (cmd GetTime) Execute(t transport.TPM, s ...Session) (*GetTimeResponse, error) {
2245 var rsp GetTimeResponse
2246 if err := execute[GetTimeResponse](t, cmd, &rsp, s...); err != nil {
2247 return nil, err
2248 }
2249 return &rsp, nil
2250 }
2251
2252 // GetTimeResponse is the response from TPM2_GetTime.
2253 type GetTimeResponse struct {
2254 // standard TPM-generated attestation block
2255 TimeInfo TPM2BAttest
2256 // the signature over timeInfo
2257 Signature TPMTSignature
2258 }