Debian Codegraph @

tpm2/structures.go

raw
1 // Package tpm2 defines all the TPM 2.0 structures together to avoid import cycles
2 package tpm2
3
4 import (
5 "bytes"
6 "crypto"
7 "crypto/ecdh"
8 "crypto/elliptic"
9 "encoding/binary"
10 "reflect"
11
12 // Register the relevant hash implementations.
13 _ "crypto/sha1"
14 _ "crypto/sha256"
15 _ "crypto/sha512"
16 "fmt"
17 )
18
19 // TPMCmdHeader is the header structure in front of any TPM command.
20 // It is described in Part 1, Architecture.
21 type TPMCmdHeader struct {
22 marshalByReflection
23 Tag TPMISTCommandTag
24 Length uint32
25 CommandCode TPMCC
26 }
27
28 // TPMRspHeader is the header structure in front of any TPM response.
29 // It is described in Part 1, Architecture.
30 type TPMRspHeader struct {
31 marshalByReflection
32 Tag TPMISTCommandTag
33 Length uint32
34 ResponseCode TPMRC
35 }
36
37 // TPMAlgorithmID represents a TPM_ALGORITHM_ID
38 // this is the 1.2 compatible form of the TPM_ALG_ID
39 // See definition in Part 2, Structures, section 5.3.
40 type TPMAlgorithmID uint32
41
42 // TPMModifierIndicator represents a TPM_MODIFIER_INDICATOR.
43 // See definition in Part 2, Structures, section 5.3.
44 type TPMModifierIndicator uint32
45
46 // TPMAuthorizationSize represents a TPM_AUTHORIZATION_SIZE.
47 // the authorizationSize parameter in a command
48 // See definition in Part 2, Structures, section 5.3.
49 type TPMAuthorizationSize uint32
50
51 // TPMParameterSize represents a TPM_PARAMETER_SIZE.
52 // the parameterSize parameter in a command
53 // See definition in Part 2, Structures, section 5.3.
54 type TPMParameterSize uint32
55
56 // TPMKeySize represents a TPM_KEY_SIZE.
57 // a key size in octets
58 // See definition in Part 2, Structures, section 5.3.
59 type TPMKeySize uint16
60
61 // TPMKeyBits represents a TPM_KEY_BITS.
62 // a key size in bits
63 // See definition in Part 2, Structures, section 5.3.
64 type TPMKeyBits uint16
65
66 // TPMGenerated represents a TPM_GENERATED.
67 // See definition in Part 2: Structures, section 6.2.
68 type TPMGenerated uint32
69
70 // Generated values come from Part 2: Structures, section 6.2.
71 const (
72 TPMGeneratedValue TPMGenerated = 0xff544347
73 )
74
75 // Check verifies that a TPMGenerated value is correct, and returns an error
76 // otherwise.
77 func (g TPMGenerated) Check() error {
78 if g != TPMGeneratedValue {
79 return fmt.Errorf("TPM_GENERATED value should be 0x%x, was 0x%x", TPMGeneratedValue, g)
80 }
81 return nil
82 }
83
84 // Curve returns the elliptic.Curve associated with a TPMECCCurve.
85 func (c TPMECCCurve) Curve() (elliptic.Curve, error) {
86 switch c {
87 case TPMECCNistP224:
88 return elliptic.P224(), nil
89 case TPMECCNistP256:
90 return elliptic.P256(), nil
91 case TPMECCNistP384:
92 return elliptic.P384(), nil
93 case TPMECCNistP521:
94 return elliptic.P521(), nil
95 default:
96 return nil, fmt.Errorf("unsupported ECC curve: %v", c)
97 }
98 }
99
100 // ECDHCurve returns the ecdh.Curve associated with a TPMECCCurve.
101 func (c TPMECCCurve) ECDHCurve() (ecdh.Curve, error) {
102 switch c {
103 case TPMECCNistP256:
104 return ecdh.P256(), nil
105 case TPMECCNistP384:
106 return ecdh.P384(), nil
107 case TPMECCNistP521:
108 return ecdh.P521(), nil
109 default:
110 return nil, fmt.Errorf("unsupported ECC curve: %v", c)
111 }
112 }
113
114 // HandleValue returns the handle value. This behavior is intended to satisfy
115 // an interface that can be implemented by other, more complex types as well.
116 func (h TPMHandle) HandleValue() uint32 {
117 return uint32(h)
118 }
119
120 // KnownName returns the TPM Name associated with the handle, if it can be known
121 // based only on the handle. This depends upon the value of the handle:
122 // only PCR, session, and permanent values have known constant Names.
123 // See definition in part 1: Architecture, section 16.
124 func (h TPMHandle) KnownName() *TPM2BName {
125 switch (TPMHT)(h >> 24) {
126 case TPMHTPCR, TPMHTHMACSession, TPMHTPolicySession, TPMHTPermanent:
127 result := make([]byte, 4)
128 binary.BigEndian.PutUint32(result, h.HandleValue())
129 return &TPM2BName{Buffer: result}
130 }
131 return nil
132 }
133
134 // TPMAAlgorithm represents a TPMA_ALGORITHM.
135 // See definition in Part 2: Structures, section 8.2.
136 type TPMAAlgorithm struct {
137 bitfield32
138 marshalByReflection
139 // SET (1): an asymmetric algorithm with public and private portions
140 // CLEAR (0): not an asymmetric algorithm
141 Asymmetric bool `gotpm:"bit=0"`
142 // SET (1): a symmetric block cipher
143 // CLEAR (0): not a symmetric block cipher
144 Symmetric bool `gotpm:"bit=1"`
145 // SET (1): a hash algorithm
146 // CLEAR (0): not a hash algorithm
147 Hash bool `gotpm:"bit=2"`
148 // SET (1): an algorithm that may be used as an object type
149 // CLEAR (0): an algorithm that is not used as an object type
150 Object bool `gotpm:"bit=3"`
151 // SET (1): a signing algorithm. The setting of asymmetric,
152 // symmetric, and hash will indicate the type of signing algorithm.
153 // CLEAR (0): not a signing algorithm
154 Signing bool `gotpm:"bit=8"`
155 // SET (1): an encryption/decryption algorithm. The setting of
156 // asymmetric, symmetric, and hash will indicate the type of
157 // encryption/decryption algorithm.
158 // CLEAR (0): not an encryption/decryption algorithm
159 Encrypting bool `gotpm:"bit=9"`
160 // SET (1): a method such as a key derivative function (KDF)
161 // CLEAR (0): not a method
162 Method bool `gotpm:"bit=10"`
163 }
164
165 // TPMAObject represents a TPMA_OBJECT.
166 // See definition in Part 2: Structures, section 8.3.2.
167 type TPMAObject struct {
168 bitfield32
169 marshalByReflection
170 // SET (1): The hierarchy of the object, as indicated by its
171 // Qualified Name, may not change.
172 // CLEAR (0): The hierarchy of the object may change as a result
173 // of this object or an ancestor key being duplicated for use in
174 // another hierarchy.
175 FixedTPM bool `gotpm:"bit=1"`
176 // SET (1): Previously saved contexts of this object may not be
177 // loaded after Startup(CLEAR).
178 // CLEAR (0): Saved contexts of this object may be used after a
179 // Shutdown(STATE) and subsequent Startup().
180 STClear bool `gotpm:"bit=2"`
181 // SET (1): The parent of the object may not change.
182 // CLEAR (0): The parent of the object may change as the result of
183 // a TPM2_Duplicate() of the object.
184 FixedParent bool `gotpm:"bit=4"`
185 // SET (1): Indicates that, when the object was created with
186 // TPM2_Create() or TPM2_CreatePrimary(), the TPM generated all of
187 // the sensitive data other than the authValue.
188 // CLEAR (0): A portion of the sensitive data, other than the
189 // authValue, was provided by the caller.
190 SensitiveDataOrigin bool `gotpm:"bit=5"`
191 // SET (1): Approval of USER role actions with this object may be
192 // with an HMAC session or with a password using the authValue of
193 // the object or a policy session.
194 // CLEAR (0): Approval of USER role actions with this object may
195 // only be done with a policy session.
196 UserWithAuth bool `gotpm:"bit=6"`
197 // SET (1): Approval of ADMIN role actions with this object may
198 // only be done with a policy session.
199 // CLEAR (0): Approval of ADMIN role actions with this object may
200 // be with an HMAC session or with a password using the authValue
201 // of the object or a policy session.
202 AdminWithPolicy bool `gotpm:"bit=7"`
203 // SET (1): The object exists only within a firmware-limited hierarchy.
204 // CLEAR (0): The object can exist outside a firmware-limited hierarchy.
205 FirmwareLimited bool `gotpm:"bit=8"`
206 // SET (1): The object is not subject to dictionary attack
207 // protections.
208 // CLEAR (0): The object is subject to dictionary attack
209 // protections.
210 NoDA bool `gotpm:"bit=10"`
211 // SET (1): If the object is duplicated, then symmetricAlg shall
212 // not be TPM_ALG_NULL and newParentHandle shall not be
213 // TPM_RH_NULL.
214 // CLEAR (0): The object may be duplicated without an inner
215 // wrapper on the private portion of the object and the new parent
216 // may be TPM_RH_NULL.
217 EncryptedDuplication bool `gotpm:"bit=11"`
218 // SET (1): Key usage is restricted to manipulate structures of
219 // known format; the parent of this key shall have restricted SET.
220 // CLEAR (0): Key usage is not restricted to use on special
221 // formats.
222 Restricted bool `gotpm:"bit=16"`
223 // SET (1): The private portion of the key may be used to decrypt.
224 // CLEAR (0): The private portion of the key may not be used to
225 // decrypt.
226 Decrypt bool `gotpm:"bit=17"`
227 // SET (1): For a symmetric cipher object, the private portion of
228 // the key may be used to encrypt. For other objects, the private
229 // portion of the key may be used to sign.
230 // CLEAR (0): The private portion of the key may not be used to
231 // sign or encrypt.
232 SignEncrypt bool `gotpm:"bit=18"`
233 // SET (1): An asymmetric key that may not be used to sign with
234 // TPM2_Sign() CLEAR (0): A key that may be used with TPM2_Sign()
235 // if sign is SET
236 // NOTE: This attribute only has significance if sign is SET.
237 X509Sign bool `gotpm:"bit=19"`
238 }
239
240 // TPMASession represents a TPMA_SESSION.
241 // See definition in Part 2: Structures, section 8.4.
242 type TPMASession struct {
243 bitfield8
244 marshalByReflection
245 // SET (1): In a command, this setting indicates that the session
246 // is to remain active after successful completion of the command.
247 // In a response, it indicates that the session is still active.
248 // If SET in the command, this attribute shall be SET in the response.
249 // CLEAR (0): In a command, this setting indicates that the TPM should
250 // close the session and flush any related context when the command
251 // completes successfully. In a response, it indicates that the
252 // session is closed and the context is no longer active.
253 // This attribute has no meaning for a password authorization and the
254 // TPM will allow any setting of the attribute in the command and SET
255 // the attribute in the response.
256 ContinueSession bool `gotpm:"bit=0"`
257 // SET (1): In a command, this setting indicates that the command
258 // should only be executed if the session is exclusive at the start of
259 // the command. In a response, it indicates that the session is
260 // exclusive. This setting is only allowed if the audit attribute is
261 // SET (TPM_RC_ATTRIBUTES).
262 // CLEAR (0): In a command, indicates that the session need not be
263 // exclusive at the start of the command. In a response, indicates that
264 // the session is not exclusive.
265 AuditExclusive bool `gotpm:"bit=1"`
266 // SET (1): In a command, this setting indicates that the audit digest
267 // of the session should be initialized and the exclusive status of the
268 // session SET. This setting is only allowed if the audit attribute is
269 // SET (TPM_RC_ATTRIBUTES).
270 // CLEAR (0): In a command, indicates that the audit digest should not
271 // be initialized. This bit is always CLEAR in a response.
272 AuditReset bool `gotpm:"bit=2"`
273 // SET (1): In a command, this setting indicates that the first
274 // parameter in the command is symmetrically encrypted using the
275 // parameter encryption scheme described in TPM 2.0 Part 1. The TPM will
276 // decrypt the parameter after performing any HMAC computations and
277 // before unmarshaling the parameter. In a response, the attribute is
278 // copied from the request but has no effect on the response.
279 // CLEAR (0): Session not used for encryption.
280 // For a password authorization, this attribute will be CLEAR in both the
281 // command and response.
282 Decrypt bool `gotpm:"bit=5"`
283 // SET (1): In a command, this setting indicates that the TPM should use
284 // this session to encrypt the first parameter in the response. In a
285 // response, it indicates that the attribute was set in the command and
286 // that the TPM used the session to encrypt the first parameter in the
287 // response using the parameter encryption scheme described in TPM 2.0
288 // Part 1.
289 // CLEAR (0): Session not used for encryption.
290 // For a password authorization, this attribute will be CLEAR in both the
291 // command and response.
292 Encrypt bool `gotpm:"bit=6"`
293 // SET (1): In a command or response, this setting indicates that the
294 // session is for audit and that auditExclusive and auditReset have
295 // meaning. This session may also be used for authorization, encryption,
296 // or decryption. The encrypted and encrypt fields may be SET or CLEAR.
297 // CLEAR (0): Session is not used for audit.
298 // If SET in the command, then this attribute will be SET in the response.
299 Audit bool `gotpm:"bit=7"`
300 }
301
302 // TPMALocality represents a TPMA_LOCALITY.
303 // See definition in Part 2: Structures, section 8.5.
304 type TPMALocality struct {
305 bitfield8
306 marshalByReflection
307 TPMLocZero bool `gotpm:"bit=0"`
308 TPMLocOne bool `gotpm:"bit=1"`
309 TPMLocTwo bool `gotpm:"bit=2"`
310 TPMLocThree bool `gotpm:"bit=3"`
311 TPMLocFour bool `gotpm:"bit=4"`
312 // If any of these bits is set, an extended locality is indicated
313 Extended uint8 `gotpm:"bit=7:5"`
314 }
315
316 // TPMACC represents a TPMA_CC.
317 // See definition in Part 2: Structures, section 8.9.
318 type TPMACC struct {
319 bitfield32
320 marshalByReflection
321 // indicates the command being selected
322 CommandIndex uint16 `gotpm:"bit=15:0"`
323 // SET (1): indicates that the command may write to NV
324 // CLEAR (0): indicates that the command does not write to NV
325 NV bool `gotpm:"bit=22"`
326 // SET (1): This command could flush any number of loaded contexts.
327 // CLEAR (0): no additional changes other than indicated by the flushed attribute
328 Extensive bool `gotpm:"bit=23"`
329 // SET (1): The context associated with any transient handle in the command will be flushed when this command completes.
330 // CLEAR (0): No context is flushed as a side effect of this command.
331 Flushed bool `gotpm:"bit=24"`
332 // indicates the number of the handles in the handle area for this command
333 CHandles uint8 `gotpm:"bit=27:25"`
334 // SET (1): indicates the presence of the handle area in the response
335 RHandle bool `gotpm:"bit=28"`
336 // SET (1): indicates that the command is vendor-specific
337 // CLEAR (0): indicates that the command is defined in a version of this specification
338 V bool `gotpm:"bit=29"`
339 }
340
341 // TPMAACT represents a TPMA_ACT.
342 // See definition in Part 2: Structures, section 8.12.
343 type TPMAACT struct {
344 bitfield32
345 marshalByReflection
346 // SET (1): The ACT has signaled
347 // CLEAR (0): The ACT has not signaled
348 Signaled bool `gotpm:"bit=0"`
349 // SET (1): The ACT signaled bit is preserved over a power cycle
350 // CLEAR (0): The ACT signaled bit is not preserved over a power cycle
351 PreserveSignaled bool `gotpm:"bit=1"`
352 }
353
354 // TPMIYesNo represents a TPMI_YES_NO.
355 // See definition in Part 2: Structures, section 9.2.
356 // Use native bool for TPMI_YES_NO; encoding/binary already treats this as 8 bits wide.
357 type TPMIYesNo = bool
358
359 // TPMIDHObject represents a TPMI_DH_OBJECT.
360 // See definition in Part 2: Structures, section 9.3.
361 type TPMIDHObject = TPMHandle
362
363 // TPMIDHPersistent represents a TPMI_DH_PERSISTENT.
364 // See definition in Part 2: Structures, section 9.5.
365 type TPMIDHPersistent = TPMHandle
366
367 // TPMIDHEntity represents a TPMI_DH_ENTITY.
368 // See definition in Part 2: Structures, section 9.6.
369 type TPMIDHEntity = TPMHandle
370
371 // TPMISHAuthSession represents a TPMI_SH_AUTH_SESSION.
372 // See definition in Part 2: Structures, section 9.8.
373 type TPMISHAuthSession = TPMHandle
374
375 // TPMISHHMAC represents a TPMI_SH_HMAC.
376 // See definition in Part 2: Structures, section 9.9.
377 type TPMISHHMAC = TPMHandle
378
379 // TPMISHPolicy represents a TPMI_SH_POLICY.
380 // See definition in Part 2: Structures, section 9.10.
381 type TPMISHPolicy = TPMHandle
382
383 // TPMIDHContext represents a TPMI_DH_CONTEXT.
384 // See definition in Part 2: Structures, section 9.11.
385 type TPMIDHContext = TPMHandle
386
387 // TPMIDHSaved represents a TPMI_DH_SAVED.
388 // See definition in Part 2: Structures, section 9.12.
389 type TPMIDHSaved = TPMHandle
390
391 // TPMIRHHierarchy represents a TPMI_RH_HIERARCHY.
392 // See definition in Part 2: Structures, section 9.13.
393 type TPMIRHHierarchy = TPMHandle
394
395 // TPMIRHEnables represents a TPMI_RH_ENABLES.
396 // See definition in Part 2: Structures, section 9.14.
397 type TPMIRHEnables = TPMHandle
398
399 // TPMIRHHierarchyAuth represents a TPMI_RH_HIERARCHY_AUTH.
400 // See definition in Part 2: Structures, section 9.15.
401 type TPMIRHHierarchyAuth = TPMHandle
402
403 // TPMIRHHierarchyPolicy represents a TPMI_RH_HIERARCHY_POLICY.
404 // See definition in Part 2: Structures, section 9.16.
405 type TPMIRHHierarchyPolicy = TPMHandle
406
407 // TPMIRHPlatform represents a TPMI_RH_PLATFORM.
408 // See definition in Part 2: Structures, section 9.17.
409 type TPMIRHPlatform = TPMHandle
410
411 // TPMIRHOwner represents a TPMI_RH_OWNER.
412 // See definition in Part 2: Structures, section 9.18.
413 type TPMIRHOwner = TPMHandle
414
415 // TPMIRHEndorsement represents a TPMI_RH_ENDORSEMENT.
416 // See definition in Part 2: Structures, section 9.19.
417 type TPMIRHEndorsement = TPMHandle
418
419 // TPMIRHProvision represents a TPMI_RH_PROVISION.
420 // See definition in Part 2: Structures, section 9.20.
421 type TPMIRHProvision = TPMHandle
422
423 // TPMIRHClear represents a TPMI_RH_CLEAR.
424 // See definition in Part 2: Structures, section 9.21.
425 type TPMIRHClear = TPMHandle
426
427 // TPMIRHNVAuth represents a TPMI_RH_NV_AUTH.
428 // See definition in Part 2: Structures, section 9.22.
429 type TPMIRHNVAuth = TPMHandle
430
431 // TPMIRHLockout represents a TPMI_RH_LOCKOUT.
432 // See definition in Part 2: Structures, section 9.23.
433 type TPMIRHLockout = TPMHandle
434
435 // TPMIRHNVIndex represents a TPMI_RH_NV_INDEX.
436 // See definition in Part 2: Structures, section 9.24.
437 type TPMIRHNVIndex = TPMHandle
438
439 // TPMIRHAC represents a TPMI_RH_AC.
440 // See definition in Part 2: Structures, section 9.25.
441 type TPMIRHAC = TPMHandle
442
443 // TPMIRHACT represents a TPMI_RH_ACT.
444 // See definition in Part 2: Structures, section 9.26.
445 type TPMIRHACT = TPMHandle
446
447 // TPMIAlgHash represents a TPMI_ALG_HASH.
448 // See definition in Part 2: Structures, section 9.27.
449 type TPMIAlgHash = TPMAlgID
450
451 // Hash returns the crypto.Hash associated with a TPMIAlgHash.
452 func (a TPMIAlgHash) Hash() (crypto.Hash, error) {
453 switch TPMAlgID(a) {
454 case TPMAlgSHA1:
455 return crypto.SHA1, nil
456 case TPMAlgSHA256:
457 return crypto.SHA256, nil
458 case TPMAlgSHA384:
459 return crypto.SHA384, nil
460 case TPMAlgSHA512:
461 return crypto.SHA512, nil
462 }
463 return crypto.SHA256, fmt.Errorf("unsupported hash algorithm: %v", a)
464 }
465
466 // TPMIAlgSym represents a TPMI_ALG_SYM.
467 // See definition in Part 2: Structures, section 9.29.
468 type TPMIAlgSym = TPMAlgID
469
470 // TPMIAlgSymObject represents a TPMI_ALG_SYM_OBJECT.
471 // See definition in Part 2: Structures, section 9.30.
472 type TPMIAlgSymObject = TPMAlgID
473
474 // TPMIAlgSymMode represents a TPMI_ALG_SYM_MODE.
475 // See definition in Part 2: Structures, section 9.31.
476 type TPMIAlgSymMode = TPMAlgID
477
478 // TPMIAlgKDF represents a TPMI_ALG_KDF.
479 // See definition in Part 2: Structures, section 9.32.
480 type TPMIAlgKDF = TPMAlgID
481
482 // TPMIAlgSigScheme represents a TPMI_ALG_SIG_SCHEME.
483 // See definition in Part 2: Structures, section 9.33.
484 type TPMIAlgSigScheme = TPMAlgID
485
486 // TPMISTCommandTag represents a TPMI_ST_COMMAND_TAG.
487 // See definition in Part 2: Structures, section 9.35.
488 type TPMISTCommandTag = TPMST
489
490 // TPMSEmpty represents a TPMS_EMPTY.
491 // See definition in Part 2: Structures, section 10.1.
492 type TPMSEmpty struct {
493 marshalByReflection
494 }
495
496 // TPMTHA represents a TPMT_HA.
497 // See definition in Part 2: Structures, section 10.3.2.
498 type TPMTHA struct {
499 marshalByReflection
500 // selector of the hash contained in the digest that implies the size of the digest
501 HashAlg TPMIAlgHash `gotpm:"nullable"`
502 // the digest data
503 // NOTE: For convenience, this is not implemented as a union.
504 Digest []byte
505 }
506
507 // TPM2BDigest represents a TPM2B_DIGEST.
508 // See definition in Part 2: Structures, section 10.4.2.
509 type TPM2BDigest TPM2BData
510
511 // TPM2BData represents a TPM2B_DATA.
512 // See definition in Part 2: Structures, section 10.4.3.
513 type TPM2BData struct {
514 marshalByReflection
515 // size in octets of the buffer field; may be 0
516 Buffer []byte `gotpm:"sized"`
517 }
518
519 // TPM2BNonce represents a TPM2B_NONCE.
520 // See definition in Part 2: Structures, section 10.4.4.
521 type TPM2BNonce TPM2BDigest
522
523 // TPM2BEvent represents a TPM2B_EVENT.
524 // See definition in Part 2: Structures, section 10.4.7.
525 type TPM2BEvent TPM2BData
526
527 // TPM2BTimeout represents a TPM2B_TIMEOUT.
528 // See definition in Part 2: Structures, section 10.4.10.
529 type TPM2BTimeout TPM2BData
530
531 // TPM2BAuth represents a TPM2B_AUTH.
532 // See definition in Part 2: Structures, section 10.4.5.
533 type TPM2BAuth TPM2BDigest
534
535 // TPM2BOperand represents a TPM2B_Operand.
536 // See definition in Part 2: Structures, section 10.4.6.
537 type TPM2BOperand TPM2BDigest
538
539 // TPM2BMaxBuffer represents a TPM2B_MAX_BUFFER.
540 // See definition in Part 2: Structures, section 10.4.8.
541 type TPM2BMaxBuffer TPM2BData
542
543 // TPM2BMaxNVBuffer represents a TPM2B_MAX_NV_BUFFER.
544 // See definition in Part 2: Structures, section 10.4.9.
545 type TPM2BMaxNVBuffer TPM2BData
546
547 // TPM2BIV represents a TPM2B_IV.
548 // See definition in Part 2: Structures, section 10.4.11.
549 type TPM2BIV TPM2BData
550
551 // TPM2BName represents a TPM2B_NAME.
552 // See definition in Part 2: Structures, section 10.5.3.
553 // NOTE: This structure does not contain a TPMUName, because that union
554 // is not tagged with a selector. Instead, TPM2B_Name is flattened and
555 // all TPMDirect helpers that deal with names will deal with them as so.
556 type TPM2BName TPM2BData
557
558 // TPMSPCRSelection represents a TPMS_PCR_SELECTION.
559 // See definition in Part 2: Structures, section 10.6.2.
560 type TPMSPCRSelection struct {
561 marshalByReflection
562 Hash TPMIAlgHash
563 PCRSelect []byte `gotpm:"sized8"`
564 }
565
566 // TPMTTKCreation represents a TPMT_TK_CREATION.
567 // See definition in Part 2: Structures, section 10.7.3.
568 type TPMTTKCreation struct {
569 marshalByReflection
570 // ticket structure tag
571 Tag TPMST
572 // the hierarchy containing name
573 Hierarchy TPMIRHHierarchy
574 // This shall be the HMAC produced using a proof value of hierarchy.
575 Digest TPM2BDigest
576 }
577
578 // TPMTTKVerified represents a TPMT_TK_Verified.
579 // See definition in Part 2: Structures, section 10.7.4.
580 type TPMTTKVerified struct {
581 marshalByReflection
582 // ticket structure tag
583 Tag TPMST
584 // the hierarchy containing keyName
585 Hierarchy TPMIRHHierarchy
586 // This shall be the HMAC produced using a proof value of hierarchy.
587 Digest TPM2BDigest
588 }
589
590 // TPMTTKAuth represents a TPMT_TK_AUTH.
591 // See definition in Part 2: Structures, section 10.7.5.
592 type TPMTTKAuth struct {
593 marshalByReflection
594 // ticket structure tag
595 Tag TPMST
596 // the hierarchy of the object used to produce the ticket
597 Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
598 // This shall be the HMAC produced using a proof value of hierarchy.
599 Digest TPM2BDigest
600 }
601
602 // TPMTTKHashCheck represents a TPMT_TK_HASHCHECK.
603 // See definition in Part 2: Structures, section 10.7.6.
604 type TPMTTKHashCheck struct {
605 marshalByReflection
606 // ticket structure tag
607 Tag TPMST
608 // the hierarchy
609 Hierarchy TPMIRHHierarchy `gotpm:"nullable"`
610 // This shall be the HMAC produced using a proof value of hierarchy.
611 Digest TPM2BDigest
612 }
613
614 // TPMSAlgProperty represents a TPMS_ALG_PROPERTY.
615 // See definition in Part 2: Structures, section 10.8.1.
616 type TPMSAlgProperty struct {
617 marshalByReflection
618 // an algorithm identifier
619 Alg TPMAlgID
620 // the attributes of the algorithm
621 AlgProperties TPMAAlgorithm
622 }
623
624 // TPMSTaggedProperty represents a TPMS_TAGGED_PROPERTY.
625 // See definition in Part 2: Structures, section 10.8.2.
626 type TPMSTaggedProperty struct {
627 marshalByReflection
628 // a property identifier
629 Property TPMPT
630 // the value of the property
631 Value uint32
632 }
633
634 // TPMSTaggedPCRSelect represents a TPMS_TAGGED_PCR_SELECT.
635 // See definition in Part 2: Structures, section 10.8.3.
636 type TPMSTaggedPCRSelect struct {
637 marshalByReflection
638 // the property identifier
639 Tag TPMPTPCR
640 // the bit map of PCR with the identified property
641 PCRSelect []byte `gotpm:"sized8"`
642 }
643
644 // TPMSTaggedPolicy represents a TPMS_TAGGED_POLICY.
645 // See definition in Part 2: Structures, section 10.8.4.
646 type TPMSTaggedPolicy struct {
647 marshalByReflection
648 // a permanent handle
649 Handle TPMHandle
650 // the policy algorithm and hash
651 PolicyHash TPMTHA
652 }
653
654 // TPMSACTData represents a TPMS_ACT_DATA.
655 // See definition in Part 2: Structures, section 10.8.5.
656 type TPMSACTData struct {
657 marshalByReflection
658 // a permanent handle
659 Handle TPMHandle
660 // the current timeout of the ACT
661 Timeout uint32
662 // the state of the ACT
663 Attributes TPMAACT
664 }
665
666 // TPMLCC represents a TPML_CC.
667 // See definition in Part 2: Structures, section 10.9.1.
668 type TPMLCC struct {
669 marshalByReflection
670 CommandCodes []TPMCC `gotpm:"list"`
671 }
672
673 // TPMLCCA represents a TPML_CCA.
674 // See definition in Part 2: Structures, section 10.9.2.
675 type TPMLCCA struct {
676 marshalByReflection
677 CommandAttributes []TPMACC `gotpm:"list"`
678 }
679
680 // TPMLAlg represents a TPML_ALG.
681 // See definition in Part 2: Structures, section 10.9.3.
682 type TPMLAlg struct {
683 marshalByReflection
684 Algorithms []TPMAlgID `gotpm:"list"`
685 }
686
687 // TPMLHandle represents a TPML_HANDLE.
688 // See definition in Part 2: Structures, section 10.9.4.
689 type TPMLHandle struct {
690 marshalByReflection
691 Handle []TPMHandle `gotpm:"list"`
692 }
693
694 // TPMLDigest represents a TPML_DIGEST.
695 // See definition in Part 2: Structures, section 10.9.5.
696 type TPMLDigest struct {
697 marshalByReflection
698 // a list of digests
699 Digests []TPM2BDigest `gotpm:"list"`
700 }
701
702 // TPMLDigestValues represents a TPML_DIGEST_VALUES.
703 // See definition in Part 2: Structures, section 10.9.6.
704 type TPMLDigestValues struct {
705 marshalByReflection
706 // a list of tagged digests
707 Digests []TPMTHA `gotpm:"list"`
708 }
709
710 // TPMLPCRSelection represents a TPML_PCR_SELECTION.
711 // See definition in Part 2: Structures, section 10.9.7.
712 type TPMLPCRSelection struct {
713 marshalByReflection
714 PCRSelections []TPMSPCRSelection `gotpm:"list"`
715 }
716
717 // TPMLAlgProperty represents a TPML_ALG_PROPERTY.
718 // See definition in Part 2: Structures, section 10.9.8.
719 type TPMLAlgProperty struct {
720 marshalByReflection
721 AlgProperties []TPMSAlgProperty `gotpm:"list"`
722 }
723
724 // TPMLTaggedTPMProperty represents a TPML_TAGGED_TPM_PROPERTY.
725 // See definition in Part 2: Structures, section 10.9.9.
726 type TPMLTaggedTPMProperty struct {
727 marshalByReflection
728 TPMProperty []TPMSTaggedProperty `gotpm:"list"`
729 }
730
731 // TPMLTaggedPCRProperty represents a TPML_TAGGED_PCR_PROPERTY.
732 // See definition in Part 2: Structures, section 10.9.10.
733 type TPMLTaggedPCRProperty struct {
734 marshalByReflection
735 PCRProperty []TPMSTaggedPCRSelect `gotpm:"list"`
736 }
737
738 // TPMLECCCurve represents a TPML_ECC_CURVE.
739 // See definition in Part 2: Structures, section 10.9.11.
740 type TPMLECCCurve struct {
741 marshalByReflection
742 ECCCurves []TPMECCCurve `gotpm:"list"`
743 }
744
745 // TPMLTaggedPolicy represents a TPML_TAGGED_POLICY.
746 // See definition in Part 2: Structures, section 10.9.12.
747 type TPMLTaggedPolicy struct {
748 marshalByReflection
749 Policies []TPMSTaggedPolicy `gotpm:"list"`
750 }
751
752 // TPMLACTData represents a TPML_ACT_DATA.
753 // See definition in Part 2: Structures, section 10.9.13.
754 type TPMLACTData struct {
755 marshalByReflection
756 ACTData []TPMSACTData `gotpm:"list"`
757 }
758
759 // TPMUCapabilities represents a TPMU_CAPABILITIES.
760 // See definition in Part 2: Structures, section 10.10.1.
761 type TPMUCapabilities struct {
762 selector TPMCap
763 contents Marshallable
764 }
765
766 // CapabilitiesContents is a type constraint representing the possible contents of TPMUCapabilities.
767 type CapabilitiesContents interface {
768 Marshallable
769 *TPMLAlgProperty | *TPMLHandle | *TPMLCCA | *TPMLCC | *TPMLPCRSelection | *TPMLTaggedTPMProperty |
770 *TPMLTaggedPCRProperty | *TPMLECCCurve | *TPMLTaggedPolicy | *TPMLACTData
771 }
772
773 // create implements the unmarshallableWithHint interface.
774 func (u *TPMUCapabilities) create(hint int64) (reflect.Value, error) {
775 switch TPMCap(hint) {
776 case TPMCapAlgs:
777 contents := TPMLAlgProperty{}
778 u.contents = &contents
779 u.selector = TPMCap(hint)
780 return reflect.ValueOf(&contents), nil
781 case TPMCapHandles:
782 contents := TPMLHandle{}
783 u.contents = &contents
784 u.selector = TPMCap(hint)
785 return reflect.ValueOf(&contents), nil
786 case TPMCapCommands:
787 contents := TPMLCCA{}
788 u.contents = &contents
789 u.selector = TPMCap(hint)
790 return reflect.ValueOf(&contents), nil
791 case TPMCapPPCommands, TPMCapAuditCommands:
792 contents := TPMLCC{}
793 u.contents = &contents
794 u.selector = TPMCap(hint)
795 return reflect.ValueOf(&contents), nil
796 case TPMCapPCRs:
797 contents := TPMLPCRSelection{}
798 u.contents = &contents
799 u.selector = TPMCap(hint)
800 return reflect.ValueOf(&contents), nil
801 case TPMCapTPMProperties:
802 contents := TPMLTaggedTPMProperty{}
803 u.contents = &contents
804 u.selector = TPMCap(hint)
805 return reflect.ValueOf(&contents), nil
806 case TPMCapPCRProperties:
807 contents := TPMLTaggedPCRProperty{}
808 u.contents = &contents
809 u.selector = TPMCap(hint)
810 return reflect.ValueOf(&contents), nil
811 case TPMCapECCCurves:
812 contents := TPMLECCCurve{}
813 u.contents = &contents
814 u.selector = TPMCap(hint)
815 return reflect.ValueOf(&contents), nil
816 case TPMCapAuthPolicies:
817 contents := TPMLTaggedPolicy{}
818 u.contents = &contents
819 u.selector = TPMCap(hint)
820 return reflect.ValueOf(&contents), nil
821 case TPMCapACT:
822 contents := TPMLACTData{}
823 u.contents = &contents
824 u.selector = TPMCap(hint)
825 return reflect.ValueOf(&contents), nil
826 }
827 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
828 }
829
830 // get implements the marshallableWithHint interface.
831 func (u TPMUCapabilities) get(hint int64) (reflect.Value, error) {
832 if u.selector != 0 && hint != int64(u.selector) {
833 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
834 }
835 switch TPMCap(hint) {
836 case TPMCapAlgs:
837 contents := TPMLAlgProperty{}
838 if u.contents != nil {
839 contents = *u.contents.(*TPMLAlgProperty)
840 }
841 return reflect.ValueOf(&contents), nil
842 case TPMCapHandles:
843 contents := TPMLHandle{}
844 if u.contents != nil {
845 contents = *u.contents.(*TPMLHandle)
846 }
847 return reflect.ValueOf(&contents), nil
848 case TPMCapCommands:
849 contents := TPMLCCA{}
850 if u.contents != nil {
851 contents = *u.contents.(*TPMLCCA)
852 }
853 return reflect.ValueOf(&contents), nil
854 case TPMCapPPCommands, TPMCapAuditCommands:
855 contents := TPMLCC{}
856 if u.contents != nil {
857 contents = *u.contents.(*TPMLCC)
858 }
859 return reflect.ValueOf(&contents), nil
860 case TPMCapPCRs:
861 contents := TPMLPCRSelection{}
862 if u.contents != nil {
863 contents = *u.contents.(*TPMLPCRSelection)
864 }
865 return reflect.ValueOf(&contents), nil
866 case TPMCapTPMProperties:
867 contents := TPMLTaggedTPMProperty{}
868 if u.contents != nil {
869 contents = *u.contents.(*TPMLTaggedTPMProperty)
870 }
871 return reflect.ValueOf(&contents), nil
872 case TPMCapPCRProperties:
873 contents := TPMLTaggedPCRProperty{}
874 if u.contents != nil {
875 contents = *u.contents.(*TPMLTaggedPCRProperty)
876 }
877 return reflect.ValueOf(&contents), nil
878 case TPMCapECCCurves:
879 contents := TPMLECCCurve{}
880 if u.contents != nil {
881 contents = *u.contents.(*TPMLECCCurve)
882 }
883 return reflect.ValueOf(&contents), nil
884 case TPMCapAuthPolicies:
885 contents := TPMLTaggedPolicy{}
886 if u.contents != nil {
887 contents = *u.contents.(*TPMLTaggedPolicy)
888 }
889 return reflect.ValueOf(&contents), nil
890 case TPMCapACT:
891 contents := TPMLACTData{}
892 if u.contents != nil {
893 contents = *u.contents.(*TPMLACTData)
894 }
895 return reflect.ValueOf(&contents), nil
896 }
897 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
898 }
899
900 // NewTPMUCapabilities instantiates a TPMUCapabilities with the given contents.
901 func NewTPMUCapabilities[C CapabilitiesContents](selector TPMCap, contents C) TPMUCapabilities {
902 return TPMUCapabilities{
903 selector: selector,
904 contents: contents,
905 }
906 }
907
908 // Algorithms returns the 'algorithms' member of the union.
909 func (u *TPMUCapabilities) Algorithms() (*TPMLAlgProperty, error) {
910 if u.selector == TPMCapAlgs {
911 return u.contents.(*TPMLAlgProperty), nil
912 }
913 return nil, fmt.Errorf("did not contain algorithms (selector value was %v)", u.selector)
914 }
915
916 // Handles returns the 'handles' member of the union.
917 func (u *TPMUCapabilities) Handles() (*TPMLHandle, error) {
918 if u.selector == TPMCapHandles {
919 return u.contents.(*TPMLHandle), nil
920 }
921 return nil, fmt.Errorf("did not contain handles (selector value was %v)", u.selector)
922 }
923
924 // Command returns the 'command' member of the union.
925 func (u *TPMUCapabilities) Command() (*TPMLCCA, error) {
926 if u.selector == TPMCapCommands {
927 return u.contents.(*TPMLCCA), nil
928 }
929 return nil, fmt.Errorf("did not contain command (selector value was %v)", u.selector)
930 }
931
932 // PPCommands returns the 'ppCommands' member of the union.
933 func (u *TPMUCapabilities) PPCommands() (*TPMLCC, error) {
934 if u.selector == TPMCapPPCommands {
935 return u.contents.(*TPMLCC), nil
936 }
937 return nil, fmt.Errorf("did not contain ppCommands (selector value was %v)", u.selector)
938 }
939
940 // AuditCommands returns the 'auditCommands' member of the union.
941 func (u *TPMUCapabilities) AuditCommands() (*TPMLCC, error) {
942 if u.selector == TPMCapAuditCommands {
943 return u.contents.(*TPMLCC), nil
944 }
945 return nil, fmt.Errorf("did not contain auditCommands (selector value was %v)", u.selector)
946 }
947
948 // AssignedPCR returns the 'assignedPCR' member of the union.
949 func (u *TPMUCapabilities) AssignedPCR() (*TPMLPCRSelection, error) {
950 if u.selector == TPMCapPCRs {
951 return u.contents.(*TPMLPCRSelection), nil
952 }
953 return nil, fmt.Errorf("did not contain assignedPCR (selector value was %v)", u.selector)
954 }
955
956 // TPMProperties returns the 'tpmProperties' member of the union.
957 func (u *TPMUCapabilities) TPMProperties() (*TPMLTaggedTPMProperty, error) {
958 if u.selector == TPMCapTPMProperties {
959 return u.contents.(*TPMLTaggedTPMProperty), nil
960 }
961 return nil, fmt.Errorf("did not contain tpmProperties (selector value was %v)", u.selector)
962 }
963
964 // PCRProperties returns the 'pcrProperties' member of the union.
965 func (u *TPMUCapabilities) PCRProperties() (*TPMLTaggedPCRProperty, error) {
966 if u.selector == TPMCapPCRProperties {
967 return u.contents.(*TPMLTaggedPCRProperty), nil
968 }
969 return nil, fmt.Errorf("did not contain pcrProperties (selector value was %v)", u.selector)
970 }
971
972 // ECCCurves returns the 'eccCurves' member of the union.
973 func (u *TPMUCapabilities) ECCCurves() (*TPMLECCCurve, error) {
974 if u.selector == TPMCapECCCurves {
975 return u.contents.(*TPMLECCCurve), nil
976 }
977 return nil, fmt.Errorf("did not contain eccCurves (selector value was %v)", u.selector)
978 }
979
980 // AuthPolicies returns the 'authPolicies' member of the union.
981 func (u *TPMUCapabilities) AuthPolicies() (*TPMLTaggedPolicy, error) {
982 if u.selector == TPMCapAuthPolicies {
983 return u.contents.(*TPMLTaggedPolicy), nil
984 }
985 return nil, fmt.Errorf("did not contain authPolicies (selector value was %v)", u.selector)
986 }
987
988 // ACTData returns the 'actData' member of the union.
989 func (u *TPMUCapabilities) ACTData() (*TPMLACTData, error) {
990 if u.selector == TPMCapAuthPolicies {
991 return u.contents.(*TPMLACTData), nil
992 }
993 return nil, fmt.Errorf("did not contain actData (selector value was %v)", u.selector)
994 }
995
996 // TPMSCapabilityData represents a TPMS_CAPABILITY_DATA.
997 // See definition in Part 2: Structures, section 10.10.2.
998 type TPMSCapabilityData struct {
999 marshalByReflection
1000 // the capability
1001 Capability TPMCap
1002 // the capability data
1003 Data TPMUCapabilities `gotpm:"tag=Capability"`
1004 }
1005
1006 // TPMSClockInfo represents a TPMS_CLOCK_INFO.
1007 // See definition in Part 2: Structures, section 10.11.1.
1008 type TPMSClockInfo struct {
1009 marshalByReflection
1010 // time value in milliseconds that advances while the TPM is powered
1011 Clock uint64
1012 // number of occurrences of TPM Reset since the last TPM2_Clear()
1013 ResetCount uint32
1014 // number of times that TPM2_Shutdown() or _TPM_Hash_Start have
1015 // occurred since the last TPM Reset or TPM2_Clear().
1016 RestartCount uint32
1017 // no value of Clock greater than the current value of Clock has been
1018 // previously reported by the TPM. Set to YES on TPM2_Clear().
1019 Safe TPMIYesNo
1020 }
1021
1022 // TPMSTimeInfo represents a TPMS_TIMEzINFO.
1023 // See definition in Part 2: Structures, section 10.11.6.
1024 type TPMSTimeInfo struct {
1025 marshalByReflection
1026 // time in milliseconds since the TIme circuit was last reset
1027 Time uint64
1028 // a structure containing the clock information
1029 ClockInfo TPMSClockInfo
1030 }
1031
1032 // TPMSTimeAttestInfo represents a TPMS_TIME_ATTEST_INFO.
1033 // See definition in Part 2: Structures, section 10.12.2.
1034 type TPMSTimeAttestInfo struct {
1035 marshalByReflection
1036 // the Time, Clock, resetCount, restartCount, and Safe indicator
1037 Time TPMSTimeInfo
1038 // a TPM vendor-specific value indicating the version number of the firmware
1039 FirmwareVersion uint64
1040 }
1041
1042 // TPMSCertifyInfo represents a TPMS_CERTIFY_INFO.
1043 // See definition in Part 2: Structures, section 10.12.3.
1044 type TPMSCertifyInfo struct {
1045 marshalByReflection
1046 // Name of the certified object
1047 Name TPM2BName
1048 // Qualified Name of the certified object
1049 QualifiedName TPM2BName
1050 }
1051
1052 // TPMSQuoteInfo represents a TPMS_QUOTE_INFO.
1053 // See definition in Part 2: Structures, section 10.12.4.
1054 type TPMSQuoteInfo struct {
1055 marshalByReflection
1056 // information on algID, PCR selected and digest
1057 PCRSelect TPMLPCRSelection
1058 // digest of the selected PCR using the hash of the signing key
1059 PCRDigest TPM2BDigest
1060 }
1061
1062 // TPMSCommandAuditInfo represents a TPMS_COMMAND_AUDIT_INFO.
1063 // See definition in Part 2: Structures, section 10.12.5.
1064 type TPMSCommandAuditInfo struct {
1065 marshalByReflection
1066 // the monotonic audit counter
1067 AuditCounter uint64
1068 // hash algorithm used for the command audit
1069 DigestAlg TPMAlgID
1070 // the current value of the audit digest
1071 AuditDigest TPM2BDigest
1072 // digest of the command codes being audited using digestAlg
1073 CommandDigest TPM2BDigest
1074 }
1075
1076 // TPMSSessionAuditInfo represents a TPMS_SESSION_AUDIT_INFO.
1077 // See definition in Part 2: Structures, section 10.12.6.
1078 type TPMSSessionAuditInfo struct {
1079 marshalByReflection
1080 // current exclusive status of the session
1081 ExclusiveSession TPMIYesNo
1082 // the current value of the session audit digest
1083 SessionDigest TPM2BDigest
1084 }
1085
1086 // TPMSCreationInfo represents a TPMS_CREATION_INFO.
1087 // See definition in Part 2: Structures, section 10.12.7.
1088 type TPMSCreationInfo struct {
1089 marshalByReflection
1090 // Name of the object
1091 ObjectName TPM2BName
1092 // creationHash
1093 CreationHash TPM2BDigest
1094 }
1095
1096 // TPMSNVCertifyInfo represents a TPMS_NV_CERTIFY_INFO.
1097 // See definition in Part 2: Structures, section 10.12.8.
1098 type TPMSNVCertifyInfo struct {
1099 marshalByReflection
1100 // Name of the NV Index
1101 IndexName TPM2BName
1102 // the offset parameter of TPM2_NV_Certify()
1103 Offset uint16
1104 // contents of the NV Index
1105 NVContents TPM2BData
1106 }
1107
1108 // TPMSNVDigestCertifyInfo represents a TPMS_NV_DIGEST_CERTIFY_INFO.
1109 // See definition in Part 2: Structures, section 10.12.9.
1110 type TPMSNVDigestCertifyInfo struct {
1111 marshalByReflection
1112 // Name of the NV Index
1113 IndexName TPM2BName
1114 // hash of the contents of the index
1115 NVDigest TPM2BDigest
1116 }
1117
1118 // TPMISTAttest represents a TPMI_ST_ATTEST.
1119 // See definition in Part 2: Structures, section 10.12.10.
1120 type TPMISTAttest = TPMST
1121
1122 // TPMUAttest represents a TPMU_ATTEST.
1123 // See definition in Part 2: Structures, section 10.12.11.
1124 type TPMUAttest struct {
1125 selector TPMST
1126 contents Marshallable
1127 }
1128
1129 // AttestContents is a type constraint representing the possible contents of TPMUAttest.
1130 type AttestContents interface {
1131 Marshallable
1132 *TPMSNVCertifyInfo | *TPMSCommandAuditInfo | *TPMSSessionAuditInfo | *TPMSCertifyInfo |
1133 *TPMSQuoteInfo | *TPMSTimeAttestInfo | *TPMSCreationInfo | *TPMSNVDigestCertifyInfo
1134 }
1135
1136 // create implements the unmarshallableWithHint interface.
1137 func (u *TPMUAttest) create(hint int64) (reflect.Value, error) {
1138 switch TPMST(hint) {
1139 case TPMSTAttestNV:
1140 contents := TPMSNVCertifyInfo{}
1141 u.contents = &contents
1142 u.selector = TPMST(hint)
1143 return reflect.ValueOf(&contents), nil
1144 case TPMSTAttestCommandAudit:
1145 contents := TPMSCommandAuditInfo{}
1146 u.contents = &contents
1147 u.selector = TPMST(hint)
1148 return reflect.ValueOf(&contents), nil
1149 case TPMSTAttestSessionAudit:
1150 contents := TPMSSessionAuditInfo{}
1151 u.contents = &contents
1152 u.selector = TPMST(hint)
1153 return reflect.ValueOf(&contents), nil
1154 case TPMSTAttestCertify:
1155 contents := TPMSCertifyInfo{}
1156 u.contents = &contents
1157 u.selector = TPMST(hint)
1158 return reflect.ValueOf(&contents), nil
1159 case TPMSTAttestQuote:
1160 contents := TPMSQuoteInfo{}
1161 u.contents = &contents
1162 u.selector = TPMST(hint)
1163 return reflect.ValueOf(&contents), nil
1164 case TPMSTAttestTime:
1165 contents := TPMSTimeAttestInfo{}
1166 u.contents = &contents
1167 u.selector = TPMST(hint)
1168 return reflect.ValueOf(&contents), nil
1169 case TPMSTAttestCreation:
1170 contents := TPMSCreationInfo{}
1171 u.contents = &contents
1172 u.selector = TPMST(hint)
1173 return reflect.ValueOf(&contents), nil
1174 case TPMSTAttestNVDigest:
1175 contents := TPMSNVDigestCertifyInfo{}
1176 u.contents = &contents
1177 u.selector = TPMST(hint)
1178 return reflect.ValueOf(&contents), nil
1179 }
1180 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1181 }
1182
1183 // get implements the marshallableWithHint interface.
1184 func (u TPMUAttest) get(hint int64) (reflect.Value, error) {
1185 if u.selector != 0 && hint != int64(u.selector) {
1186 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
1187 }
1188 switch TPMST(hint) {
1189 case TPMSTAttestNV:
1190 contents := TPMSNVCertifyInfo{}
1191 if u.contents != nil {
1192 contents = *u.contents.(*TPMSNVCertifyInfo)
1193 }
1194 return reflect.ValueOf(&contents), nil
1195 case TPMSTAttestCommandAudit:
1196 contents := TPMSCommandAuditInfo{}
1197 if u.contents != nil {
1198 contents = *u.contents.(*TPMSCommandAuditInfo)
1199 }
1200 return reflect.ValueOf(&contents), nil
1201 case TPMSTAttestSessionAudit:
1202 contents := TPMSSessionAuditInfo{}
1203 if u.contents != nil {
1204 contents = *u.contents.(*TPMSSessionAuditInfo)
1205 }
1206 return reflect.ValueOf(&contents), nil
1207 case TPMSTAttestCertify:
1208 contents := TPMSCertifyInfo{}
1209 if u.contents != nil {
1210 contents = *u.contents.(*TPMSCertifyInfo)
1211 }
1212 return reflect.ValueOf(&contents), nil
1213 case TPMSTAttestQuote:
1214 contents := TPMSQuoteInfo{}
1215 if u.contents != nil {
1216 contents = *u.contents.(*TPMSQuoteInfo)
1217 }
1218 return reflect.ValueOf(&contents), nil
1219 case TPMSTAttestTime:
1220 contents := TPMSTimeAttestInfo{}
1221 if u.contents != nil {
1222 contents = *u.contents.(*TPMSTimeAttestInfo)
1223 }
1224 return reflect.ValueOf(&contents), nil
1225 case TPMSTAttestCreation:
1226 contents := TPMSCreationInfo{}
1227 if u.contents != nil {
1228 contents = *u.contents.(*TPMSCreationInfo)
1229 }
1230 return reflect.ValueOf(&contents), nil
1231 case TPMSTAttestNVDigest:
1232 contents := TPMSNVDigestCertifyInfo{}
1233 if u.contents != nil {
1234 contents = *u.contents.(*TPMSNVDigestCertifyInfo)
1235 }
1236 return reflect.ValueOf(&contents), nil
1237 }
1238 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1239 }
1240
1241 // NewTPMUAttest instantiates a TPMUAttest with the given contents.
1242 func NewTPMUAttest[C AttestContents](selector TPMST, contents C) TPMUAttest {
1243 return TPMUAttest{
1244 selector: selector,
1245 contents: contents,
1246 }
1247 }
1248
1249 // Certify returns the 'certify' member of the union.
1250 func (u *TPMUAttest) Certify() (*TPMSCertifyInfo, error) {
1251 if u.selector == TPMSTAttestCertify {
1252 return u.contents.(*TPMSCertifyInfo), nil
1253 }
1254 return nil, fmt.Errorf("did not contain certify (selector value was %v)", u.selector)
1255 }
1256
1257 // Creation returns the 'creation' member of the union.
1258 func (u *TPMUAttest) Creation() (*TPMSCreationInfo, error) {
1259 if u.selector == TPMSTAttestCreation {
1260 return u.contents.(*TPMSCreationInfo), nil
1261 }
1262 return nil, fmt.Errorf("did not contain creation (selector value was %v)", u.selector)
1263 }
1264
1265 // Quote returns the 'quote' member of the union.
1266 func (u *TPMUAttest) Quote() (*TPMSQuoteInfo, error) {
1267 if u.selector == TPMSTAttestQuote {
1268 return u.contents.(*TPMSQuoteInfo), nil
1269 }
1270 return nil, fmt.Errorf("did not contain quote (selector value was %v)", u.selector)
1271 }
1272
1273 // CommandAudit returns the 'commandAudit' member of the union.
1274 func (u *TPMUAttest) CommandAudit() (*TPMSCommandAuditInfo, error) {
1275 if u.selector == TPMSTAttestCommandAudit {
1276 return u.contents.(*TPMSCommandAuditInfo), nil
1277 }
1278 return nil, fmt.Errorf("did not contain commandAudit (selector value was %v)", u.selector)
1279 }
1280
1281 // SessionAudit returns the 'sessionAudit' member of the union.
1282 func (u *TPMUAttest) SessionAudit() (*TPMSSessionAuditInfo, error) {
1283 if u.selector == TPMSTAttestSessionAudit {
1284 return u.contents.(*TPMSSessionAuditInfo), nil
1285 }
1286 return nil, fmt.Errorf("did not contain sessionAudit (selector value was %v)", u.selector)
1287 }
1288
1289 // Time returns the 'time' member of the union.
1290 func (u *TPMUAttest) Time() (*TPMSTimeAttestInfo, error) {
1291 if u.selector == TPMSTAttestTime {
1292 return u.contents.(*TPMSTimeAttestInfo), nil
1293 }
1294 return nil, fmt.Errorf("did not contain time (selector value was %v)", u.selector)
1295 }
1296
1297 // NV returns the 'nv' member of the union.
1298 func (u *TPMUAttest) NV() (*TPMSNVCertifyInfo, error) {
1299 if u.selector == TPMSTAttestNV {
1300 return u.contents.(*TPMSNVCertifyInfo), nil
1301 }
1302 return nil, fmt.Errorf("did not contain nv (selector value was %v)", u.selector)
1303 }
1304
1305 // NVDigest returns the 'nvDigest' member of the union.
1306 func (u *TPMUAttest) NVDigest() (*TPMSNVDigestCertifyInfo, error) {
1307 if u.selector == TPMSTAttestNVDigest {
1308 return u.contents.(*TPMSNVDigestCertifyInfo), nil
1309 }
1310 return nil, fmt.Errorf("did not contain nvDigest (selector value was %v)", u.selector)
1311 }
1312
1313 // TPMSAttest represents a TPMS_ATTEST.
1314 // See definition in Part 2: Structures, section 10.12.12.
1315 type TPMSAttest struct {
1316 marshalByReflection
1317 // the indication that this structure was created by a TPM (always TPM_GENERATED_VALUE)
1318 Magic TPMGenerated `gotpm:"check"`
1319 // type of the attestation structure
1320 Type TPMISTAttest
1321 // Qualified Name of the signing key
1322 QualifiedSigner TPM2BName
1323 // external information supplied by caller
1324 ExtraData TPM2BData
1325 // Clock, resetCount, restartCount, and Safe
1326 ClockInfo TPMSClockInfo
1327 // TPM-vendor-specific value identifying the version number of the firmware
1328 FirmwareVersion uint64
1329 // the type-specific attestation information
1330 Attested TPMUAttest `gotpm:"tag=Type"`
1331 }
1332
1333 // TPM2BAttest represents a TPM2B_ATTEST.
1334 // See definition in Part 2: Structures, section 10.12.13.
1335 type TPM2BAttest = TPM2B[TPMSAttest, *TPMSAttest]
1336
1337 // TPMSAuthCommand represents a TPMS_AUTH_COMMAND.
1338 // See definition in Part 2: Structures, section 10.13.2.
1339 type TPMSAuthCommand struct {
1340 marshalByReflection
1341 Handle TPMISHAuthSession
1342 Nonce TPM2BNonce
1343 Attributes TPMASession
1344 Authorization TPM2BData
1345 }
1346
1347 // TPMSAuthResponse represents a TPMS_AUTH_RESPONSE.
1348 // See definition in Part 2: Structures, section 10.13.3.
1349 type TPMSAuthResponse struct {
1350 marshalByReflection
1351 Nonce TPM2BNonce
1352 Attributes TPMASession
1353 Authorization TPM2BData
1354 }
1355
1356 // TPMUSymKeyBits represents a TPMU_SYM_KEY_BITS.
1357 // See definition in Part 2: Structures, section 11.1.3.
1358 type TPMUSymKeyBits struct {
1359 selector TPMAlgID
1360 contents Marshallable
1361 }
1362
1363 // SymKeyBitsContents is a type constraint representing the possible contents of TPMUSymKeyBits.
1364 type SymKeyBitsContents interface {
1365 TPMKeyBits | TPMAlgID
1366 }
1367
1368 // create implements the unmarshallableWithHint interface.
1369 func (u *TPMUSymKeyBits) create(hint int64) (reflect.Value, error) {
1370 switch TPMAlgID(hint) {
1371 case TPMAlgTDES, TPMAlgAES, TPMAlgSM4, TPMAlgCamellia:
1372 var contents boxed[TPMKeyBits]
1373 u.contents = &contents
1374 u.selector = TPMAlgID(hint)
1375 return reflect.ValueOf(&contents), nil
1376 case TPMAlgXOR:
1377 var contents boxed[TPMAlgID]
1378 u.contents = &contents
1379 u.selector = TPMAlgID(hint)
1380 return reflect.ValueOf(&contents), nil
1381 }
1382 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1383 }
1384
1385 // get implements the marshallableWithHint interface.
1386 func (u TPMUSymKeyBits) get(hint int64) (reflect.Value, error) {
1387 if u.selector != 0 && hint != int64(u.selector) {
1388 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
1389 }
1390 switch TPMAlgID(hint) {
1391 case TPMAlgTDES, TPMAlgAES, TPMAlgSM4, TPMAlgCamellia:
1392 var contents boxed[TPMKeyBits]
1393 if u.contents != nil {
1394 contents = *u.contents.(*boxed[TPMKeyBits])
1395 }
1396 return reflect.ValueOf(&contents), nil
1397 case TPMAlgXOR:
1398 var contents boxed[TPMAlgID]
1399 if u.contents != nil {
1400 contents = *u.contents.(*boxed[TPMAlgID])
1401 }
1402 return reflect.ValueOf(&contents), nil
1403 }
1404 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1405 }
1406
1407 // NewTPMUSymKeyBits instantiates a TPMUSymKeyBits with the given contents.
1408 func NewTPMUSymKeyBits[C SymKeyBitsContents](selector TPMAlgID, contents C) TPMUSymKeyBits {
1409 boxed := box(&contents)
1410 return TPMUSymKeyBits{
1411 selector: selector,
1412 contents: &boxed,
1413 }
1414 }
1415
1416 // Sym returns the 'sym' member of the union.
1417 func (u *TPMUSymKeyBits) Sym() (*TPMKeyBits, error) {
1418
1419 switch u.selector {
1420 case TPMAlgTDES, TPMAlgAES, TPMAlgSM4, TPMAlgCamellia:
1421 value := u.contents.(*boxed[TPMKeyBits]).unbox()
1422 return value, nil
1423 default:
1424 return nil, fmt.Errorf("did not contain sym (selector value was %v)", u.selector)
1425 }
1426 }
1427
1428 // AES returns the 'aes' member of the union.
1429 func (u *TPMUSymKeyBits) AES() (*TPMKeyBits, error) {
1430 if u.selector == TPMAlgAES {
1431 value := u.contents.(*boxed[TPMKeyBits]).unbox()
1432 return value, nil
1433 }
1434 return nil, fmt.Errorf("did not contain aes (selector value was %v)", u.selector)
1435 }
1436
1437 // TDES returns the 'tdes' member of the union.
1438 //
1439 // Deprecated: TDES exists for historical compatibility
1440 // and is not recommended anymore.
1441 // https://csrc.nist.gov/news/2023/nist-to-withdraw-sp-800-67-rev-2
1442 func (u *TPMUSymKeyBits) TDES() (*TPMKeyBits, error) {
1443 if u.selector == TPMAlgTDES {
1444 value := u.contents.(*boxed[TPMKeyBits]).unbox()
1445 return value, nil
1446 }
1447 return nil, fmt.Errorf("did not contain tdes (selector value was %v)", u.selector)
1448 }
1449
1450 // SM4 returns the 'sm4' member of the union.
1451 func (u *TPMUSymKeyBits) SM4() (*TPMKeyBits, error) {
1452 if u.selector == TPMAlgSM4 {
1453 value := u.contents.(*boxed[TPMKeyBits]).unbox()
1454 return value, nil
1455 }
1456 return nil, fmt.Errorf("did not contain sm4 (selector value was %v)", u.selector)
1457 }
1458
1459 // Camellia returns the 'camellia' member of the union.
1460 func (u *TPMUSymKeyBits) Camellia() (*TPMKeyBits, error) {
1461 if u.selector == TPMAlgCamellia {
1462 value := u.contents.(*boxed[TPMKeyBits]).unbox()
1463 return value, nil
1464 }
1465 return nil, fmt.Errorf("did not contain camellia (selector value was %v)", u.selector)
1466 }
1467
1468 // XOR returns the 'xor' member of the union.
1469 func (u *TPMUSymKeyBits) XOR() (*TPMAlgID, error) {
1470 if u.selector == TPMAlgXOR {
1471 value := u.contents.(*boxed[TPMAlgID]).unbox()
1472 return value, nil
1473 }
1474 return nil, fmt.Errorf("did not contain xor (selector value was %v)", u.selector)
1475 }
1476
1477 // TPMUSymMode represents a TPMU_SYM_MODE.
1478 // See definition in Part 2: Structures, section 11.1.4.
1479 type TPMUSymMode struct {
1480 selector TPMAlgID
1481 contents Marshallable
1482 }
1483
1484 // SymModeContents is a type constraint representing the possible contents of TPMUSymMode.
1485 type SymModeContents interface {
1486 TPMIAlgSymMode | TPMSEmpty
1487 }
1488
1489 // create implements the unmarshallableWithHint interface.
1490 func (u *TPMUSymMode) create(hint int64) (reflect.Value, error) {
1491 switch TPMAlgID(hint) {
1492 case TPMAlgTDES, TPMAlgAES, TPMAlgSM4, TPMAlgCamellia:
1493 var contents boxed[TPMAlgID]
1494 u.contents = &contents
1495 u.selector = TPMAlgID(hint)
1496 return reflect.ValueOf(&contents), nil
1497 case TPMAlgXOR:
1498 var contents boxed[TPMSEmpty]
1499 u.contents = &contents
1500 u.selector = TPMAlgID(hint)
1501 return reflect.ValueOf(&contents), nil
1502 }
1503 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1504 }
1505
1506 // get implements the marshallableWithHint interface.
1507 func (u TPMUSymMode) get(hint int64) (reflect.Value, error) {
1508 if u.selector != 0 && hint != int64(u.selector) {
1509 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
1510 }
1511 switch TPMAlgID(hint) {
1512 case TPMAlgTDES, TPMAlgAES, TPMAlgSM4, TPMAlgCamellia:
1513 var contents boxed[TPMAlgID]
1514 if u.contents != nil {
1515 contents = *u.contents.(*boxed[TPMAlgID])
1516 }
1517 return reflect.ValueOf(&contents), nil
1518 case TPMAlgXOR:
1519 var contents boxed[TPMSEmpty]
1520 if u.contents != nil {
1521 contents = *u.contents.(*boxed[TPMSEmpty])
1522 }
1523 return reflect.ValueOf(&contents), nil
1524 }
1525 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1526 }
1527
1528 // NewTPMUSymMode instantiates a TPMUSymMode with the given contents.
1529 func NewTPMUSymMode[C SymModeContents](selector TPMAlgID, contents C) TPMUSymMode {
1530 boxed := box(&contents)
1531 return TPMUSymMode{
1532 selector: selector,
1533 contents: &boxed,
1534 }
1535 }
1536
1537 // Sym returns the 'sym' member of the union.
1538 func (u *TPMUSymMode) Sym() (*TPMIAlgSymMode, error) {
1539 switch u.selector {
1540 case TPMAlgTDES, TPMAlgAES, TPMAlgSM4, TPMAlgCamellia:
1541 value := u.contents.(*boxed[TPMIAlgSymMode]).unbox()
1542 return value, nil
1543 default:
1544 return nil, fmt.Errorf("did not contain sym (selector value was %v)", u.selector)
1545 }
1546 }
1547
1548 // AES returns the 'aes' member of the union.
1549 func (u *TPMUSymMode) AES() (*TPMIAlgSymMode, error) {
1550 if u.selector == TPMAlgAES {
1551 value := u.contents.(*boxed[TPMIAlgSymMode]).unbox()
1552 return value, nil
1553 }
1554 return nil, fmt.Errorf("did not contain aes (selector value was %v)", u.selector)
1555 }
1556
1557 // TDES returns the 'tdes' member of the union.
1558 //
1559 // Deprecated: TDES exists for historical compatibility
1560 // and is not recommended anymore.
1561 // https://csrc.nist.gov/news/2023/nist-to-withdraw-sp-800-67-rev-2
1562 func (u *TPMUSymMode) TDES() (*TPMIAlgSymMode, error) {
1563 if u.selector == TPMAlgTDES {
1564 value := u.contents.(*boxed[TPMIAlgSymMode]).unbox()
1565 return value, nil
1566 }
1567 return nil, fmt.Errorf("did not contain tdes (selector value was %v)", u.selector)
1568 }
1569
1570 // SM4 returns the 'sm4' member of the union.
1571 func (u *TPMUSymMode) SM4() (*TPMIAlgSymMode, error) {
1572 if u.selector == TPMAlgSM4 {
1573 value := u.contents.(*boxed[TPMIAlgSymMode]).unbox()
1574 return value, nil
1575 }
1576 return nil, fmt.Errorf("did not contain sm4 (selector value was %v)", u.selector)
1577 }
1578
1579 // Camellia returns the 'camellia' member of the union.
1580 func (u *TPMUSymMode) Camellia() (*TPMIAlgSymMode, error) {
1581 if u.selector == TPMAlgCamellia {
1582 value := u.contents.(*boxed[TPMIAlgSymMode]).unbox()
1583 return value, nil
1584 }
1585 return nil, fmt.Errorf("did not contain camellia (selector value was %v)", u.selector)
1586 }
1587
1588 // TPMUSymDetails represents a TPMU_SYM_DETAILS.
1589 // See definition in Part 2: Structures, section 11.1.5.
1590 type TPMUSymDetails struct {
1591 selector TPMAlgID
1592 contents Marshallable
1593 }
1594
1595 // SymDetailsContents is a type constraint representing the possible contents of TPMUSymDetails.
1596 type SymDetailsContents interface {
1597 TPMSEmpty
1598 }
1599
1600 // create implements the unmarshallableWithHint interface.
1601 func (u *TPMUSymDetails) create(hint int64) (reflect.Value, error) {
1602 switch TPMAlgID(hint) {
1603 case TPMAlgAES:
1604 var contents boxed[TPMSEmpty]
1605 u.contents = &contents
1606 u.selector = TPMAlgID(hint)
1607 return reflect.ValueOf(&contents), nil
1608 case TPMAlgXOR:
1609 var contents boxed[TPMSEmpty]
1610 u.contents = &contents
1611 u.selector = TPMAlgID(hint)
1612 return reflect.ValueOf(&contents), nil
1613 }
1614 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1615 }
1616
1617 // get implements the marshallableWithHint interface.
1618 func (u TPMUSymDetails) get(hint int64) (reflect.Value, error) {
1619 if u.selector != 0 && hint != int64(u.selector) {
1620 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
1621 }
1622 switch TPMAlgID(hint) {
1623 case TPMAlgAES, TPMAlgXOR:
1624 var contents boxed[TPMSEmpty]
1625 if u.contents != nil {
1626 contents = *u.contents.(*boxed[TPMSEmpty])
1627 }
1628 return reflect.ValueOf(&contents), nil
1629 }
1630 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1631 }
1632
1633 // NewTPMUSymDetails instantiates a TPMUSymDetails with the given contents.
1634 func NewTPMUSymDetails[C SymDetailsContents](selector TPMAlgID, contents C) TPMUSymMode {
1635 boxed := box(&contents)
1636 return TPMUSymMode{
1637 selector: selector,
1638 contents: &boxed,
1639 }
1640 }
1641
1642 // TPMTSymDef represents a TPMT_SYM_DEF.
1643 // See definition in Part 2: Structures, section 11.1.6.
1644 type TPMTSymDef struct {
1645 marshalByReflection
1646 // indicates a symmetric algorithm
1647 Algorithm TPMIAlgSym `gotpm:"nullable"`
1648 // the key size
1649 KeyBits TPMUSymKeyBits `gotpm:"tag=Algorithm"`
1650 // the mode for the key
1651 Mode TPMUSymMode `gotpm:"tag=Algorithm"`
1652 // contains the additional algorithm details
1653 Details TPMUSymDetails `gotpm:"tag=Algorithm"`
1654 }
1655
1656 // TPMTSymDefObject represents a TPMT_SYM_DEF_OBJECT.
1657 // See definition in Part 2: Structures, section 11.1.7.
1658 type TPMTSymDefObject struct {
1659 marshalByReflection
1660 // selects a symmetric block cipher
1661 // When used in the parameter area of a parent object, this shall
1662 // be a supported block cipher and not TPM_ALG_NULL
1663 Algorithm TPMIAlgSymObject `gotpm:"nullable"`
1664 // the key size
1665 KeyBits TPMUSymKeyBits `gotpm:"tag=Algorithm"`
1666 // default mode
1667 // When used in the parameter area of a parent object, this shall
1668 // be TPM_ALG_CFB.
1669 Mode TPMUSymMode `gotpm:"tag=Algorithm"`
1670 // contains the additional algorithm details, if any
1671 Details TPMUSymDetails `gotpm:"tag=Algorithm"`
1672 }
1673
1674 // TPM2BSymKey represents a TPM2B_SYM_KEY.
1675 // See definition in Part 2: Structures, section 11.1.8.
1676 type TPM2BSymKey TPM2BData
1677
1678 // TPMSSymCipherParms represents a TPMS_SYMCIPHER_PARMS.
1679 // See definition in Part 2: Structures, section 11.1.9.
1680 type TPMSSymCipherParms struct {
1681 marshalByReflection
1682 // a symmetric block cipher
1683 Sym TPMTSymDefObject
1684 }
1685
1686 // TPM2BLabel represents a TPM2B_LABEL.
1687 // See definition in Part 2: Structures, section 11.1.10.
1688 type TPM2BLabel TPM2BData
1689
1690 // TPMSDerive represents a TPMS_DERIVE.
1691 // See definition in Part 2: Structures, section 11.1.11.
1692 type TPMSDerive struct {
1693 marshalByReflection
1694 Label TPM2BLabel
1695 Context TPM2BLabel
1696 }
1697
1698 // TPM2BDerive represents a TPM2B_DERIVE.
1699 // See definition in Part 2: Structures, section 11.1.12.
1700 type TPM2BDerive = TPM2B[TPMSDerive, *TPMSDerive]
1701
1702 // TPMUSensitiveCreate represents a TPMU_SENSITIVE_CREATE.
1703 // See definition in Part 2: Structures, section 11.1.13.
1704 type TPMUSensitiveCreate struct {
1705 contents Marshallable
1706 }
1707
1708 // SensitiveCreateContents is a type constraint representing the possible contents of TPMUSensitiveCreate.
1709 type SensitiveCreateContents interface {
1710 Marshallable
1711 *TPM2BDerive | *TPM2BSensitiveData
1712 }
1713
1714 // marshal implements the Marshallable interface.
1715 func (u TPMUSensitiveCreate) marshal(buf *bytes.Buffer) {
1716 if u.contents != nil {
1717 buf.Write(Marshal(u.contents))
1718 } else {
1719 // If this is a zero-valued structure, marshal a default TPM2BSensitiveData.
1720 var defaultValue TPM2BSensitiveData
1721 buf.Write(Marshal(&defaultValue))
1722 }
1723 }
1724
1725 // NewTPMUSensitiveCreate instantiates a TPMUSensitiveCreate with the given contents.
1726 func NewTPMUSensitiveCreate[C SensitiveCreateContents](contents C) TPMUSensitiveCreate {
1727 return TPMUSensitiveCreate{contents: contents}
1728 }
1729
1730 // TPM2BSensitiveData represents a TPM2B_SENSITIVE_DATA.
1731 // See definition in Part 2: Structures, section 11.1.14.
1732 type TPM2BSensitiveData TPM2BData
1733
1734 // TPMSSensitiveCreate represents a TPMS_SENSITIVE_CREATE.
1735 // See definition in Part 2: Structures, section 11.1.15.
1736 type TPMSSensitiveCreate struct {
1737 marshalByReflection
1738 // the USER auth secret value.
1739 UserAuth TPM2BAuth
1740 // data to be sealed, a key, or derivation values.
1741 Data TPMUSensitiveCreate
1742 }
1743
1744 // TPM2BSensitiveCreate represents a TPM2B_SENSITIVE_CREATE.
1745 // See definition in Part 2: Structures, section 11.1.16.
1746 // This is a structure instead of an alias to TPM2B[TPMSSensitiveCreate],
1747 // because it has custom marshalling logic for zero-valued parameters.
1748 type TPM2BSensitiveCreate struct {
1749 Sensitive *TPMSSensitiveCreate
1750 }
1751
1752 // Quirk: When this structure is zero-valued, we need to marshal
1753 // a 2B-wrapped zero-valued TPMS_SENSITIVE_CREATE instead of
1754 // [0x00, 0x00] (a zero-valued 2B).
1755 func (c TPM2BSensitiveCreate) marshal(buf *bytes.Buffer) {
1756 var marshalled TPM2B[TPMSSensitiveCreate, *TPMSSensitiveCreate]
1757 if c.Sensitive != nil {
1758 marshalled = New2B(*c.Sensitive)
1759 } else {
1760 // If no value was provided (i.e., this is a zero-valued structure),
1761 // provide an 2B containing a zero-valued TPMS_SensitiveCreate.
1762 marshalled = New2B(TPMSSensitiveCreate{
1763 Data: NewTPMUSensitiveCreate(&TPM2BSensitiveData{}),
1764 })
1765 }
1766 marshalled.marshal(buf)
1767 }
1768
1769 // TPMSSchemeHash represents a TPMS_SCHEME_HASH.
1770 // See definition in Part 2: Structures, section 11.1.17.
1771 type TPMSSchemeHash struct {
1772 marshalByReflection
1773 // the hash algorithm used to digest the message
1774 HashAlg TPMIAlgHash
1775 }
1776
1777 // TPMSSchemeECDAA represents a TPMS_SCHEME_ECDAA.
1778 // See definition in Part 2: Structures, section 11.1.18.
1779 type TPMSSchemeECDAA struct {
1780 marshalByReflection
1781 // the hash algorithm used to digest the message
1782 HashAlg TPMIAlgHash
1783 // the counter value that is used between TPM2_Commit()
1784 // and the sign operation
1785 Count uint16
1786 }
1787
1788 // TPMIAlgKeyedHashScheme represents a TPMI_ALG_KEYEDHASH_SCHEME.
1789 // See definition in Part 2: Structures, section 11.1.19.
1790 type TPMIAlgKeyedHashScheme = TPMAlgID
1791
1792 // TPMSSchemeHMAC represents a TPMS_SCHEME_HMAC.
1793 // See definition in Part 2: Structures, section 11.1.20.
1794 type TPMSSchemeHMAC TPMSSchemeHash
1795
1796 // TPMSSchemeXOR represents a TPMS_SCHEME_XOR.
1797 // See definition in Part 2: Structures, section 11.1.21.
1798 type TPMSSchemeXOR struct {
1799 marshalByReflection
1800 // the hash algorithm used to digest the message
1801 HashAlg TPMIAlgHash
1802 // the key derivation function
1803 KDF TPMIAlgKDF
1804 }
1805
1806 // TPMUSchemeKeyedHash represents a TPMU_SCHEME_KEYEDHASH.
1807 // See definition in Part 2: Structures, section 11.1.22.
1808 type TPMUSchemeKeyedHash struct {
1809 selector TPMAlgID
1810 contents Marshallable
1811 }
1812
1813 // SchemeKeyedHashContents is a type constraint representing the possible contents of TPMUSchemeKeyedHash.
1814 type SchemeKeyedHashContents interface {
1815 Marshallable
1816 *TPMSSchemeHMAC | *TPMSSchemeXOR
1817 }
1818
1819 // create implements the unmarshallableWithHint interface.
1820 func (u *TPMUSchemeKeyedHash) create(hint int64) (reflect.Value, error) {
1821 switch TPMAlgID(hint) {
1822 case TPMAlgHMAC:
1823 var contents TPMSSchemeHMAC
1824 u.contents = &contents
1825 u.selector = TPMAlgID(hint)
1826 return reflect.ValueOf(&contents), nil
1827 case TPMAlgXOR:
1828 var contents TPMSSchemeXOR
1829 u.contents = &contents
1830 u.selector = TPMAlgID(hint)
1831 return reflect.ValueOf(&contents), nil
1832 }
1833 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1834 }
1835
1836 // get implements the marshallableWithHint interface.
1837 func (u TPMUSchemeKeyedHash) get(hint int64) (reflect.Value, error) {
1838 if u.selector != 0 && hint != int64(u.selector) {
1839 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
1840 }
1841 switch TPMAlgID(hint) {
1842 case TPMAlgHMAC:
1843 var contents TPMSSchemeHMAC
1844 if u.contents != nil {
1845 contents = *u.contents.(*TPMSSchemeHMAC)
1846 }
1847 return reflect.ValueOf(&contents), nil
1848 case TPMAlgXOR:
1849 var contents TPMSSchemeXOR
1850 if u.contents != nil {
1851 contents = *u.contents.(*TPMSSchemeXOR)
1852 }
1853 return reflect.ValueOf(&contents), nil
1854 }
1855 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1856 }
1857
1858 // NewTPMUSchemeKeyedHash instantiates a TPMUSchemeKeyedHash with the given contents.
1859 func NewTPMUSchemeKeyedHash[C SchemeKeyedHashContents](selector TPMAlgID, contents C) TPMUSchemeKeyedHash {
1860 return TPMUSchemeKeyedHash{
1861 selector: selector,
1862 contents: contents,
1863 }
1864 }
1865
1866 // HMAC returns the 'hmac' member of the union.
1867 func (u *TPMUSchemeKeyedHash) HMAC() (*TPMSSchemeHMAC, error) {
1868 if u.selector == TPMAlgHMAC {
1869 value := u.contents.(*TPMSSchemeHMAC)
1870 return value, nil
1871 }
1872 return nil, fmt.Errorf("did not contain hmac (selector value was %v)", u.selector)
1873 }
1874
1875 // XOR returns the 'xor' member of the union.
1876 func (u *TPMUSchemeKeyedHash) XOR() (*TPMSSchemeXOR, error) {
1877 if u.selector == TPMAlgXOR {
1878 value := u.contents.(*TPMSSchemeXOR)
1879 return value, nil
1880 }
1881 return nil, fmt.Errorf("did not contain xor (selector value was %v)", u.selector)
1882 }
1883
1884 // TPMTKeyedHashScheme represents a TPMT_KEYEDHASH_SCHEME.
1885 // See definition in Part 2: Structures, section 11.1.23.
1886 type TPMTKeyedHashScheme struct {
1887 marshalByReflection
1888 Scheme TPMIAlgKeyedHashScheme `gotpm:"nullable"`
1889 Details TPMUSchemeKeyedHash `gotpm:"tag=Scheme"`
1890 }
1891
1892 // TPMSSigSchemeRSASSA represents a TPMS_SIG_SCHEME_RSASSA.
1893 // See definition in Part 2: Structures, section 11.2.1.2.
1894 type TPMSSigSchemeRSASSA TPMSSchemeHash
1895
1896 // TPMSSigSchemeRSAPSS represents a TPMS_SIG_SCHEME_RSAPSS.
1897 // See definition in Part 2: Structures, section 11.2.1.2.
1898 type TPMSSigSchemeRSAPSS TPMSSchemeHash
1899
1900 // TPMSSigSchemeECDSA represents a TPMS_SIG_SCHEME_ECDSA.
1901 // See definition in Part 2: Structures, section 11.2.1.3.
1902 type TPMSSigSchemeECDSA TPMSSchemeHash
1903
1904 // TPMUSigScheme represents a TPMU_SIG_SCHEME.
1905 // See definition in Part 2: Structures, section 11.2.1.4.
1906 type TPMUSigScheme struct {
1907 selector TPMAlgID
1908 contents Marshallable
1909 }
1910
1911 // SigSchemeContents is a type constraint representing the possible contents of TPMUSigScheme.
1912 type SigSchemeContents interface {
1913 Marshallable
1914 *TPMSSchemeHMAC | *TPMSSchemeHash | *TPMSSchemeECDAA
1915 }
1916
1917 // create implements the unmarshallableWithHint interface.
1918 func (u *TPMUSigScheme) create(hint int64) (reflect.Value, error) {
1919 switch TPMAlgID(hint) {
1920 case TPMAlgHMAC:
1921 var contents TPMSSchemeHMAC
1922 u.contents = &contents
1923 u.selector = TPMAlgID(hint)
1924 return reflect.ValueOf(&contents), nil
1925 case TPMAlgRSASSA, TPMAlgRSAPSS, TPMAlgECDSA:
1926 var contents TPMSSchemeHash
1927 u.contents = &contents
1928 u.selector = TPMAlgID(hint)
1929 return reflect.ValueOf(&contents), nil
1930 case TPMAlgECDAA:
1931 var contents TPMSSchemeECDAA
1932 u.contents = &contents
1933 u.selector = TPMAlgID(hint)
1934 return reflect.ValueOf(&contents), nil
1935 }
1936 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1937 }
1938
1939 // get implements the marshallableWithHint interface.
1940 func (u TPMUSigScheme) get(hint int64) (reflect.Value, error) {
1941 if u.selector != 0 && hint != int64(u.selector) {
1942 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
1943 }
1944 switch TPMAlgID(hint) {
1945 case TPMAlgHMAC:
1946 var contents TPMSSchemeHMAC
1947 if u.contents != nil {
1948 contents = *u.contents.(*TPMSSchemeHMAC)
1949 }
1950 return reflect.ValueOf(&contents), nil
1951 case TPMAlgRSASSA, TPMAlgRSAPSS, TPMAlgECDSA:
1952 var contents TPMSSchemeHash
1953 if u.contents != nil {
1954 contents = *u.contents.(*TPMSSchemeHash)
1955 }
1956 return reflect.ValueOf(&contents), nil
1957 case TPMAlgECDAA:
1958 var contents TPMSSchemeECDAA
1959 if u.contents != nil {
1960 contents = *u.contents.(*TPMSSchemeECDAA)
1961 }
1962 return reflect.ValueOf(&contents), nil
1963 }
1964 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
1965 }
1966
1967 // NewTPMUSigScheme instantiates a TPMUSigScheme with the given contents.
1968 func NewTPMUSigScheme[C SigSchemeContents](selector TPMAlgID, contents C) TPMUSigScheme {
1969 return TPMUSigScheme{
1970 selector: selector,
1971 contents: contents,
1972 }
1973 }
1974
1975 // HMAC returns the 'hmac' member of the union.
1976 func (u *TPMUSigScheme) HMAC() (*TPMSSchemeHMAC, error) {
1977 if u.selector == TPMAlgHMAC {
1978 return u.contents.(*TPMSSchemeHMAC), nil
1979 }
1980 return nil, fmt.Errorf("did not contain hmac (selector value was %v)", u.selector)
1981 }
1982
1983 // RSASSA returns the 'rsassa' member of the union.
1984 func (u *TPMUSigScheme) RSASSA() (*TPMSSchemeHash, error) {
1985 if u.selector == TPMAlgRSASSA {
1986 return u.contents.(*TPMSSchemeHash), nil
1987 }
1988 return nil, fmt.Errorf("did not contain rsassa (selector value was %v)", u.selector)
1989 }
1990
1991 // RSAPSS returns the 'rsapss' member of the union.
1992 func (u *TPMUSigScheme) RSAPSS() (*TPMSSchemeHash, error) {
1993 if u.selector == TPMAlgRSAPSS {
1994 return u.contents.(*TPMSSchemeHash), nil
1995 }
1996 return nil, fmt.Errorf("did not contain rsapss (selector value was %v)", u.selector)
1997 }
1998
1999 // ECDSA returns the 'ecdsa' member of the union.
2000 func (u *TPMUSigScheme) ECDSA() (*TPMSSchemeHash, error) {
2001 if u.selector == TPMAlgECDSA {
2002 return u.contents.(*TPMSSchemeHash), nil
2003 }
2004 return nil, fmt.Errorf("did not contain ecdsa (selector value was %v)", u.selector)
2005 }
2006
2007 // ECDAA returns the 'ecdaa' member of the union.
2008 func (u *TPMUSigScheme) ECDAA() (*TPMSSchemeECDAA, error) {
2009 if u.selector == TPMAlgECDAA {
2010 return u.contents.(*TPMSSchemeECDAA), nil
2011 }
2012 return nil, fmt.Errorf("did not contain ecdaa (selector value was %v)", u.selector)
2013 }
2014
2015 // TPMTSigScheme represents a TPMT_SIG_SCHEME.
2016 // See definition in Part 2: Structures, section 11.2.1.5.
2017 type TPMTSigScheme struct {
2018 marshalByReflection
2019 Scheme TPMIAlgSigScheme `gotpm:"nullable"`
2020 Details TPMUSigScheme `gotpm:"tag=Scheme"`
2021 }
2022
2023 // TPMSEncSchemeRSAES represents a TPMS_ENC_SCHEME_RSAES.
2024 // See definition in Part 2: Structures, section 11.2.2.2.
2025 type TPMSEncSchemeRSAES TPMSEmpty
2026
2027 // TPMSEncSchemeOAEP represents a TPMS_ENC_SCHEME_OAEP.
2028 // See definition in Part 2: Structures, section 11.2.2.2.
2029 type TPMSEncSchemeOAEP TPMSSchemeHash
2030
2031 // TPMSKeySchemeECDH represents a TPMS_KEY_SCHEME_ECDH.
2032 // See definition in Part 2: Structures, section 11.2.2.3.
2033 type TPMSKeySchemeECDH TPMSSchemeHash
2034
2035 // TPMSKeySchemeECMQV represents a TPMS_KEY_SCHEME_ECMQV.
2036 // See definition in Part 2: Structures, section 11.2.2.3.
2037 type TPMSKeySchemeECMQV TPMSSchemeHash
2038
2039 // TPMSKDFSchemeMGF1 represents a TPMS_KDF_SCHEME_MGF1.
2040 // See definition in Part 2: Structures, section 11.2.3.1.
2041 type TPMSKDFSchemeMGF1 TPMSSchemeHash
2042
2043 // TPMSKDFSchemeECDH represents a TPMS_KDF_SCHEME_ECDH.
2044 // See definition in Part 2: Structures, section 11.2.3.1.
2045 type TPMSKDFSchemeECDH TPMSSchemeHash
2046
2047 // TPMSKDFSchemeKDF1SP80056A represents a TPMS_KDF_SCHEME_KDF1SP80056A.
2048 // See definition in Part 2: Structures, section 11.2.3.1.
2049 type TPMSKDFSchemeKDF1SP80056A TPMSSchemeHash
2050
2051 // TPMSKDFSchemeKDF2 represents a TPMS_KDF_SCHEME_KDF2.
2052 // See definition in Part 2: Structures, section 11.2.3.1.
2053 type TPMSKDFSchemeKDF2 TPMSSchemeHash
2054
2055 // TPMSKDFSchemeKDF1SP800108 represents a TPMS_KDF_SCHEME_KDF1SP800108.
2056 // See definition in Part 2: Structures, section 11.2.3.1.
2057 type TPMSKDFSchemeKDF1SP800108 TPMSSchemeHash
2058
2059 // TPMUKDFScheme represents a TPMU_KDF_SCHEME.
2060 // See definition in Part 2: Structures, section 11.2.3.2.
2061 type TPMUKDFScheme struct {
2062 selector TPMAlgID
2063 contents Marshallable
2064 }
2065
2066 // KDFSchemeContents is a type constraint representing the possible contents of TPMUKDFScheme.
2067 type KDFSchemeContents interface {
2068 Marshallable
2069 *TPMSKDFSchemeMGF1 | *TPMSKDFSchemeECDH | *TPMSKDFSchemeKDF1SP80056A |
2070 *TPMSKDFSchemeKDF2 | *TPMSKDFSchemeKDF1SP800108
2071 }
2072
2073 // create implements the unmarshallableWithHint interface.
2074 func (u *TPMUKDFScheme) create(hint int64) (reflect.Value, error) {
2075 switch TPMAlgID(hint) {
2076 case TPMAlgMGF1:
2077 var contents TPMSKDFSchemeMGF1
2078 u.contents = &contents
2079 u.selector = TPMAlgID(hint)
2080 return reflect.ValueOf(&contents), nil
2081 case TPMAlgECDH:
2082 var contents TPMSKDFSchemeECDH
2083 u.contents = &contents
2084 u.selector = TPMAlgID(hint)
2085 return reflect.ValueOf(&contents), nil
2086 case TPMAlgKDF1SP80056A:
2087 var contents TPMSKDFSchemeKDF1SP80056A
2088 u.contents = &contents
2089 u.selector = TPMAlgID(hint)
2090 return reflect.ValueOf(&contents), nil
2091 case TPMAlgKDF2:
2092 var contents TPMSKDFSchemeKDF2
2093 u.contents = &contents
2094 u.selector = TPMAlgID(hint)
2095 return reflect.ValueOf(&contents), nil
2096 case TPMAlgKDF1SP800108:
2097 var contents TPMSKDFSchemeKDF1SP800108
2098 u.contents = &contents
2099 u.selector = TPMAlgID(hint)
2100 return reflect.ValueOf(&contents), nil
2101 }
2102 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2103 }
2104
2105 // get implements the marshallableWithHint interface.
2106 func (u TPMUKDFScheme) get(hint int64) (reflect.Value, error) {
2107 if u.selector != 0 && hint != int64(u.selector) {
2108 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
2109 }
2110 switch TPMAlgID(hint) {
2111 case TPMAlgMGF1:
2112 var contents TPMSKDFSchemeMGF1
2113 if u.contents != nil {
2114 contents = *u.contents.(*TPMSKDFSchemeMGF1)
2115 }
2116 return reflect.ValueOf(&contents), nil
2117 case TPMAlgECDH:
2118 var contents TPMSKDFSchemeECDH
2119 if u.contents != nil {
2120 contents = *u.contents.(*TPMSKDFSchemeECDH)
2121 }
2122 return reflect.ValueOf(&contents), nil
2123 case TPMAlgKDF1SP80056A:
2124 var contents TPMSKDFSchemeKDF1SP80056A
2125 if u.contents != nil {
2126 contents = *u.contents.(*TPMSKDFSchemeKDF1SP80056A)
2127 }
2128 return reflect.ValueOf(&contents), nil
2129 case TPMAlgKDF2:
2130 var contents TPMSKDFSchemeKDF2
2131 if u.contents != nil {
2132 contents = *u.contents.(*TPMSKDFSchemeKDF2)
2133 }
2134 return reflect.ValueOf(&contents), nil
2135
2136 case TPMAlgKDF1SP800108:
2137 var contents TPMSKDFSchemeKDF1SP800108
2138 if u.contents != nil {
2139 contents = *u.contents.(*TPMSKDFSchemeKDF1SP800108)
2140 }
2141 return reflect.ValueOf(&contents), nil
2142 }
2143 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2144 }
2145
2146 // NewTPMUKDFScheme instantiates a TPMUKDFScheme with the given contents.
2147 func NewTPMUKDFScheme[C KDFSchemeContents](selector TPMAlgID, contents C) TPMUKDFScheme {
2148 return TPMUKDFScheme{
2149 selector: selector,
2150 contents: contents,
2151 }
2152 }
2153
2154 // MGF1 returns the 'mgf1' member of the union.
2155 func (u *TPMUKDFScheme) MGF1() (*TPMSKDFSchemeMGF1, error) {
2156 if u.selector == TPMAlgMGF1 {
2157 return u.contents.(*TPMSKDFSchemeMGF1), nil
2158 }
2159 return nil, fmt.Errorf("did not contain mgf1 (selector value was %v)", u.selector)
2160 }
2161
2162 // ECDH returns the 'ecdh' member of the union.
2163 func (u *TPMUKDFScheme) ECDH() (*TPMSKDFSchemeECDH, error) {
2164 if u.selector == TPMAlgECDH {
2165 return u.contents.(*TPMSKDFSchemeECDH), nil
2166 }
2167 return nil, fmt.Errorf("did not contain ecdh (selector value was %v)", u.selector)
2168 }
2169
2170 // KDF1SP80056A returns the 'kdf1sp80056a' member of the union.
2171 func (u *TPMUKDFScheme) KDF1SP80056A() (*TPMSKDFSchemeKDF1SP80056A, error) {
2172 if u.selector == TPMAlgMGF1 {
2173 return u.contents.(*TPMSKDFSchemeKDF1SP80056A), nil
2174 }
2175 return nil, fmt.Errorf("did not contain kdf1sp80056a (selector value was %v)", u.selector)
2176 }
2177
2178 // KDF2 returns the 'kdf2' member of the union.
2179 func (u *TPMUKDFScheme) KDF2() (*TPMSKDFSchemeKDF2, error) {
2180 if u.selector == TPMAlgMGF1 {
2181 return u.contents.(*TPMSKDFSchemeKDF2), nil
2182 }
2183 return nil, fmt.Errorf("did not contain mgf1 (selector value was %v)", u.selector)
2184 }
2185
2186 // KDF1SP800108 returns the 'kdf1sp800108' member of the union.
2187 func (u *TPMUKDFScheme) KDF1SP800108() (*TPMSKDFSchemeKDF1SP800108, error) {
2188 if u.selector == TPMAlgMGF1 {
2189 return u.contents.(*TPMSKDFSchemeKDF1SP800108), nil
2190 }
2191 return nil, fmt.Errorf("did not contain kdf1sp800108 (selector value was %v)", u.selector)
2192 }
2193
2194 // TPMTKDFScheme represents a TPMT_KDF_SCHEME.
2195 // See definition in Part 2: Structures, section 11.2.3.3.
2196 type TPMTKDFScheme struct {
2197 marshalByReflection
2198 // scheme selector
2199 Scheme TPMIAlgKDF `gotpm:"nullable"`
2200 // scheme parameters
2201 Details TPMUKDFScheme `gotpm:"tag=Scheme"`
2202 }
2203
2204 // TPMUAsymScheme represents a TPMU_ASYM_SCHEME.
2205 // See definition in Part 2: Structures, section 11.2.3.5.
2206 type TPMUAsymScheme struct {
2207 selector TPMAlgID
2208 contents Marshallable
2209 }
2210
2211 // AsymSchemeContents is a type constraint representing the possible contents of TPMUAsymScheme.
2212 type AsymSchemeContents interface {
2213 Marshallable
2214 *TPMSSigSchemeRSASSA | *TPMSEncSchemeRSAES | *TPMSSigSchemeRSAPSS | *TPMSEncSchemeOAEP |
2215 *TPMSSigSchemeECDSA | *TPMSKeySchemeECDH | *TPMSKeySchemeECMQV | *TPMSSchemeECDAA
2216 }
2217
2218 // create implements the unmarshallableWithHint interface.
2219 func (u *TPMUAsymScheme) create(hint int64) (reflect.Value, error) {
2220 switch TPMAlgID(hint) {
2221 case TPMAlgRSASSA:
2222 var contents TPMSSigSchemeRSASSA
2223 u.contents = &contents
2224 u.selector = TPMAlgID(hint)
2225 return reflect.ValueOf(&contents), nil
2226 case TPMAlgRSAES:
2227 var contents TPMSEncSchemeRSAES
2228 u.contents = &contents
2229 u.selector = TPMAlgID(hint)
2230 return reflect.ValueOf(&contents), nil
2231 case TPMAlgRSAPSS:
2232 var contents TPMSSigSchemeRSAPSS
2233 u.contents = &contents
2234 u.selector = TPMAlgID(hint)
2235 return reflect.ValueOf(&contents), nil
2236 case TPMAlgOAEP:
2237 var contents TPMSEncSchemeOAEP
2238 u.contents = &contents
2239 u.selector = TPMAlgID(hint)
2240 return reflect.ValueOf(&contents), nil
2241 case TPMAlgECDSA:
2242 var contents TPMSSigSchemeECDSA
2243 u.contents = &contents
2244 u.selector = TPMAlgID(hint)
2245 return reflect.ValueOf(&contents), nil
2246 case TPMAlgECDH:
2247 var contents TPMSKeySchemeECDH
2248 u.contents = &contents
2249 u.selector = TPMAlgID(hint)
2250 return reflect.ValueOf(&contents), nil
2251 case TPMAlgECMQV:
2252 var contents TPMSKeySchemeECMQV
2253 u.contents = &contents
2254 u.selector = TPMAlgID(hint)
2255 return reflect.ValueOf(&contents), nil
2256 case TPMAlgECDAA:
2257 var contents TPMSSchemeECDAA
2258 u.contents = &contents
2259 u.selector = TPMAlgID(hint)
2260 return reflect.ValueOf(&contents), nil
2261 }
2262 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2263 }
2264
2265 // get implements the marshallableWithHint interface.
2266 func (u TPMUAsymScheme) get(hint int64) (reflect.Value, error) {
2267 if u.selector != 0 && hint != int64(u.selector) {
2268 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
2269 }
2270 switch TPMAlgID(hint) {
2271 case TPMAlgRSASSA:
2272 var contents TPMSSigSchemeRSASSA
2273 if u.contents != nil {
2274 contents = *u.contents.(*TPMSSigSchemeRSASSA)
2275 }
2276 return reflect.ValueOf(&contents), nil
2277 case TPMAlgRSAES:
2278 var contents TPMSEncSchemeRSAES
2279 if u.contents != nil {
2280 contents = *u.contents.(*TPMSEncSchemeRSAES)
2281 }
2282 return reflect.ValueOf(&contents), nil
2283 case TPMAlgRSAPSS:
2284 var contents TPMSSigSchemeRSAPSS
2285 if u.contents != nil {
2286 contents = *u.contents.(*TPMSSigSchemeRSAPSS)
2287 }
2288 return reflect.ValueOf(&contents), nil
2289 case TPMAlgOAEP:
2290 var contents TPMSEncSchemeOAEP
2291 if u.contents != nil {
2292 contents = *u.contents.(*TPMSEncSchemeOAEP)
2293 }
2294 return reflect.ValueOf(&contents), nil
2295 case TPMAlgECDSA:
2296 var contents TPMSSigSchemeECDSA
2297 if u.contents != nil {
2298 contents = *u.contents.(*TPMSSigSchemeECDSA)
2299 }
2300 return reflect.ValueOf(&contents), nil
2301 case TPMAlgECDH:
2302 var contents TPMSKeySchemeECDH
2303 if u.contents != nil {
2304 contents = *u.contents.(*TPMSKeySchemeECDH)
2305 }
2306 return reflect.ValueOf(&contents), nil
2307 case TPMAlgECMQV:
2308 var contents TPMSKeySchemeECMQV
2309 if u.contents != nil {
2310 contents = *u.contents.(*TPMSKeySchemeECMQV)
2311 }
2312 return reflect.ValueOf(&contents), nil
2313 case TPMAlgECDAA:
2314 var contents TPMSSchemeECDAA
2315 if u.contents != nil {
2316 contents = *u.contents.(*TPMSSchemeECDAA)
2317 }
2318 return reflect.ValueOf(&contents), nil
2319 }
2320 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2321 }
2322
2323 // NewTPMUAsymScheme instantiates a TPMUAsymScheme with the given contents.
2324 func NewTPMUAsymScheme[C AsymSchemeContents](selector TPMAlgID, contents C) TPMUAsymScheme {
2325 return TPMUAsymScheme{
2326 selector: selector,
2327 contents: contents,
2328 }
2329 }
2330
2331 // RSASSA returns the 'rsassa' member of the union.
2332 func (u *TPMUAsymScheme) RSASSA() (*TPMSSigSchemeRSASSA, error) {
2333 if u.selector == TPMAlgRSASSA {
2334 return u.contents.(*TPMSSigSchemeRSASSA), nil
2335 }
2336 return nil, fmt.Errorf("did not contain rsassa (selector value was %v)", u.selector)
2337 }
2338
2339 // RSAES returns the 'rsaes' member of the union.
2340 func (u *TPMUAsymScheme) RSAES() (*TPMSEncSchemeRSAES, error) {
2341 if u.selector == TPMAlgRSAES {
2342 return u.contents.(*TPMSEncSchemeRSAES), nil
2343 }
2344 return nil, fmt.Errorf("did not contain rsaes (selector value was %v)", u.selector)
2345 }
2346
2347 // RSAPSS returns the 'rsapss' member of the union.
2348 func (u *TPMUAsymScheme) RSAPSS() (*TPMSSigSchemeRSAPSS, error) {
2349 if u.selector == TPMAlgRSAPSS {
2350 return u.contents.(*TPMSSigSchemeRSAPSS), nil
2351 }
2352 return nil, fmt.Errorf("did not contain rsapss (selector value was %v)", u.selector)
2353 }
2354
2355 // OAEP returns the 'oaep' member of the union.
2356 func (u *TPMUAsymScheme) OAEP() (*TPMSEncSchemeOAEP, error) {
2357 if u.selector == TPMAlgOAEP {
2358 return u.contents.(*TPMSEncSchemeOAEP), nil
2359 }
2360 return nil, fmt.Errorf("did not contain oaep (selector value was %v)", u.selector)
2361 }
2362
2363 // ECDSA returns the 'ecdsa' member of the union.
2364 func (u *TPMUAsymScheme) ECDSA() (*TPMSSigSchemeECDSA, error) {
2365 if u.selector == TPMAlgECDSA {
2366 return u.contents.(*TPMSSigSchemeECDSA), nil
2367 }
2368 return nil, fmt.Errorf("did not contain rsassa (selector value was %v)", u.selector)
2369 }
2370
2371 // ECDH returns the 'ecdh' member of the union.
2372 func (u *TPMUAsymScheme) ECDH() (*TPMSKeySchemeECDH, error) {
2373 if u.selector == TPMAlgRSASSA {
2374 return u.contents.(*TPMSKeySchemeECDH), nil
2375 }
2376 return nil, fmt.Errorf("did not contain ecdh (selector value was %v)", u.selector)
2377 }
2378
2379 // ECDAA returns the 'ecdaa' member of the union.
2380 func (u *TPMUAsymScheme) ECDAA() (*TPMSSchemeECDAA, error) {
2381 if u.selector == TPMAlgECDAA {
2382 return u.contents.(*TPMSSchemeECDAA), nil
2383 }
2384 return nil, fmt.Errorf("did not contain rsassa (selector value was %v)", u.selector)
2385 }
2386
2387 // TPMIAlgRSAScheme represents a TPMI_ALG_RSA_SCHEME.
2388 // See definition in Part 2: Structures, section 11.2.4.1.
2389 type TPMIAlgRSAScheme = TPMAlgID
2390
2391 // TPMTRSAScheme represents a TPMT_RSA_SCHEME.
2392 // See definition in Part 2: Structures, section 11.2.4.2.
2393 type TPMTRSAScheme struct {
2394 marshalByReflection
2395 // scheme selector
2396 Scheme TPMIAlgRSAScheme `gotpm:"nullable"`
2397 // scheme parameters
2398 Details TPMUAsymScheme `gotpm:"tag=Scheme"`
2399 }
2400
2401 // TPMIAlgRSADecrypt represents a TPMI_ALG_RSA_DECRYPT.
2402 // See definition in Part 2: Structures, section 11.2.4.3.
2403 type TPMIAlgRSADecrypt = TPMAlgID
2404
2405 // TPMTRSADecrypt represents a TPMT_RSA_DECRYPT.
2406 // See definition in Part 2: Structures, section 11.2.4.4.
2407 type TPMTRSADecrypt struct {
2408 marshalByReflection
2409 // scheme selector
2410 Scheme TPMIAlgRSADecrypt `gotpm:"nullable"`
2411 // scheme parameters
2412 Details TPMUAsymScheme `gotpm:"tag=Scheme"`
2413 }
2414
2415 // TPM2BPublicKeyRSA represents a TPM2B_PUBLIC_KEY_RSA.
2416 // See definition in Part 2: Structures, section 11.2.4.5.
2417 type TPM2BPublicKeyRSA TPM2BData
2418
2419 // TPMIRSAKeyBits represents a TPMI_RSA_KEY_BITS.
2420 // See definition in Part 2: Structures, section 11.2.4.6.
2421 type TPMIRSAKeyBits = TPMKeyBits
2422
2423 // TPM2BPrivateKeyRSA representsa a TPM2B_PRIVATE_KEY_RSA.
2424 // See definition in Part 2: Structures, section 11.2.4.7.
2425 type TPM2BPrivateKeyRSA TPM2BData
2426
2427 // TPM2BECCParameter represents a TPM2B_ECC_PARAMETER.
2428 // See definition in Part 2: Structures, section 11.2.5.1.
2429 type TPM2BECCParameter TPM2BData
2430
2431 // TPMSECCPoint represents a TPMS_ECC_POINT.
2432 // See definition in Part 2: Structures, section 11.2.5.2.
2433 type TPMSECCPoint struct {
2434 marshalByReflection
2435 // X coordinate
2436 X TPM2BECCParameter
2437 // Y coordinate
2438 Y TPM2BECCParameter
2439 }
2440
2441 // TPM2BECCPoint represents a TPM2B_ECC_POINT.
2442 // See definition in Part 2: Structures, section 11.2.5.3.
2443 type TPM2BECCPoint = TPM2B[TPMSECCPoint, *TPMSECCPoint]
2444
2445 // TPMIAlgECCScheme represents a TPMI_ALG_ECC_SCHEME.
2446 // See definition in Part 2: Structures, section 11.2.5.4.
2447 type TPMIAlgECCScheme = TPMAlgID
2448
2449 // TPMIECCCurve represents a TPMI_ECC_CURVE.
2450 // See definition in Part 2: Structures, section 11.2.5.5.
2451 type TPMIECCCurve = TPMECCCurve
2452
2453 // TPMTECCScheme represents a TPMT_ECC_SCHEME.
2454 // See definition in Part 2: Structures, section 11.2.5.6.
2455 type TPMTECCScheme struct {
2456 marshalByReflection
2457 // scheme selector
2458 Scheme TPMIAlgECCScheme `gotpm:"nullable"`
2459 // scheme parameters
2460 Details TPMUAsymScheme `gotpm:"tag=Scheme"`
2461 }
2462
2463 // TPMSSignatureRSA represents a TPMS_SIGNATURE_RSA.
2464 // See definition in Part 2: Structures, section 11.3.1.
2465 type TPMSSignatureRSA struct {
2466 marshalByReflection
2467 // the hash algorithm used to digest the message
2468 Hash TPMIAlgHash
2469 // The signature is the size of a public key.
2470 Sig TPM2BPublicKeyRSA
2471 }
2472
2473 // TPMSSignatureECC represents a TPMS_SIGNATURE_ECC.
2474 // See definition in Part 2: Structures, section 11.3.2.
2475 type TPMSSignatureECC struct {
2476 marshalByReflection
2477 // the hash algorithm used in the signature process
2478 Hash TPMIAlgHash
2479 SignatureR TPM2BECCParameter
2480 SignatureS TPM2BECCParameter
2481 }
2482
2483 // TPMUSignature represents a TPMU_SIGNATURE.
2484 // See definition in Part 2: Structures, section 11.3.3.
2485 type TPMUSignature struct {
2486 selector TPMAlgID
2487 contents Marshallable
2488 }
2489
2490 // SignatureContents is a type constraint representing the possible contents of TPMUSignature.
2491 type SignatureContents interface {
2492 Marshallable
2493 *TPMTHA | *TPMSSignatureRSA | *TPMSSignatureECC
2494 }
2495
2496 // create implements the unmarshallableWithHint interface.
2497 func (u *TPMUSignature) create(hint int64) (reflect.Value, error) {
2498 switch TPMAlgID(hint) {
2499 case TPMAlgHMAC:
2500 var contents TPMTHA
2501 u.contents = &contents
2502 u.selector = TPMAlgID(hint)
2503 return reflect.ValueOf(&contents), nil
2504 case TPMAlgRSASSA, TPMAlgRSAPSS:
2505 var contents TPMSSignatureRSA
2506 u.contents = &contents
2507 u.selector = TPMAlgID(hint)
2508 return reflect.ValueOf(&contents), nil
2509 case TPMAlgECDSA, TPMAlgECDAA:
2510 var contents TPMSSignatureECC
2511 u.contents = &contents
2512 u.selector = TPMAlgID(hint)
2513 return reflect.ValueOf(&contents), nil
2514 }
2515 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2516 }
2517
2518 // get implements the marshallableWithHint interface.
2519 func (u TPMUSignature) get(hint int64) (reflect.Value, error) {
2520 if u.selector != 0 && hint != int64(u.selector) {
2521 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
2522 }
2523 switch TPMAlgID(hint) {
2524 case TPMAlgHMAC:
2525 var contents TPMTHA
2526 if u.contents != nil {
2527 contents = *u.contents.(*TPMTHA)
2528 }
2529 return reflect.ValueOf(&contents), nil
2530 case TPMAlgRSASSA, TPMAlgRSAPSS:
2531 var contents TPMSSignatureRSA
2532 if u.contents != nil {
2533 contents = *u.contents.(*TPMSSignatureRSA)
2534 }
2535 return reflect.ValueOf(&contents), nil
2536 case TPMAlgECDSA, TPMAlgECDAA:
2537 var contents TPMSSignatureECC
2538 if u.contents != nil {
2539 contents = *u.contents.(*TPMSSignatureECC)
2540 }
2541 return reflect.ValueOf(&contents), nil
2542 }
2543 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2544 }
2545
2546 // NewTPMUSignature instantiates a TPMUSignature with the given contents.
2547 func NewTPMUSignature[C SignatureContents](selector TPMAlgID, contents C) TPMUSignature {
2548 return TPMUSignature{
2549 selector: selector,
2550 contents: contents,
2551 }
2552 }
2553
2554 // HMAC returns the 'hmac' member of the union.
2555 func (u *TPMUSignature) HMAC() (*TPMTHA, error) {
2556 if u.selector == TPMAlgHMAC {
2557 return u.contents.(*TPMTHA), nil
2558 }
2559 return nil, fmt.Errorf("did not contain hmac (selector value was %v)", u.selector)
2560 }
2561
2562 // RSASSA returns the 'rsassa' member of the union.
2563 func (u *TPMUSignature) RSASSA() (*TPMSSignatureRSA, error) {
2564 if u.selector == TPMAlgRSASSA {
2565 return u.contents.(*TPMSSignatureRSA), nil
2566 }
2567 return nil, fmt.Errorf("did not contain rsassa (selector value was %v)", u.selector)
2568 }
2569
2570 // RSAPSS returns the 'rsapss' member of the union.
2571 func (u *TPMUSignature) RSAPSS() (*TPMSSignatureRSA, error) {
2572 if u.selector == TPMAlgRSAPSS {
2573 return u.contents.(*TPMSSignatureRSA), nil
2574 }
2575 return nil, fmt.Errorf("did not contain rsapss (selector value was %v)", u.selector)
2576 }
2577
2578 // ECDSA returns the 'ecdsa' member of the union.
2579 func (u *TPMUSignature) ECDSA() (*TPMSSignatureECC, error) {
2580 if u.selector == TPMAlgECDSA {
2581 return u.contents.(*TPMSSignatureECC), nil
2582 }
2583 return nil, fmt.Errorf("did not contain ecdsa (selector value was %v)", u.selector)
2584 }
2585
2586 // ECDAA returns the 'ecdaa' member of the union.
2587 func (u *TPMUSignature) ECDAA() (*TPMSSignatureECC, error) {
2588 if u.selector == TPMAlgECDAA {
2589 return u.contents.(*TPMSSignatureECC), nil
2590 }
2591 return nil, fmt.Errorf("did not contain ecdaa (selector value was %v)", u.selector)
2592 }
2593
2594 // TPMTSignature represents a TPMT_SIGNATURE.
2595 // See definition in Part 2: Structures, section 11.3.4.
2596 type TPMTSignature struct {
2597 marshalByReflection
2598 // selector of the algorithm used to construct the signature
2599 SigAlg TPMIAlgSigScheme `gotpm:"nullable"`
2600 // This shall be the actual signature information.
2601 Signature TPMUSignature `gotpm:"tag=SigAlg"`
2602 }
2603
2604 // TPM2BEncryptedSecret represents a TPM2B_ENCRYPTED_SECRET.
2605 // See definition in Part 2: Structures, section 11.4.33.
2606 type TPM2BEncryptedSecret TPM2BData
2607
2608 // TPMIAlgPublic represents a TPMI_ALG_PUBLIC.
2609 // See definition in Part 2: Structures, section 12.2.2.
2610 type TPMIAlgPublic = TPMAlgID
2611
2612 // TPMUPublicID represents a TPMU_PUBLIC_ID.
2613 // See definition in Part 2: Structures, section 12.2.3.2.
2614 type TPMUPublicID struct {
2615 selector TPMAlgID
2616 contents Marshallable
2617 }
2618
2619 // PublicIDContents is a type constraint representing the possible contents of TPMUPublicID.
2620 type PublicIDContents interface {
2621 Marshallable
2622 *TPM2BDigest | *TPM2BPublicKeyRSA | *TPMSECCPoint
2623 }
2624
2625 // create implements the unmarshallableWithHint interface.
2626 func (u *TPMUPublicID) create(hint int64) (reflect.Value, error) {
2627 switch TPMAlgID(hint) {
2628 case TPMAlgKeyedHash:
2629 var contents TPM2BDigest
2630 u.contents = &contents
2631 u.selector = TPMAlgID(hint)
2632 return reflect.ValueOf(&contents), nil
2633 case TPMAlgSymCipher:
2634 var contents TPM2BDigest
2635 u.contents = &contents
2636 u.selector = TPMAlgID(hint)
2637 return reflect.ValueOf(&contents), nil
2638 case TPMAlgRSA:
2639 var contents TPM2BPublicKeyRSA
2640 u.contents = &contents
2641 u.selector = TPMAlgID(hint)
2642 return reflect.ValueOf(&contents), nil
2643 case TPMAlgECC:
2644 var contents TPMSECCPoint
2645 u.contents = &contents
2646 u.selector = TPMAlgID(hint)
2647 return reflect.ValueOf(&contents), nil
2648 }
2649 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2650 }
2651
2652 // get implements the marshallableWithHint interface.
2653 func (u TPMUPublicID) get(hint int64) (reflect.Value, error) {
2654 if u.selector != 0 && hint != int64(u.selector) {
2655 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
2656 }
2657 switch TPMAlgID(hint) {
2658 case TPMAlgKeyedHash:
2659 var contents TPM2BDigest
2660 if u.contents != nil {
2661 contents = *u.contents.(*TPM2BDigest)
2662 }
2663 return reflect.ValueOf(&contents), nil
2664 case TPMAlgSymCipher:
2665 var contents TPM2BDigest
2666 if u.contents != nil {
2667 contents = *u.contents.(*TPM2BDigest)
2668 }
2669 return reflect.ValueOf(&contents), nil
2670 case TPMAlgRSA:
2671 var contents TPM2BPublicKeyRSA
2672 if u.contents != nil {
2673 contents = *u.contents.(*TPM2BPublicKeyRSA)
2674 }
2675 return reflect.ValueOf(&contents), nil
2676 case TPMAlgECC:
2677 var contents TPMSECCPoint
2678 if u.contents != nil {
2679 contents = *u.contents.(*TPMSECCPoint)
2680 }
2681 return reflect.ValueOf(&contents), nil
2682 }
2683 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2684 }
2685
2686 // NewTPMUPublicID instantiates a TPMUPublicID with the given contents.
2687 func NewTPMUPublicID[C PublicIDContents](selector TPMAlgID, contents C) TPMUPublicID {
2688 return TPMUPublicID{
2689 selector: selector,
2690 contents: contents,
2691 }
2692 }
2693
2694 // KeyedHash returns the 'keyedHash' member of the union.
2695 func (u *TPMUPublicID) KeyedHash() (*TPM2BDigest, error) {
2696 if u.selector == TPMAlgKeyedHash {
2697 return u.contents.(*TPM2BDigest), nil
2698 }
2699 return nil, fmt.Errorf("did not contain keyedHash (selector value was %v)", u.selector)
2700 }
2701
2702 // SymCipher returns the 'symCipher' member of the union.
2703 func (u *TPMUPublicID) SymCipher() (*TPM2BDigest, error) {
2704 if u.selector == TPMAlgSymCipher {
2705 return u.contents.(*TPM2BDigest), nil
2706 }
2707 return nil, fmt.Errorf("did not contain symCipher (selector value was %v)", u.selector)
2708 }
2709
2710 // RSA returns the 'rsa' member of the union.
2711 func (u *TPMUPublicID) RSA() (*TPM2BPublicKeyRSA, error) {
2712 if u.selector == TPMAlgRSA {
2713 return u.contents.(*TPM2BPublicKeyRSA), nil
2714 }
2715 return nil, fmt.Errorf("did not contain rsa (selector value was %v)", u.selector)
2716 }
2717
2718 // ECC returns the 'ecc' member of the union.
2719 func (u *TPMUPublicID) ECC() (*TPMSECCPoint, error) {
2720 if u.selector == TPMAlgECC {
2721 return u.contents.(*TPMSECCPoint), nil
2722 }
2723 return nil, fmt.Errorf("did not contain ecc (selector value was %v)", u.selector)
2724 }
2725
2726 // TPMSKeyedHashParms represents a TPMS_KEYEDHASH_PARMS.
2727 // See definition in Part 2: Structures, section 12.2.3.3.
2728 type TPMSKeyedHashParms struct {
2729 marshalByReflection
2730 // Indicates the signing method used for a keyedHash signing
2731 // object. This field also determines the size of the data field
2732 // for a data object created with TPM2_Create() or
2733 // TPM2_CreatePrimary().
2734 Scheme TPMTKeyedHashScheme
2735 }
2736
2737 // TPMSRSAParms represents a TPMS_RSA_PARMS.
2738 // See definition in Part 2: Structures, section 12.2.3.5.
2739 type TPMSRSAParms struct {
2740 marshalByReflection
2741 // for a restricted decryption key, shall be set to a supported
2742 // symmetric algorithm, key size, and mode.
2743 // if the key is not a restricted decryption key, this field shall
2744 // be set to TPM_ALG_NULL.
2745 Symmetric TPMTSymDefObject
2746 // scheme.scheme shall be:
2747 // for an unrestricted signing key, either TPM_ALG_RSAPSS
2748 // TPM_ALG_RSASSA or TPM_ALG_NULL
2749 // for a restricted signing key, either TPM_ALG_RSAPSS or
2750 // TPM_ALG_RSASSA
2751 // for an unrestricted decryption key, TPM_ALG_RSAES, TPM_ALG_OAEP,
2752 // or TPM_ALG_NULL unless the object also has the sign attribute
2753 // for a restricted decryption key, TPM_ALG_NULL
2754 Scheme TPMTRSAScheme
2755 // number of bits in the public modulus
2756 KeyBits TPMIRSAKeyBits
2757 // the public exponent
2758 // A prime number greater than 2.
2759 Exponent uint32
2760 }
2761
2762 // TPMSECCParms represents a TPMS_ECC_PARMS.
2763 // See definition in Part 2: Structures, section 12.2.3.6.
2764 type TPMSECCParms struct {
2765 marshalByReflection
2766 // for a restricted decryption key, shall be set to a supported
2767 // symmetric algorithm, key size. and mode.
2768 // if the key is not a restricted decryption key, this field shall
2769 // be set to TPM_ALG_NULL.
2770 Symmetric TPMTSymDefObject
2771 // If the sign attribute of the key is SET, then this shall be a
2772 // valid signing scheme.
2773 Scheme TPMTECCScheme
2774 // ECC curve ID
2775 CurveID TPMIECCCurve
2776 // an optional key derivation scheme for generating a symmetric key
2777 // from a Z value
2778 // If the kdf parameter associated with curveID is not TPM_ALG_NULL
2779 // then this is required to be NULL.
2780 KDF TPMTKDFScheme
2781 }
2782
2783 // TPMUPublicParms represents a TPMU_PUBLIC_PARMS.
2784 // See definition in Part 2: Structures, section 12.2.3.7.
2785 type TPMUPublicParms struct {
2786 selector TPMAlgID
2787 contents Marshallable
2788 }
2789
2790 // PublicParmsContents is a type constraint representing the possible contents of TPMUPublicParms.
2791 type PublicParmsContents interface {
2792 Marshallable
2793 *TPMSKeyedHashParms | *TPMSSymCipherParms | *TPMSRSAParms |
2794 *TPMSECCParms
2795 }
2796
2797 // create implements the unmarshallableWithHint interface.
2798 func (u *TPMUPublicParms) create(hint int64) (reflect.Value, error) {
2799 switch TPMAlgID(hint) {
2800 case TPMAlgKeyedHash:
2801 var contents TPMSKeyedHashParms
2802 u.contents = &contents
2803 u.selector = TPMAlgID(hint)
2804 return reflect.ValueOf(&contents), nil
2805 case TPMAlgSymCipher:
2806 var contents TPMSSymCipherParms
2807 u.contents = &contents
2808 u.selector = TPMAlgID(hint)
2809 return reflect.ValueOf(&contents), nil
2810 case TPMAlgRSA:
2811 var contents TPMSRSAParms
2812 u.contents = &contents
2813 u.selector = TPMAlgID(hint)
2814 return reflect.ValueOf(&contents), nil
2815 case TPMAlgECC:
2816 var contents TPMSECCParms
2817 u.contents = &contents
2818 u.selector = TPMAlgID(hint)
2819 return reflect.ValueOf(&contents), nil
2820 }
2821 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2822 }
2823
2824 // get implements the marshallableWithHint interface.
2825 func (u TPMUPublicParms) get(hint int64) (reflect.Value, error) {
2826 if u.selector != 0 && hint != int64(u.selector) {
2827 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
2828 }
2829 switch TPMAlgID(hint) {
2830 case TPMAlgKeyedHash:
2831 var contents TPMSKeyedHashParms
2832 if u.contents != nil {
2833 contents = *u.contents.(*TPMSKeyedHashParms)
2834 }
2835 return reflect.ValueOf(&contents), nil
2836 case TPMAlgSymCipher:
2837 var contents TPMSSymCipherParms
2838 if u.contents != nil {
2839 contents = *u.contents.(*TPMSSymCipherParms)
2840 }
2841 return reflect.ValueOf(&contents), nil
2842 case TPMAlgRSA:
2843 var contents TPMSRSAParms
2844 if u.contents != nil {
2845 contents = *u.contents.(*TPMSRSAParms)
2846 }
2847 return reflect.ValueOf(&contents), nil
2848 case TPMAlgECC:
2849 var contents TPMSECCParms
2850 if u.contents != nil {
2851 contents = *u.contents.(*TPMSECCParms)
2852 }
2853 return reflect.ValueOf(&contents), nil
2854 }
2855 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
2856 }
2857
2858 // NewTPMUPublicParms instantiates a TPMUPublicParms with the given contents.
2859 func NewTPMUPublicParms[C PublicParmsContents](selector TPMAlgID, contents C) TPMUPublicParms {
2860 return TPMUPublicParms{
2861 selector: selector,
2862 contents: contents,
2863 }
2864 }
2865
2866 // KeyedHashDetail returns the 'keyedHashDetail' member of the union.
2867 func (u *TPMUPublicParms) KeyedHashDetail() (*TPMSKeyedHashParms, error) {
2868 if u.selector == TPMAlgKeyedHash {
2869 return u.contents.(*TPMSKeyedHashParms), nil
2870 }
2871 return nil, fmt.Errorf("did not contain keyedHashDetail (selector value was %v)", u.selector)
2872 }
2873
2874 // SymDetail returns the 'symDetail' member of the union.
2875 func (u *TPMUPublicParms) SymDetail() (*TPMSSymCipherParms, error) {
2876 if u.selector == TPMAlgSymCipher {
2877 return u.contents.(*TPMSSymCipherParms), nil
2878 }
2879 return nil, fmt.Errorf("did not contain symDetail (selector value was %v)", u.selector)
2880 }
2881
2882 // RSADetail returns the 'rsaDetail' member of the union.
2883 func (u *TPMUPublicParms) RSADetail() (*TPMSRSAParms, error) {
2884 if u.selector == TPMAlgRSA {
2885 return u.contents.(*TPMSRSAParms), nil
2886 }
2887 return nil, fmt.Errorf("did not contain rsaDetail (selector value was %v)", u.selector)
2888 }
2889
2890 // ECCDetail returns the 'eccDetail' member of the union.
2891 func (u *TPMUPublicParms) ECCDetail() (*TPMSECCParms, error) {
2892 if u.selector == TPMAlgECC {
2893 return u.contents.(*TPMSECCParms), nil
2894 }
2895 return nil, fmt.Errorf("did not contain eccDetail (selector value was %v)", u.selector)
2896 }
2897
2898 // TPMTPublicParms represents a TPMT_PUBLIC_PARMS.
2899 // See definition in Part 2: Structures, section 12.2.3.8.
2900 type TPMTPublicParms struct {
2901 marshalByReflection
2902 // algorithm to be tested
2903 Type TPMIAlgPublic
2904 // algorithm details
2905 Parameters TPMUPublicParms `gotpm:"tag=Type"`
2906 }
2907
2908 // TPMTPublic represents a TPMT_PUBLIC.
2909 // See definition in Part 2: Structures, section 12.2.4.
2910 type TPMTPublic struct {
2911 marshalByReflection
2912 // “algorithm” associated with this object
2913 Type TPMIAlgPublic
2914 // algorithm used for computing the Name of the object
2915 NameAlg TPMIAlgHash
2916 // attributes that, along with type, determine the manipulations
2917 // of this object
2918 ObjectAttributes TPMAObject
2919 // optional policy for using this key
2920 // The policy is computed using the nameAlg of the object.
2921 AuthPolicy TPM2BDigest
2922 // the algorithm or structure details
2923 Parameters TPMUPublicParms `gotpm:"tag=Type"`
2924 // the unique identifier of the structure
2925 // For an asymmetric key, this would be the public key.
2926 Unique TPMUPublicID `gotpm:"tag=Type"`
2927 }
2928
2929 // TPM2BPublic represents a TPM2B_PUBLIC.
2930 // See definition in Part 2: Structures, section 12.2.5.
2931 type TPM2BPublic = TPM2B[TPMTPublic, *TPMTPublic]
2932
2933 // TPM2BTemplate represents a TPM2B_TEMPLATE.
2934 // See definition in Part 2: Structures, section 12.2.6.
2935 type TPM2BTemplate TPM2BData
2936
2937 // TemplateContents is a type constraint representing the possible contents of TPMUTemplate.
2938 type TemplateContents interface {
2939 Marshallable
2940 *TPMTPublic | *TPMTTemplate
2941 }
2942
2943 // TPMTTemplate represents a TPMT_TEMPLATE. It is not defined in the spec.
2944 // It represents the alternate form of TPMT_PUBLIC for TPM2B_TEMPLATE as
2945 // described in Part 2: Structures, 12.2.6.
2946 type TPMTTemplate struct {
2947 marshalByReflection
2948 // “algorithm” associated with this object
2949 Type TPMIAlgPublic
2950 // algorithm used for computing the Name of the object
2951 NameAlg TPMIAlgHash
2952 // attributes that, along with type, determine the manipulations
2953 // of this object
2954 ObjectAttributes TPMAObject
2955 // optional policy for using this key
2956 // The policy is computed using the nameAlg of the object.
2957 AuthPolicy TPM2BDigest
2958 // the algorithm or structure details
2959 Parameters TPMUPublicParms `gotpm:"tag=Type"`
2960 // the derivation parameters
2961 Unique TPMSDerive
2962 }
2963
2964 // New2BTemplate creates a TPM2BTemplate with the given data.
2965 func New2BTemplate[C TemplateContents](data C) TPM2BTemplate {
2966 return TPM2BTemplate{
2967 Buffer: Marshal(data),
2968 }
2969 }
2970
2971 // Sym returns the 'sym' member of the union.
2972 func (u *TPMUSensitiveComposite) Sym() (*TPM2BSymKey, error) {
2973 if u.selector == TPMAlgSymCipher {
2974 return u.contents.(*TPM2BSymKey), nil
2975 }
2976 return nil, fmt.Errorf("did not contain sym (selector value was %v)", u.selector)
2977 }
2978
2979 // Bits returns the 'bits' member of the union.
2980 func (u *TPMUSensitiveComposite) Bits() (*TPM2BSensitiveData, error) {
2981 if u.selector == TPMAlgKeyedHash {
2982 return u.contents.(*TPM2BSensitiveData), nil
2983 }
2984 return nil, fmt.Errorf("did not contain bits (selector value was %v)", u.selector)
2985 }
2986
2987 // RSA returns the 'rsa' member of the union.
2988 func (u *TPMUSensitiveComposite) RSA() (*TPM2BPrivateKeyRSA, error) {
2989 if u.selector == TPMAlgRSA {
2990 return u.contents.(*TPM2BPrivateKeyRSA), nil
2991 }
2992 return nil, fmt.Errorf("did not contain rsa (selector value was %v)", u.selector)
2993 }
2994
2995 // ECC returns the 'ecc' member of the union.
2996 func (u *TPMUSensitiveComposite) ECC() (*TPM2BECCParameter, error) {
2997 if u.selector == TPMAlgECC {
2998 return u.contents.(*TPM2BECCParameter), nil
2999 }
3000 return nil, fmt.Errorf("did not contain ecc (selector value was %v)", u.selector)
3001 }
3002
3003 // TPMUSensitiveComposite represents a TPMU_SENSITIVE_COMPOSITE.
3004 // See definition in Part 2: Structures, section 12.3.2.3.
3005 type TPMUSensitiveComposite struct {
3006 selector TPMAlgID
3007 contents Marshallable
3008 }
3009
3010 // SensitiveCompositeContents is a type constraint representing the possible contents of TPMUSensitiveComposite.
3011 type SensitiveCompositeContents interface {
3012 Marshallable
3013 *TPM2BPrivateKeyRSA | *TPM2BECCParameter | *TPM2BSensitiveData | *TPM2BSymKey
3014 }
3015
3016 // create implements the unmarshallableWithHint interface.
3017 func (u *TPMUSensitiveComposite) create(hint int64) (reflect.Value, error) {
3018 switch TPMAlgID(hint) {
3019 case TPMAlgRSA:
3020 var contents TPM2BPrivateKeyRSA
3021 u.contents = &contents
3022 u.selector = TPMAlgID(hint)
3023 return reflect.ValueOf(&contents), nil
3024 case TPMAlgECC:
3025 var contents TPM2BECCParameter
3026 u.contents = &contents
3027 u.selector = TPMAlgID(hint)
3028 return reflect.ValueOf(&contents), nil
3029 case TPMAlgKeyedHash:
3030 var contents TPM2BSensitiveData
3031 u.contents = &contents
3032 u.selector = TPMAlgID(hint)
3033 return reflect.ValueOf(&contents), nil
3034 case TPMAlgSymCipher:
3035 var contents TPM2BSymKey
3036 u.contents = &contents
3037 u.selector = TPMAlgID(hint)
3038 return reflect.ValueOf(&contents), nil
3039 }
3040 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
3041 }
3042
3043 // get implements the marshallableWithHint interface.
3044 func (u TPMUSensitiveComposite) get(hint int64) (reflect.Value, error) {
3045 if u.selector != 0 && hint != int64(u.selector) {
3046 return reflect.ValueOf(nil), fmt.Errorf("incorrect union tag %v, is %v", hint, u.selector)
3047 }
3048 switch TPMAlgID(hint) {
3049 case TPMAlgRSA:
3050 var contents TPM2BPrivateKeyRSA
3051 if u.contents != nil {
3052 contents = *u.contents.(*TPM2BPrivateKeyRSA)
3053 }
3054 return reflect.ValueOf(&contents), nil
3055 case TPMAlgECC:
3056 var contents TPM2BECCParameter
3057 if u.contents != nil {
3058 contents = *u.contents.(*TPM2BECCParameter)
3059 }
3060 return reflect.ValueOf(&contents), nil
3061 case TPMAlgKeyedHash:
3062 var contents TPM2BSensitiveData
3063 if u.contents != nil {
3064 contents = *u.contents.(*TPM2BSensitiveData)
3065 }
3066 return reflect.ValueOf(&contents), nil
3067 case TPMAlgSymCipher:
3068 var contents TPM2BSymKey
3069 if u.contents != nil {
3070 contents = *u.contents.(*TPM2BSymKey)
3071 }
3072 return reflect.ValueOf(&contents), nil
3073 }
3074 return reflect.ValueOf(nil), fmt.Errorf("no union member for tag %v", hint)
3075 }
3076
3077 // NewTPMUSensitiveComposite instantiates a TPMUSensitiveComposite with the given contents.
3078 func NewTPMUSensitiveComposite[C SensitiveCompositeContents](selector TPMAlgID, contents C) TPMUSensitiveComposite {
3079 return TPMUSensitiveComposite{
3080 selector: selector,
3081 contents: contents,
3082 }
3083 }
3084
3085 // RSA returns the 'rsa' member of the union.
3086 func (u *TPMUKDFScheme) RSA() (*TPM2BPrivateKeyRSA, error) {
3087 if u.selector == TPMAlgRSA {
3088 return u.contents.(*TPM2BPrivateKeyRSA), nil
3089 }
3090 return nil, fmt.Errorf("did not contain rsa (selector value was %v)", u.selector)
3091 }
3092
3093 // ECC returns the 'ecc' member of the union.
3094 func (u *TPMUKDFScheme) ECC() (*TPM2BECCParameter, error) {
3095 if u.selector == TPMAlgECC {
3096 return u.contents.(*TPM2BECCParameter), nil
3097 }
3098 return nil, fmt.Errorf("did not contain ecc (selector value was %v)", u.selector)
3099 }
3100
3101 // Bits returns the 'bits' member of the union.
3102 func (u *TPMUKDFScheme) Bits() (*TPM2BSensitiveData, error) {
3103 if u.selector == TPMAlgKeyedHash {
3104 return u.contents.(*TPM2BSensitiveData), nil
3105 }
3106 return nil, fmt.Errorf("did not contain bits (selector value was %v)", u.selector)
3107 }
3108
3109 // Sym returns the 'sym' member of the union.
3110 func (u *TPMUKDFScheme) Sym() (*TPM2BSymKey, error) {
3111 if u.selector == TPMAlgSymCipher {
3112 return u.contents.(*TPM2BSymKey), nil
3113 }
3114 return nil, fmt.Errorf("did not contain sym (selector value was %v)", u.selector)
3115 }
3116
3117 // TPMTSensitive represents a TPMT_SENSITIVE.
3118 // See definition in Part 2: Structures, section 12.3.2.4.
3119 type TPMTSensitive struct {
3120 marshalByReflection
3121 // identifier for the sensitive area
3122 SensitiveType TPMIAlgPublic
3123 // user authorization data
3124 AuthValue TPM2BAuth
3125 // for a parent object, the optional protection seed; for other objects,
3126 // the obfuscation value
3127 SeedValue TPM2BDigest
3128 // the type-specific private data
3129 Sensitive TPMUSensitiveComposite `gotpm:"tag=SensitiveType"`
3130 }
3131
3132 // TPM2BSensitive represents a TPM2B_SENSITIVE.
3133 // See definition in Part 2: Structures, section 12.3.3.
3134 type TPM2BSensitive = TPM2B[TPMTSensitive, *TPMTSensitive]
3135
3136 // TPM2BPrivate represents a TPM2B_PRIVATE.
3137 // See definition in Part 2: Structures, section 12.3.7.
3138 type TPM2BPrivate TPM2BData
3139
3140 // TPMSCreationData represents a TPMS_CREATION_DATA.
3141 // See definition in Part 2: Structures, section 15.1.
3142 type TPMSCreationData struct {
3143 marshalByReflection
3144 // list indicating the PCR included in pcrDigest
3145 PCRSelect TPMLPCRSelection
3146 // digest of the selected PCR using nameAlg of the object for which
3147 // this structure is being created
3148 PCRDigest TPM2BDigest
3149 // the locality at which the object was created
3150 Locality TPMALocality
3151 // nameAlg of the parent
3152 ParentNameAlg TPMAlgID
3153 // Name of the parent at time of creation
3154 ParentName TPM2BName
3155 // Qualified Name of the parent at the time of creation
3156 ParentQualifiedName TPM2BName
3157 // association with additional information added by the key
3158 OutsideInfo TPM2BData
3159 }
3160
3161 // TPM2BIDObject represents a TPM2B_ID_OBJECT.
3162 // See definition in Part 2: Structures, section 12.4.3.
3163 type TPM2BIDObject TPM2BData
3164
3165 // TPMANV represents a TPMA_NV.
3166 // See definition in Part 2: Structures, section 13.4.
3167 type TPMANV struct {
3168 bitfield32
3169 marshalByReflection
3170 // SET (1): The Index data can be written if Platform Authorization is
3171 // provided.
3172 // CLEAR (0): Writing of the Index data cannot be authorized with
3173 // Platform Authorization.
3174 PPWrite bool `gotpm:"bit=0"`
3175 // SET (1): The Index data can be written if Owner Authorization is
3176 // provided.
3177 // CLEAR (0): Writing of the Index data cannot be authorized with Owner
3178 // Authorization.
3179 OwnerWrite bool `gotpm:"bit=1"`
3180 // SET (1): Authorizations to change the Index contents that require
3181 // USER role may be provided with an HMAC session or password.
3182 // CLEAR (0): Authorizations to change the Index contents that require
3183 // USER role may not be provided with an HMAC session or password.
3184 AuthWrite bool `gotpm:"bit=2"`
3185 // SET (1): Authorizations to change the Index contents that require
3186 // USER role may be provided with a policy session.
3187 // CLEAR (0): Authorizations to change the Index contents that require
3188 // USER role may not be provided with a policy session.
3189 PolicyWrite bool `gotpm:"bit=3"`
3190 // The type of the index.
3191 NT TPMNT `gotpm:"bit=7:4"`
3192 // SET (1): Index may not be deleted unless the authPolicy is satisfied
3193 // using TPM2_NV_UndefineSpaceSpecial().
3194 // CLEAR (0): Index may be deleted with proper platform or owner
3195 // authorization using TPM2_NV_UndefineSpace().
3196 PolicyDelete bool `gotpm:"bit=10"`
3197 // SET (1): Index cannot be written.
3198 // CLEAR (0): Index can be written.
3199 WriteLocked bool `gotpm:"bit=11"`
3200 // SET (1): A partial write of the Index data is not allowed. The write
3201 // size shall match the defined space size.
3202 // CLEAR (0): Partial writes are allowed. This setting is required if
3203 // the .dataSize of the Index is larger than NV_MAX_BUFFER_SIZE for the
3204 // implementation.
3205 WriteAll bool `gotpm:"bit=12"`
3206 // SET (1): TPM2_NV_WriteLock() may be used to prevent further writes
3207 // to this location.
3208 // CLEAR (0): TPM2_NV_WriteLock() does not block subsequent writes if
3209 // TPMA_NV_WRITE_STCLEAR is also CLEAR.
3210 WriteDefine bool `gotpm:"bit=13"`
3211 // SET (1): TPM2_NV_WriteLock() may be used to prevent further writes
3212 // to this location until the next TPM Reset or TPM Restart.
3213 // CLEAR (0): TPM2_NV_WriteLock() does not block subsequent writes if
3214 // TPMA_NV_WRITEDEFINE is also CLEAR.
3215 WriteSTClear bool `gotpm:"bit=14"`
3216 // SET (1): If TPM2_NV_GlobalWriteLock() is successful,
3217 // TPMA_NV_WRITELOCKED is set.
3218 // CLEAR (0): TPM2_NV_GlobalWriteLock() has no effect on the writing of
3219 // the data at this Index.
3220 GlobalLock bool `gotpm:"bit=15"`
3221 // SET (1): The Index data can be read if Platform Authorization is
3222 // provided.
3223 // CLEAR (0): Reading of the Index data cannot be authorized with
3224 // Platform Authorization.
3225 PPRead bool `gotpm:"bit=16"`
3226 // SET (1): The Index data can be read if Owner Authorization is
3227 // provided.
3228 // CLEAR (0): Reading of the Index data cannot be authorized with Owner
3229 // Authorization.
3230 OwnerRead bool `gotpm:"bit=17"`
3231 // SET (1): The Index data may be read if the authValue is provided.
3232 // CLEAR (0): Reading of the Index data cannot be authorized with the
3233 // Index authValue.
3234 AuthRead bool `gotpm:"bit=18"`
3235 // SET (1): The Index data may be read if the authPolicy is satisfied.
3236 // CLEAR (0): Reading of the Index data cannot be authorized with the
3237 // Index authPolicy.
3238 PolicyRead bool `gotpm:"bit=19"`
3239 // SET (1): Authorization failures of the Index do not affect the DA
3240 // logic and authorization of the Index is not blocked when the TPM is
3241 // in Lockout mode.
3242 // CLEAR (0): Authorization failures of the Index will increment the
3243 // authorization failure counter and authorizations of this Index are
3244 // not allowed when the TPM is in Lockout mode.
3245 NoDA bool `gotpm:"bit=25"`
3246 // SET (1): NV Index state is only required to be saved when the TPM
3247 // performs an orderly shutdown (TPM2_Shutdown()).
3248 // CLEAR (0): NV Index state is required to be persistent after the
3249 // command to update the Index completes successfully (that is, the NV
3250 // update is synchronous with the update command).
3251 Orderly bool `gotpm:"bit=26"`
3252 // SET (1): TPMA_NV_WRITTEN for the Index is CLEAR by TPM Reset or TPM
3253 // Restart.
3254 // CLEAR (0): TPMA_NV_WRITTEN is not changed by TPM Restart.
3255 ClearSTClear bool `gotpm:"bit=27"`
3256 // SET (1): Reads of the Index are blocked until the next TPM Reset or
3257 // TPM Restart.
3258 // CLEAR (0): Reads of the Index are allowed if proper authorization is
3259 // provided.
3260 ReadLocked bool `gotpm:"bit=28"`
3261 // SET (1): Index has been written.
3262 // CLEAR (0): Index has not been written.
3263 Written bool `gotpm:"bit=29"`
3264 // SET (1): This Index may be undefined with Platform Authorization
3265 // but not with Owner Authorization.
3266 // CLEAR (0): This Index may be undefined using Owner Authorization but
3267 // not with Platform Authorization.
3268 PlatformCreate bool `gotpm:"bit=30"`
3269 // SET (1): TPM2_NV_ReadLock() may be used to SET TPMA_NV_READLOCKED
3270 // for this Index.
3271 // CLEAR (0): TPM2_NV_ReadLock() has no effect on this Index.
3272 ReadSTClear bool `gotpm:"bit=31"`
3273 }
3274
3275 // TPMSNVPublic represents a TPMS_NV_PUBLIC.
3276 // See definition in Part 2: Structures, section 13.5.
3277 type TPMSNVPublic struct {
3278 marshalByReflection
3279 // the handle of the data area
3280 NVIndex TPMIRHNVIndex
3281 // hash algorithm used to compute the name of the Index and used for
3282 // the authPolicy. For an extend index, the hash algorithm used for the
3283 // extend.
3284 NameAlg TPMIAlgHash
3285 // the Index attributes
3286 Attributes TPMANV
3287 // optional access policy for the Index
3288 AuthPolicy TPM2BDigest
3289 // the size of the data area
3290 DataSize uint16
3291 }
3292
3293 // TPM2BNVPublic represents a TPM2B_NV_PUBLIC.
3294 // See definition in Part 2: Structures, section 13.6.
3295 type TPM2BNVPublic = TPM2B[TPMSNVPublic, *TPMSNVPublic]
3296
3297 // TPM2BContextSensitive represents a TPM2B_CONTEXT_SENSITIVE
3298 // See definition in Part 2: Structures, section 14.2.
3299 type TPM2BContextSensitive TPM2BData
3300
3301 // TPMSContextData represents a TPMS_CONTEXT_DATA
3302 // See definition in Part 2: Structures, section 14.3.
3303 type TPMSContextData struct {
3304 marshalByReflection
3305 // the integrity value
3306 Integrity TPM2BDigest
3307 // the sensitive area
3308 Encrypted TPM2BContextSensitive
3309 }
3310
3311 // TPM2BContextData represents a TPM2B_CONTEXT_DATA
3312 // See definition in Part 2: Structures, section 14.4.
3313 // Represented here as a flat buffer because how a TPM chooses
3314 // to represent its context data is implementation-dependent.
3315 type TPM2BContextData TPM2BData
3316
3317 // TPMSContext represents a TPMS_CONTEXT
3318 // See definition in Part 2: Structures, section 14.5.
3319 type TPMSContext struct {
3320 marshalByReflection
3321 // the sequence number of the context
3322 Sequence uint64
3323 // a handle indicating if the context is a session, object, or sequence object
3324 SavedHandle TPMIDHSaved
3325 // the hierarchy of the context
3326 Hierarchy TPMIRHHierarchy
3327 // the context data and integrity HMAC
3328 ContextBlob TPM2BContextData
3329 }
3330
3331 type tpm2bCreationData = TPM2B[TPMSCreationData, *TPMSCreationData]