tpm2_protocol/message/
asymmetric.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) 2025 Opinsys Oy
3// Copyright (c) 2024-2025 Jarkko Sakkinen
4
5//! 14 Asymmetric Primitives
6
7use crate::{
8    data::{
9        Tpm2bData, Tpm2bEccPoint, Tpm2bMaxBuffer, Tpm2bPublicKeyRsa, TpmCc, TpmEccCurve,
10        TpmiEccKeyExchange, TpmsAlgorithmDetailEcc, TpmtKdfScheme, TpmtRsaDecrypt,
11    },
12    tpm_struct,
13};
14use core::fmt::Debug;
15
16tpm_struct! {
17    #[derive(Debug, PartialEq, Eq, Clone)]
18    kind: Command,
19    name: TpmRsaEncryptCommand,
20    cc: TpmCc::RsaEncrypt,
21    handles: {
22        pub key_handle: crate::data::TpmiDhObject,
23    },
24    parameters: {
25        pub message: Tpm2bPublicKeyRsa,
26        pub in_scheme: TpmtRsaDecrypt,
27        pub label: Tpm2bData,
28    }
29}
30
31tpm_struct! {
32    #[derive(Debug, PartialEq, Eq, Clone)]
33    kind: Response,
34    name: TpmRsaEncryptResponse,
35    cc: TpmCc::RsaEncrypt,
36    handles: {},
37    parameters: {
38        pub out_data: Tpm2bPublicKeyRsa,
39    }
40}
41
42tpm_struct! {
43    #[derive(Debug, PartialEq, Eq, Clone)]
44    kind: Command,
45    name: TpmRsaDecryptCommand,
46    cc: TpmCc::RsaDecrypt,
47    handles: {
48        pub key_handle: crate::data::TpmiDhObject,
49    },
50    parameters: {
51        pub cipher_text: Tpm2bPublicKeyRsa,
52        pub in_scheme: TpmtRsaDecrypt,
53        pub label: Tpm2bData,
54    }
55}
56
57tpm_struct! {
58    #[derive(Debug, PartialEq, Eq, Clone)]
59    kind: Response,
60    name: TpmRsaDecryptResponse,
61    cc: TpmCc::RsaDecrypt,
62    handles: {},
63    parameters: {
64        pub message: Tpm2bPublicKeyRsa,
65    }
66}
67
68tpm_struct! {
69    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
70    kind: Command,
71    name: TpmEcdhKeyGenCommand,
72    cc: TpmCc::EcdhKeyGen,
73    handles: {
74        pub key_handle: crate::data::TpmiDhObject,
75    },
76    parameters: {}
77}
78
79tpm_struct! {
80    #[derive(Debug, PartialEq, Eq, Clone)]
81    kind: Response,
82    name: TpmEcdhKeyGenResponse,
83    cc: TpmCc::EcdhKeyGen,
84    handles: {},
85    parameters: {
86        pub z_point: Tpm2bEccPoint,
87        pub pub_point: Tpm2bEccPoint,
88    }
89}
90
91tpm_struct! {
92    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
93    kind: Command,
94    name: TpmEcdhZGenCommand,
95    cc: TpmCc::EcdhZGen,
96    handles: {
97        pub key_handle: crate::data::TpmiDhObject,
98    },
99    parameters: {
100        pub in_point: Tpm2bEccPoint,
101    }
102}
103
104tpm_struct! {
105    #[derive(Debug, PartialEq, Eq, Clone)]
106    kind: Response,
107    name: TpmEcdhZGenResponse,
108    cc: TpmCc::EcdhZGen,
109    handles: {},
110    parameters: {
111        pub out_point: Tpm2bEccPoint,
112    }
113}
114
115tpm_struct! {
116    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
117    kind: Command,
118    name: TpmEccParametersCommand,
119    cc: TpmCc::EccParameters,
120    handles: {},
121    parameters: {
122        pub curve_id: TpmEccCurve,
123    }
124}
125
126tpm_struct! {
127    #[derive(Debug, PartialEq, Eq, Clone)]
128    kind: Response,
129    name: TpmEccParametersResponse,
130    cc: TpmCc::EccParameters,
131    handles: {},
132    parameters: {
133        pub parameters: TpmsAlgorithmDetailEcc,
134    }
135}
136
137tpm_struct! {
138    #[derive(Debug, PartialEq, Eq, Clone)]
139    kind: Command,
140    name: TpmZGen2PhaseCommand,
141    cc: TpmCc::ZGen2Phase,
142    handles: {
143        pub key_a: crate::data::TpmiDhObject,
144    },
145    parameters: {
146        pub in_qsb: Tpm2bEccPoint,
147        pub in_qeb: Tpm2bEccPoint,
148        pub in_scheme: TpmiEccKeyExchange,
149        pub counter: u16,
150    }
151}
152
153tpm_struct! {
154    #[derive(Debug, PartialEq, Eq, Clone)]
155    kind: Response,
156    name: TpmZGen2PhaseResponse,
157    cc: TpmCc::ZGen2Phase,
158    handles: {},
159    parameters: {
160        pub out_z1: Tpm2bEccPoint,
161        pub out_z2: Tpm2bEccPoint,
162    }
163}
164
165tpm_struct! {
166    #[derive(Debug, PartialEq, Eq, Clone)]
167    kind: Command,
168    name: TpmEccEncryptCommand,
169    cc: TpmCc::EccEncrypt,
170    handles: {
171        pub key_handle: crate::data::TpmiDhObject,
172    },
173    parameters: {
174        pub plaintext: Tpm2bMaxBuffer,
175        pub in_scheme: TpmtKdfScheme,
176    }
177}
178
179tpm_struct! {
180    #[derive(Debug, PartialEq, Eq, Clone)]
181    kind: Response,
182    name: TpmEccEncryptResponse,
183    cc: TpmCc::EccEncrypt,
184    handles: {},
185    parameters: {
186        pub c1: Tpm2bEccPoint,
187        pub c2: crate::data::Tpm2bMaxBuffer,
188        pub c3: crate::data::Tpm2bDigest,
189    }
190}
191
192tpm_struct! {
193    #[derive(Debug, PartialEq, Eq, Clone)]
194    kind: Command,
195    name: TpmEccDecryptCommand,
196    cc: TpmCc::EccDecrypt,
197    handles: {
198        pub key_handle: crate::data::TpmiDhObject,
199    },
200    parameters: {
201        pub c1: Tpm2bEccPoint,
202        pub c2: crate::data::Tpm2bMaxBuffer,
203        pub c3: crate::data::Tpm2bDigest,
204        pub in_scheme: TpmtKdfScheme,
205    }
206}
207
208tpm_struct! {
209    #[derive(Debug, PartialEq, Eq, Clone)]
210    kind: Response,
211    name: TpmEccDecryptResponse,
212    cc: TpmCc::EccDecrypt,
213    handles: {},
214    parameters: {
215        pub plaintext: crate::data::Tpm2bMaxBuffer,
216    }
217}