tpm2_protocol/data/
mod.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) 2025 Opinsys Oy
3// Copyright (c) 2024-2025 Jarkko Sakkinen
4
5mod r#enum;
6mod tpm_rc;
7mod tpma;
8mod tpmi;
9mod tpms;
10mod tpmt;
11mod tpmu;
12
13pub use self::r#enum::*;
14pub use self::tpm_rc::*;
15pub use self::tpma::*;
16pub use self::tpmi::*;
17pub use self::tpms::*;
18pub use self::tpmt::*;
19pub use self::tpmu::*;
20
21use crate::{tpm2b, tpm2b_struct, tpml, TPM_MAX_COMMAND_SIZE};
22use core::{convert::TryFrom, fmt::Debug};
23
24pub const MAX_DIGEST_SIZE: usize = 64;
25pub const MAX_ECC_KEY_BYTES: usize = 66;
26pub const MAX_SYM_KEY_BYTES: usize = 32;
27pub const MAX_RSA_KEY_BYTES: usize = 512;
28pub const MAX_SENSITIVE_DATA: usize = 256;
29pub const MAX_BUFFER_SIZE: usize = 1024;
30pub const MAX_NV_BUFFER_SIZE: usize = 1024;
31pub const MAX_PRIVATE_SIZE: usize = 1408;
32pub const MAX_EVENT_SIZE: usize = 1024;
33
34tpm2b!(Tpm2b, TPM_MAX_COMMAND_SIZE);
35tpm2b!(Tpm2bAuth, MAX_DIGEST_SIZE);
36tpm2b!(Tpm2bDigest, MAX_DIGEST_SIZE);
37tpm2b!(Tpm2bEccParameter, MAX_ECC_KEY_BYTES);
38tpm2b!(Tpm2bEncryptedSecret, MAX_ECC_KEY_BYTES);
39tpm2b!(Tpm2bEvent, MAX_EVENT_SIZE);
40tpm2b!(Tpm2bMaxBuffer, MAX_BUFFER_SIZE);
41tpm2b!(Tpm2bMaxNvBuffer, MAX_NV_BUFFER_SIZE);
42tpm2b!(Tpm2bName, { MAX_DIGEST_SIZE + 2 });
43tpm2b!(Tpm2bNonce, MAX_DIGEST_SIZE);
44tpm2b!(Tpm2bOperand, MAX_DIGEST_SIZE);
45tpm2b!(Tpm2bPrivate, MAX_PRIVATE_SIZE);
46tpm2b!(Tpm2bPrivateKeyRsa, MAX_RSA_KEY_BYTES);
47tpm2b!(Tpm2bPublicKeyRsa, MAX_RSA_KEY_BYTES);
48tpm2b!(Tpm2bSensitiveData, MAX_SENSITIVE_DATA);
49tpm2b!(Tpm2bSymKey, MAX_SYM_KEY_BYTES);
50tpm2b!(Tpm2bData, MAX_SENSITIVE_DATA);
51tpm2b!(Tpm2bTimeout, 8);
52tpm2b!(Tpm2bIv, 16);
53
54tpm2b_struct! {
55    #[derive(Debug, PartialEq, Eq, Clone, Default)]
56    Tpm2bPublic,
57    TpmtPublic
58}
59tpm2b_struct! {
60    #[derive(Debug, PartialEq, Eq, Clone, Default)]
61    Tpm2bSensitiveCreate,
62    TpmsSensitiveCreate
63}
64tpm2b_struct! {
65    #[derive(Debug, PartialEq, Eq, Clone)]
66    Tpm2bSensitive,
67    TpmtSensitive
68}
69tpm2b_struct! {
70    #[derive(Debug, PartialEq, Eq, Clone, Default)]
71    Tpm2bCreationData,
72    TpmsCreationData
73}
74tpm2b_struct! {
75    #[derive(Debug, PartialEq, Eq, Clone)]
76    Tpm2bAttest,
77    TpmsAttest
78}
79tpm2b_struct! {
80    #[derive(Debug, PartialEq, Eq, Clone)]
81    Tpm2bNvPublic,
82    TpmsNvPublic
83}
84tpm2b_struct! {
85    #[derive(Debug, PartialEq, Eq, Clone, Default)]
86    Tpm2bIdObject,
87    TpmsIdObject
88}
89
90tpm2b_struct! {
91    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
92    Tpm2bEccPoint,
93    TpmsEccPoint
94}
95
96tpm2b_struct! {
97    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
98    Tpm2bNvPublic2,
99    TpmtNvPublic2
100}
101
102tpml!(TpmlAcCapabilities, TpmsAcOutput, 64);
103tpml!(TpmlAlgProperty, TpmsAlgProperty, 64);
104tpml!(TpmlAlg, TpmAlgId, 64);
105tpml!(TpmlCc, TpmCc, 256);
106tpml!(TpmlDigest, Tpm2bDigest, 8);
107tpml!(TpmlDigestValues, TpmtHa, 8);
108tpml!(TpmlHandle, u32, 128);
109tpml!(TpmlPcrSelection, TpmsPcrSelection, 8);