-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathstructures.go
3200 lines (2896 loc) · 105 KB
/
structures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Package tpm2 defines all the TPM 2.0 structures together to avoid import cycles
package tpm2
import (
"bytes"
"crypto"
"crypto/ecdh"
"crypto/elliptic"
"encoding/binary"
"reflect"
// Register the relevant hash implementations.
_ "crypto/sha1"
_ "crypto/sha256"
_ "crypto/sha512"
"fmt"
)
// TPMCmdHeader is the header structure in front of any TPM command.
// It is described in Part 1, Architecture.
type TPMCmdHeader struct {
marshalByReflection
Tag TPMISTCommandTag
Length uint32
CommandCode TPMCC
}
// TPMRspHeader is the header structure in front of any TPM response.
// It is described in Part 1, Architecture.
type TPMRspHeader struct {
marshalByReflection
Tag TPMISTCommandTag
Length uint32
ResponseCode TPMRC
}
// TPMAlgorithmID represents a TPM_ALGORITHM_ID
// this is the 1.2 compatible form of the TPM_ALG_ID
// See definition in Part 2, Structures, section 5.3.
type TPMAlgorithmID uint32
// TPMModifierIndicator represents a TPM_MODIFIER_INDICATOR.
// See definition in Part 2, Structures, section 5.3.
type TPMModifierIndicator uint32
// TPMAuthorizationSize represents a TPM_AUTHORIZATION_SIZE.
// the authorizationSize parameter in a command
// See definition in Part 2, Structures, section 5.3.
type TPMAuthorizationSize uint32
// TPMParameterSize represents a TPM_PARAMETER_SIZE.
// the parameterSize parameter in a command
// See definition in Part 2, Structures, section 5.3.
type TPMParameterSize uint32
// TPMKeySize represents a TPM_KEY_SIZE.
// a key size in octets
// See definition in Part 2, Structures, section 5.3.
type TPMKeySize uint16
// TPMKeyBits represents a TPM_KEY_BITS.
// a key size in bits
// See definition in Part 2, Structures, section 5.3.
type TPMKeyBits uint16
// TPMGenerated represents a TPM_GENERATED.
// See definition in Part 2: Structures, section 6.2.
type TPMGenerated uint32
// Generated values come from Part 2: Structures, section 6.2.
const (
TPMGeneratedValue TPMGenerated = 0xff544347
)
// Check verifies that a TPMGenerated value is correct, and returns an error
// otherwise.
func (g TPMGenerated) Check() error {
if g != TPMGeneratedValue {
return fmt.Errorf("TPM_GENERATED value should be 0x%x, was 0x%x", TPMGeneratedValue, g)
}
return nil
}
// Curve returns the elliptic.Curve associated with a TPMECCCurve.
func (c TPMECCCurve) Curve() (elliptic.Curve, error) {
switch c {
case TPMECCNistP224:
return elliptic.P224(), nil
case TPMECCNistP256:
return elliptic.P256(), nil
case TPMECCNistP384:
return elliptic.P384(), nil
case TPMECCNistP521:
return elliptic.P521(), nil
default:
return nil, fmt.Errorf("unsupported ECC curve: %v", c)
}
}
// ECDHCurve returns the ecdh.Curve associated with a TPMECCCurve.
func (c TPMECCCurve) ECDHCurve() (ecdh.Curve, error) {
switch c {
case TPMECCNistP256:
return ecdh.P256(), nil
case TPMECCNistP384:
return ecdh.P384(), nil
case TPMECCNistP521:
return ecdh.P521(), nil
default:
return nil, fmt.Errorf("unsupported ECC curve: %v", c)
}
}
// HandleValue returns the handle value. This behavior is intended to satisfy
// an interface that can be implemented by other, more complex types as well.
func (h TPMHandle) HandleValue() uint32 {
return uint32(h)
}
// KnownName returns the TPM Name associated with the handle, if it can be known
// based only on the handle. This depends upon the value of the handle:
// only PCR, session, and permanent values have known constant Names.
// See definition in part 1: Architecture, section 16.
func (h TPMHandle) KnownName() *TPM2BName {
switch (TPMHT)(h >> 24) {
case TPMHTPCR, TPMHTHMACSession, TPMHTPolicySession, TPMHTPermanent:
result := make([]byte, 4)
binary.BigEndian.PutUint32(result, h.HandleValue())
return &TPM2BName{Buffer: result}
case TPMHTTransient:
// The Name of a sequence object is an Empty Buffer
// See part 1: Architecture, section 32.4.5
if h == TPMIDHSavedSequence {
return &TPM2BName{
Buffer: []byte{},
}
}
}
return nil
}
// TPMAAlgorithm represents a TPMA_ALGORITHM.
// See definition in Part 2: Structures, section 8.2.
type TPMAAlgorithm struct {
bitfield32
marshalByReflection
// SET (1): an asymmetric algorithm with public and private portions
// CLEAR (0): not an asymmetric algorithm
Asymmetric bool `gotpm:"bit=0"`
// SET (1): a symmetric block cipher
// CLEAR (0): not a symmetric block cipher
Symmetric bool `gotpm:"bit=1"`
// SET (1): a hash algorithm
// CLEAR (0): not a hash algorithm
Hash bool `gotpm:"bit=2"`
// SET (1): an algorithm that may be used as an object type
// CLEAR (0): an algorithm that is not used as an object type
Object bool `gotpm:"bit=3"`
// SET (1): a signing algorithm. The setting of asymmetric,
// symmetric, and hash will indicate the type of signing algorithm.
// CLEAR (0): not a signing algorithm
Signing bool `gotpm:"bit=8"`
// SET (1): an encryption/decryption algorithm. The setting of
// asymmetric, symmetric, and hash will indicate the type of
// encryption/decryption algorithm.
// CLEAR (0): not an encryption/decryption algorithm
Encrypting bool `gotpm:"bit=9"`
// SET (1): a method such as a key derivative function (KDF)
// CLEAR (0): not a method
Method bool `gotpm:"bit=10"`
}
// TPMAObject represents a TPMA_OBJECT.
// See definition in Part 2: Structures, section 8.3.2.
type TPMAObject struct {
bitfield32
marshalByReflection
// SET (1): The hierarchy of the object, as indicated by its
// Qualified Name, may not change.
// CLEAR (0): The hierarchy of the object may change as a result
// of this object or an ancestor key being duplicated for use in
// another hierarchy.
FixedTPM bool `gotpm:"bit=1"`
// SET (1): Previously saved contexts of this object may not be
// loaded after Startup(CLEAR).
// CLEAR (0): Saved contexts of this object may be used after a
// Shutdown(STATE) and subsequent Startup().
STClear bool `gotpm:"bit=2"`
// SET (1): The parent of the object may not change.
// CLEAR (0): The parent of the object may change as the result of
// a TPM2_Duplicate() of the object.
FixedParent bool `gotpm:"bit=4"`
// SET (1): Indicates that, when the object was created with
// TPM2_Create() or TPM2_CreatePrimary(), the TPM generated all of
// the sensitive data other than the authValue.
// CLEAR (0): A portion of the sensitive data, other than the
// authValue, was provided by the caller.
SensitiveDataOrigin bool `gotpm:"bit=5"`
// SET (1): Approval of USER role actions with this object may be
// with an HMAC session or with a password using the authValue of
// the object or a policy session.
// CLEAR (0): Approval of USER role actions with this object may
// only be done with a policy session.
UserWithAuth bool `gotpm:"bit=6"`
// SET (1): Approval of ADMIN role actions with this object may
// only be done with a policy session.
// CLEAR (0): Approval of ADMIN role actions with this object may
// be with an HMAC session or with a password using the authValue
// of the object or a policy session.
AdminWithPolicy bool `gotpm:"bit=7"`
// SET (1): The object is not subject to dictionary attack
// protections.
// CLEAR (0): The object is subject to dictionary attack
// protections.
NoDA bool `gotpm:"bit=10"`
// SET (1): If the object is duplicated, then symmetricAlg shall
// not be TPM_ALG_NULL and newParentHandle shall not be
// TPM_RH_NULL.
// CLEAR (0): The object may be duplicated without an inner
// wrapper on the private portion of the object and the new parent
// may be TPM_RH_NULL.
EncryptedDuplication bool `gotpm:"bit=11"`
// SET (1): Key usage is restricted to manipulate structures of
// known format; the parent of this key shall have restricted SET.
// CLEAR (0): Key usage is not restricted to use on special
// formats.
Restricted bool `gotpm:"bit=16"`
// SET (1): The private portion of the key may be used to decrypt.
// CLEAR (0): The private portion of the key may not be used to
// decrypt.
Decrypt bool `gotpm:"bit=17"`
// SET (1): For a symmetric cipher object, the private portion of
// the key may be used to encrypt. For other objects, the private
// portion of the key may be used to sign.
// CLEAR (0): The private portion of the key may not be used to
// sign or encrypt.
SignEncrypt bool `gotpm:"bit=18"`
// SET (1): An asymmetric key that may not be used to sign with
// TPM2_Sign() CLEAR (0): A key that may be used with TPM2_Sign()
// if sign is SET
// NOTE: This attribute only has significance if sign is SET.
X509Sign bool `gotpm:"bit=19"`
}
// TPMASession represents a TPMA_SESSION.
// See definition in Part 2: Structures, section 8.4.
type TPMASession struct {
bitfield8
marshalByReflection
// SET (1): In a command, this setting indicates that the session
// is to remain active after successful completion of the command.
// In a response, it indicates that the session is still active.
// If SET in the command, this attribute shall be SET in the response.
// CLEAR (0): In a command, this setting indicates that the TPM should
// close the session and flush any related context when the command
// completes successfully. In a response, it indicates that the
// session is closed and the context is no longer active.
// This attribute has no meaning for a password authorization and the
// TPM will allow any setting of the attribute in the command and SET
// the attribute in the response.
ContinueSession bool `gotpm:"bit=0"`
// SET (1): In a command, this setting indicates that the command
// should only be executed if the session is exclusive at the start of
// the command. In a response, it indicates that the session is
// exclusive. This setting is only allowed if the audit attribute is
// SET (TPM_RC_ATTRIBUTES).
// CLEAR (0): In a command, indicates that the session need not be
// exclusive at the start of the command. In a response, indicates that
// the session is not exclusive.
AuditExclusive bool `gotpm:"bit=1"`
// SET (1): In a command, this setting indicates that the audit digest
// of the session should be initialized and the exclusive status of the
// session SET. This setting is only allowed if the audit attribute is
// SET (TPM_RC_ATTRIBUTES).
// CLEAR (0): In a command, indicates that the audit digest should not
// be initialized. This bit is always CLEAR in a response.
AuditReset bool `gotpm:"bit=2"`
// SET (1): In a command, this setting indicates that the first
// parameter in the command is symmetrically encrypted using the
// parameter encryption scheme described in TPM 2.0 Part 1. The TPM will
// decrypt the parameter after performing any HMAC computations and
// before unmarshaling the parameter. In a response, the attribute is
// copied from the request but has no effect on the response.
// CLEAR (0): Session not used for encryption.
// For a password authorization, this attribute will be CLEAR in both the
// command and response.
Decrypt bool `gotpm:"bit=5"`
// SET (1): In a command, this setting indicates that the TPM should use
// this session to encrypt the first parameter in the response. In a
// response, it indicates that the attribute was set in the command and
// that the TPM used the session to encrypt the first parameter in the
// response using the parameter encryption scheme described in TPM 2.0
// Part 1.
// CLEAR (0): Session not used for encryption.
// For a password authorization, this attribute will be CLEAR in both the
// command and response.
Encrypt bool `gotpm:"bit=6"`
// SET (1): In a command or response, this setting indicates that the
// session is for audit and that auditExclusive and auditReset have
// meaning. This session may also be used for authorization, encryption,
// or decryption. The encrypted and encrypt fields may be SET or CLEAR.
// CLEAR (0): Session is not used for audit.
// If SET in the command, then this attribute will be SET in the response.
Audit bool `gotpm:"bit=7"`
}
// TPMALocality represents a TPMA_LOCALITY.
// See definition in Part 2: Structures, section 8.5.
type TPMALocality struct {
bitfield8
marshalByReflection
TPMLocZero bool `gotpm:"bit=0"`
TPMLocOne bool `gotpm:"bit=1"`
TPMLocTwo bool `gotpm:"bit=2"`
TPMLocThree bool `gotpm:"bit=3"`
TPMLocFour bool `gotpm:"bit=4"`
// If any of these bits is set, an extended locality is indicated
Extended uint8 `gotpm:"bit=7:5"`
}
// TPMACC represents a TPMA_CC.
// See definition in Part 2: Structures, section 8.9.
type TPMACC struct {
bitfield32
marshalByReflection
// indicates the command being selected
CommandIndex uint16 `gotpm:"bit=15:0"`
// SET (1): indicates that the command may write to NV
// CLEAR (0): indicates that the command does not write to NV
NV bool `gotpm:"bit=22"`
// SET (1): This command could flush any number of loaded contexts.
// CLEAR (0): no additional changes other than indicated by the flushed attribute
Extensive bool `gotpm:"bit=23"`
// SET (1): The context associated with any transient handle in the command will be flushed when this command completes.
// CLEAR (0): No context is flushed as a side effect of this command.
Flushed bool `gotpm:"bit=24"`
// indicates the number of the handles in the handle area for this command
CHandles uint8 `gotpm:"bit=27:25"`
// SET (1): indicates the presence of the handle area in the response
RHandle bool `gotpm:"bit=28"`
// SET (1): indicates that the command is vendor-specific
// CLEAR (0): indicates that the command is defined in a version of this specification
V bool `gotpm:"bit=29"`
}
// TPMAACT represents a TPMA_ACT.
// See definition in Part 2: Structures, section 8.12.
type TPMAACT struct {
bitfield32
marshalByReflection
// SET (1): The ACT has signaled
// CLEAR (0): The ACT has not signaled
Signaled bool `gotpm:"bit=0"`
// SET (1): The ACT signaled bit is preserved over a power cycle
// CLEAR (0): The ACT signaled bit is not preserved over a power cycle
PreserveSignaled bool `gotpm:"bit=1"`
}
// TPMIYesNo represents a TPMI_YES_NO.
// See definition in Part 2: Structures, section 9.2.
// Use native bool for TPMI_YES_NO; encoding/binary already treats this as 8 bits wide.
type TPMIYesNo = bool
// TPMIDHObject represents a TPMI_DH_OBJECT.
// See definition in Part 2: Structures, section 9.3.
type TPMIDHObject = TPMHandle
// TPMIDHPersistent represents a TPMI_DH_PERSISTENT.
// See definition in Part 2: Structures, section 9.5.
type TPMIDHPersistent = TPMHandle
// TPMIDHEntity represents a TPMI_DH_ENTITY.
// See definition in Part 2: Structures, section 9.6.
type TPMIDHEntity = TPMHandle
// TPMISHAuthSession represents a TPMI_SH_AUTH_SESSION.
// See definition in Part 2: Structures, section 9.8.
type TPMISHAuthSession = TPMHandle
// TPMISHHMAC represents a TPMI_SH_HMAC.
// See definition in Part 2: Structures, section 9.9.
type TPMISHHMAC = TPMHandle
// TPMISHPolicy represents a TPMI_SH_POLICY.
// See definition in Part 2: Structures, section 9.10.
type TPMISHPolicy = TPMHandle
// TPMIDHContext represents a TPMI_DH_CONTEXT.
// See definition in Part 2: Structures, section 9.11.
type TPMIDHContext = TPMHandle
// TPMIDHSaved represents a TPMI_DH_SAVED.
// See definition in Part 2: Structures, section 9.12.
type TPMIDHSaved = TPMHandle
// TPMIRHHierarchy represents a TPMI_RH_HIERARCHY.
// See definition in Part 2: Structures, section 9.13.
type TPMIRHHierarchy = TPMHandle
// TPMIRHEnables represents a TPMI_RH_ENABLES.
// See definition in Part 2: Structures, section 9.14.
type TPMIRHEnables = TPMHandle
// TPMIRHHierarchyAuth represents a TPMI_RH_HIERARCHY_AUTH.
// See definition in Part 2: Structures, section 9.15.
type TPMIRHHierarchyAuth = TPMHandle
// TPMIRHHierarchyPolicy represents a TPMI_RH_HIERARCHY_POLICY.
// See definition in Part 2: Structures, section 9.16.
type TPMIRHHierarchyPolicy = TPMHandle
// TPMIRHPlatform represents a TPMI_RH_PLATFORM.
// See definition in Part 2: Structures, section 9.17.
type TPMIRHPlatform = TPMHandle
// TPMIRHOwner represents a TPMI_RH_OWNER.
// See definition in Part 2: Structures, section 9.18.
type TPMIRHOwner = TPMHandle
// TPMIRHEndorsement represents a TPMI_RH_ENDORSEMENT.
// See definition in Part 2: Structures, section 9.19.
type TPMIRHEndorsement = TPMHandle
// TPMIRHProvision represents a TPMI_RH_PROVISION.
// See definition in Part 2: Structures, section 9.20.
type TPMIRHProvision = TPMHandle
// TPMIRHClear represents a TPMI_RH_CLEAR.
// See definition in Part 2: Structures, section 9.21.
type TPMIRHClear = TPMHandle
// TPMIRHNVAuth represents a TPMI_RH_NV_AUTH.
// See definition in Part 2: Structures, section 9.22.
type TPMIRHNVAuth = TPMHandle
// TPMIRHLockout represents a TPMI_RH_LOCKOUT.
// See definition in Part 2: Structures, section 9.23.
type TPMIRHLockout = TPMHandle
// TPMIRHNVIndex represents a TPMI_RH_NV_INDEX.
// See definition in Part 2: Structures, section 9.24.
type TPMIRHNVIndex = TPMHandle
// TPMIRHAC represents a TPMI_RH_AC.
// See definition in Part 2: Structures, section 9.25.
type TPMIRHAC = TPMHandle
// TPMIRHACT represents a TPMI_RH_ACT.
// See definition in Part 2: Structures, section 9.26.
type TPMIRHACT = TPMHandle
// TPMIAlgHash represents a TPMI_ALG_HASH.
// See definition in Part 2: Structures, section 9.27.
type TPMIAlgHash = TPMAlgID
// Hash returns the crypto.Hash associated with a TPMIAlgHash.
func (a TPMIAlgHash) Hash() (crypto.Hash, error) {
switch TPMAlgID(a) {
case TPMAlgSHA1:
return crypto.SHA1, nil
case TPMAlgSHA256:
return crypto.SHA256, nil
case TPMAlgSHA384:
return crypto.SHA384, nil
case TPMAlgSHA512:
return crypto.SHA512, nil
}
return crypto.SHA256, fmt.Errorf("unsupported hash algorithm: %v", a)
}
// TPMIAlgSym represents a TPMI_ALG_SYM.
// See definition in Part 2: Structures, section 9.29.
type TPMIAlgSym = TPMAlgID
// TPMIAlgSymObject represents a TPMI_ALG_SYM_OBJECT.
// See definition in Part 2: Structures, section 9.30.
type TPMIAlgSymObject = TPMAlgID
// TPMIAlgSymMode represents a TPMI_ALG_SYM_MODE.
// See definition in Part 2: Structures, section 9.31.
type TPMIAlgSymMode = TPMAlgID
// TPMIAlgKDF represents a TPMI_ALG_KDF.
// See definition in Part 2: Structures, section 9.32.
type TPMIAlgKDF = TPMAlgID
// TPMIAlgSigScheme represents a TPMI_ALG_SIG_SCHEME.
// See definition in Part 2: Structures, section 9.33.
type TPMIAlgSigScheme = TPMAlgID
// TPMISTCommandTag represents a TPMI_ST_COMMAND_TAG.
// See definition in Part 2: Structures, section 9.35.
type TPMISTCommandTag = TPMST
// TPMSEmpty represents a TPMS_EMPTY.
// See definition in Part 2: Structures, section 10.1.
type TPMSEmpty struct {
marshalByReflection
}
// TPMTHA represents a TPMT_HA.
// See definition in Part 2: Structures, section 10.3.2.
type TPMTHA struct {
marshalByReflection
// selector of the hash contained in the digest that implies the size of the digest
HashAlg TPMIAlgHash `gotpm:"nullable"`
// the digest data
// NOTE: For convenience, this is not implemented as a union.
Digest []byte
}
// TPM2BDigest represents a TPM2B_DIGEST.
// See definition in Part 2: Structures, section 10.4.2.
type TPM2BDigest TPM2BData
// TPM2BData represents a TPM2B_DATA.
// See definition in Part 2: Structures, section 10.4.3.
type TPM2BData struct {
marshalByReflection
// size in octets of the buffer field; may be 0
Buffer []byte `gotpm:"sized"`
}
// TPM2BNonce represents a TPM2B_NONCE.
// See definition in Part 2: Structures, section 10.4.4.
type TPM2BNonce TPM2BDigest
// TPM2BEvent represents a TPM2B_EVENT.
// See definition in Part 2: Structures, section 10.4.7.
type TPM2BEvent TPM2BData
// TPM2BTimeout represents a TPM2B_TIMEOUT.
// See definition in Part 2: Structures, section 10.4.10.
type TPM2BTimeout TPM2BData
// TPM2BAuth represents a TPM2B_AUTH.
// See definition in Part 2: Structures, section 10.4.5.
type TPM2BAuth TPM2BDigest
// TPM2BOperand represents a TPM2B_Operand.
// See definition in Part 2: Structures, section 10.4.6.
type TPM2BOperand TPM2BDigest
// TPM2BMaxBuffer represents a TPM2B_MAX_BUFFER.
// See definition in Part 2: Structures, section 10.4.8.
type TPM2BMaxBuffer TPM2BData
// TPM2BMaxNVBuffer represents a TPM2B_MAX_NV_BUFFER.
// See definition in Part 2: Structures, section 10.4.9.
type TPM2BMaxNVBuffer TPM2BData
// TPM2BName represents a TPM2B_NAME.
// See definition in Part 2: Structures, section 10.5.3.
// NOTE: This structure does not contain a TPMUName, because that union
// is not tagged with a selector. Instead, TPM2B_Name is flattened and
// all TPMDirect helpers that deal with names will deal with them as so.
type TPM2BName TPM2BData
// TPMSPCRSelection represents a TPMS_PCR_SELECTION.
// See definition in Part 2: Structures, section 10.6.2.
type TPMSPCRSelection struct {
marshalByReflection
Hash TPMIAlgHash
PCRSelect []byte `gotpm:"sized8"`
}
// TPMTTKCreation represents a TPMT_TK_CREATION.
// See definition in Part 2: Structures, section 10.7.3.
type TPMTTKCreation struct {
marshalByReflection
// ticket structure tag
Tag TPMST
// the hierarchy containing name
Hierarchy TPMIRHHierarchy
// This shall be the HMAC produced using a proof value of hierarchy.
Digest TPM2BDigest
}
// TPMTTKVerified represents a TPMT_TK_Verified.
// See definition in Part 2: Structures, section 10.7.4.
type TPMTTKVerified struct {
marshalByReflection
// ticket structure tag
Tag TPMST
// the hierarchy containing keyName
Hierarchy TPMIRHHierarchy
// This shall be the HMAC produced using a proof value of hierarchy.
Digest TPM2BDigest
}
// TPMTTKAuth represents a TPMT_TK_AUTH.
// See definition in Part 2: Structures, section 10.7.5.
type TPMTTKAuth struct {
marshalByReflection
// ticket structure tag
Tag TPMST
// the hierarchy of the object used to produce the ticket
Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
// This shall be the HMAC produced using a proof value of hierarchy.
Digest TPM2BDigest
}
// TPMTTKHashCheck represents a TPMT_TK_HASHCHECK.
// See definition in Part 2: Structures, section 10.7.6.
type TPMTTKHashCheck struct {
marshalByReflection
// ticket structure tag
Tag TPMST
// the hierarchy
Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
// This shall be the HMAC produced using a proof value of hierarchy.
Digest TPM2BDigest
}
// TPMSAlgProperty represents a TPMS_ALG_PROPERTY.
// See definition in Part 2: Structures, section 10.8.1.
type TPMSAlgProperty struct {
marshalByReflection
// an algorithm identifier
Alg TPMAlgID
// the attributes of the algorithm
AlgProperties TPMAAlgorithm
}
// TPMSTaggedProperty represents a TPMS_TAGGED_PROPERTY.
// See definition in Part 2: Structures, section 10.8.2.
type TPMSTaggedProperty struct {
marshalByReflection
// a property identifier
Property TPMPT
// the value of the property
Value uint32
}
// TPMSTaggedPCRSelect represents a TPMS_TAGGED_PCR_SELECT.
// See definition in Part 2: Structures, section 10.8.3.
type TPMSTaggedPCRSelect struct {
marshalByReflection
// the property identifier
Tag TPMPTPCR
// the bit map of PCR with the identified property
PCRSelect []byte `gotpm:"sized8"`
}
// TPMSTaggedPolicy represents a TPMS_TAGGED_POLICY.
// See definition in Part 2: Structures, section 10.8.4.
type TPMSTaggedPolicy struct {
marshalByReflection
// a permanent handle
Handle TPMHandle
// the policy algorithm and hash
PolicyHash TPMTHA
}
// TPMSACTData represents a TPMS_ACT_DATA.
// See definition in Part 2: Structures, section 10.8.5.
type TPMSACTData struct {
marshalByReflection
// a permanent handle
Handle TPMHandle
// the current timeout of the ACT
Timeout uint32
// the state of the ACT
Attributes TPMAACT
}
// TPMLCC represents a TPML_CC.
// See definition in Part 2: Structures, section 10.9.1.
type TPMLCC struct {
marshalByReflection
CommandCodes []TPMCC `gotpm:"list"`
}
// TPMLCCA represents a TPML_CCA.
// See definition in Part 2: Structures, section 10.9.2.
type TPMLCCA struct {
marshalByReflection
CommandAttributes []TPMACC `gotpm:"list"`
}
// TPMLAlg represents a TPML_ALG.
// See definition in Part 2: Structures, section 10.9.3.
type TPMLAlg struct {
marshalByReflection
Algorithms []TPMAlgID `gotpm:"list"`
}
// TPMLHandle represents a TPML_HANDLE.
// See definition in Part 2: Structures, section 10.9.4.
type TPMLHandle struct {
marshalByReflection
Handle []TPMHandle `gotpm:"list"`
}
// TPMLDigest represents a TPML_DIGEST.
// See definition in Part 2: Structures, section 10.9.5.
type TPMLDigest struct {
marshalByReflection
// a list of digests
Digests []TPM2BDigest `gotpm:"list"`
}
// TPMLDigestValues represents a TPML_DIGEST_VALUES.
// See definition in Part 2: Structures, section 10.9.6.
type TPMLDigestValues struct {
marshalByReflection
// a list of tagged digests
Digests []TPMTHA `gotpm:"list"`
}
// TPMLPCRSelection represents a TPML_PCR_SELECTION.
// See definition in Part 2: Structures, section 10.9.7.
type TPMLPCRSelection struct {
marshalByReflection
PCRSelections []TPMSPCRSelection `gotpm:"list"`
}
// TPMLAlgProperty represents a TPML_ALG_PROPERTY.
// See definition in Part 2: Structures, section 10.9.8.
type TPMLAlgProperty struct {
marshalByReflection
AlgProperties []TPMSAlgProperty `gotpm:"list"`
}
// TPMLTaggedTPMProperty represents a TPML_TAGGED_TPM_PROPERTY.
// See definition in Part 2: Structures, section 10.9.9.
type TPMLTaggedTPMProperty struct {
marshalByReflection
TPMProperty []TPMSTaggedProperty `gotpm:"list"`
}
// TPMLTaggedPCRProperty represents a TPML_TAGGED_PCR_PROPERTY.
// See definition in Part 2: Structures, section 10.9.10.
type TPMLTaggedPCRProperty struct {
marshalByReflection
PCRProperty []TPMSTaggedPCRSelect `gotpm:"list"`
}
// TPMLECCCurve represents a TPML_ECC_CURVE.
// See definition in Part 2: Structures, section 10.9.11.
type TPMLECCCurve struct {
marshalByReflection
ECCCurves []TPMECCCurve `gotpm:"list"`
}
// TPMLTaggedPolicy represents a TPML_TAGGED_POLICY.
// See definition in Part 2: Structures, section 10.9.12.
type TPMLTaggedPolicy struct {
marshalByReflection
Policies []TPMSTaggedPolicy `gotpm:"list"`
}
// TPMLACTData represents a TPML_ACT_DATA.
// See definition in Part 2: Structures, section 10.9.13.
type TPMLACTData struct {
marshalByReflection
ACTData []TPMSACTData `gotpm:"list"`
}
// TPMUCapabilities represents a TPMU_CAPABILITIES.
// See definition in Part 2: Structures, section 10.10.1.
type TPMUCapabilities struct {
selector TPMCap
contents Marshallable
}
// CapabilitiesContents is a type constraint representing the possible contents of TPMUCapabilities.
type CapabilitiesContents interface {
Marshallable
*TPMLAlgProperty | *TPMLHandle | *TPMLCCA | *TPMLCC | *TPMLPCRSelection | *TPMLTaggedTPMProperty |
*TPMLTaggedPCRProperty | *TPMLECCCurve | *TPMLTaggedPolicy | *TPMLACTData
}
// create implements the unmarshallableWithHint interface.
func (u *TPMUCapabilities) create(hint int64) (reflect.Value, error) {
switch TPMCap(hint) {
case TPMCapAlgs:
contents := TPMLAlgProperty{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapHandles:
contents := TPMLHandle{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapCommands:
contents := TPMLCCA{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapPPCommands, TPMCapAuditCommands:
contents := TPMLCC{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapPCRs:
contents := TPMLPCRSelection{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapTPMProperties:
contents := TPMLTaggedTPMProperty{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapPCRProperties:
contents := TPMLTaggedPCRProperty{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapECCCurves:
contents := TPMLECCCurve{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapAuthPolicies:
contents := TPMLTaggedPolicy{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
case TPMCapACT:
contents := TPMLACTData{}
u.contents = &contents
u.selector = TPMCap(hint)
return reflect.ValueOf(&contents), nil
}
return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
}
// get implements the marshallableWithHint interface.
func (u TPMUCapabilities) get(hint int64) (reflect.Value, error) {
if u.selector != 0 && hint != int64(u.selector) {
return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
}
switch TPMCap(hint) {
case TPMCapAlgs:
contents := TPMLAlgProperty{}
if u.contents != nil {
contents = *u.contents.(*TPMLAlgProperty)
}
return reflect.ValueOf(&contents), nil
case TPMCapHandles:
contents := TPMLHandle{}
if u.contents != nil {
contents = *u.contents.(*TPMLHandle)
}
return reflect.ValueOf(&contents), nil
case TPMCapCommands:
contents := TPMLCCA{}
if u.contents != nil {
contents = *u.contents.(*TPMLCCA)
}
return reflect.ValueOf(&contents), nil
case TPMCapPPCommands, TPMCapAuditCommands:
contents := TPMLCC{}
if u.contents != nil {
contents = *u.contents.(*TPMLCC)
}
return reflect.ValueOf(&contents), nil
case TPMCapPCRs:
contents := TPMLPCRSelection{}
if u.contents != nil {
contents = *u.contents.(*TPMLPCRSelection)
}
return reflect.ValueOf(&contents), nil
case TPMCapTPMProperties:
contents := TPMLTaggedTPMProperty{}
if u.contents != nil {
contents = *u.contents.(*TPMLTaggedTPMProperty)
}
return reflect.ValueOf(&contents), nil
case TPMCapPCRProperties:
contents := TPMLTaggedPCRProperty{}
if u.contents != nil {
contents = *u.contents.(*TPMLTaggedPCRProperty)
}
return reflect.ValueOf(&contents), nil
case TPMCapECCCurves:
contents := TPMLECCCurve{}
if u.contents != nil {
contents = *u.contents.(*TPMLECCCurve)
}
return reflect.ValueOf(&contents), nil
case TPMCapAuthPolicies:
contents := TPMLTaggedPolicy{}
if u.contents != nil {
contents = *u.contents.(*TPMLTaggedPolicy)
}
return reflect.ValueOf(&contents), nil
case TPMCapACT:
contents := TPMLACTData{}
if u.contents != nil {
contents = *u.contents.(*TPMLACTData)
}
return reflect.ValueOf(&contents), nil
}
return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
}
// NewTPMUCapabilities instantiates a TPMUCapabilities with the given contents.
func NewTPMUCapabilities[C CapabilitiesContents](selector TPMCap, contents C) TPMUCapabilities {
return TPMUCapabilities{
selector: selector,
contents: contents,
}
}
// Algorithms returns the 'algorithms' member of the union.
func (u *TPMUCapabilities) Algorithms() (*TPMLAlgProperty, error) {
if u.selector == TPMCapAlgs {
return u.contents.(*TPMLAlgProperty), nil
}
return nil, fmt.Errorf("did not contain algorithms (selector value was %v)", u.selector)
}
// Handles returns the 'handles' member of the union.
func (u *TPMUCapabilities) Handles() (*TPMLHandle, error) {
if u.selector == TPMCapHandles {
return u.contents.(*TPMLHandle), nil
}
return nil, fmt.Errorf("did not contain handles (selector value was %v)", u.selector)
}
// Command returns the 'command' member of the union.
func (u *TPMUCapabilities) Command() (*TPMLCCA, error) {
if u.selector == TPMCapCommands {
return u.contents.(*TPMLCCA), nil
}
return nil, fmt.Errorf("did not contain command (selector value was %v)", u.selector)
}
// PPCommands returns the 'ppCommands' member of the union.
func (u *TPMUCapabilities) PPCommands() (*TPMLCC, error) {
if u.selector == TPMCapPPCommands {
return u.contents.(*TPMLCC), nil
}
return nil, fmt.Errorf("did not contain ppCommands (selector value was %v)", u.selector)
}
// AuditCommands returns the 'auditCommands' member of the union.
func (u *TPMUCapabilities) AuditCommands() (*TPMLCC, error) {
if u.selector == TPMCapAuditCommands {
return u.contents.(*TPMLCC), nil
}
return nil, fmt.Errorf("did not contain auditCommands (selector value was %v)", u.selector)
}
// AssignedPCR returns the 'assignedPCR' member of the union.
func (u *TPMUCapabilities) AssignedPCR() (*TPMLPCRSelection, error) {
if u.selector == TPMCapPCRs {
return u.contents.(*TPMLPCRSelection), nil
}
return nil, fmt.Errorf("did not contain assignedPCR (selector value was %v)", u.selector)
}
// TPMProperties returns the 'tpmProperties' member of the union.
func (u *TPMUCapabilities) TPMProperties() (*TPMLTaggedTPMProperty, error) {
if u.selector == TPMCapTPMProperties {
return u.contents.(*TPMLTaggedTPMProperty), nil
}
return nil, fmt.Errorf("did not contain tpmProperties (selector value was %v)", u.selector)
}
// PCRProperties returns the 'pcrProperties' member of the union.
func (u *TPMUCapabilities) PCRProperties() (*TPMLTaggedPCRProperty, error) {
if u.selector == TPMCapPCRProperties {
return u.contents.(*TPMLTaggedPCRProperty), nil
}
return nil, fmt.Errorf("did not contain pcrProperties (selector value was %v)", u.selector)
}
// ECCCurves returns the 'eccCurves' member of the union.
func (u *TPMUCapabilities) ECCCurves() (*TPMLECCCurve, error) {
if u.selector == TPMCapECCCurves {
return u.contents.(*TPMLECCCurve), nil
}
return nil, fmt.Errorf("did not contain eccCurves (selector value was %v)", u.selector)
}
// AuthPolicies returns the 'authPolicies' member of the union.
func (u *TPMUCapabilities) AuthPolicies() (*TPMLTaggedPolicy, error) {
if u.selector == TPMCapAuthPolicies {
return u.contents.(*TPMLTaggedPolicy), nil
}
return nil, fmt.Errorf("did not contain authPolicies (selector value was %v)", u.selector)
}
// ACTData returns the 'actData' member of the union.
func (u *TPMUCapabilities) ACTData() (*TPMLACTData, error) {
if u.selector == TPMCapAuthPolicies {
return u.contents.(*TPMLACTData), nil
}
return nil, fmt.Errorf("did not contain actData (selector value was %v)", u.selector)
}
// TPMSCapabilityData represents a TPMS_CAPABILITY_DATA.
// See definition in Part 2: Structures, section 10.10.2.
type TPMSCapabilityData struct {
marshalByReflection