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    no_sessions: true,
22    with_sessions: true,
23    handles: {
24        pub key_handle: crate::data::TpmiDhObject,
25    },
26    parameters: {
27        pub message: Tpm2bPublicKeyRsa,
28        pub in_scheme: TpmtRsaDecrypt,
29        pub label: Tpm2bData,
30    }
31}
32
33tpm_struct! {
34    #[derive(Debug, PartialEq, Eq, Clone)]
35    kind: Response,
36    name: TpmRsaEncryptResponse,
37    cc: TpmCc::RsaEncrypt,
38    no_sessions: true,
39    with_sessions: true,
40    handles: {},
41    parameters: {
42        pub out_data: Tpm2bPublicKeyRsa,
43    }
44}
45
46tpm_struct! {
47    #[derive(Debug, PartialEq, Eq, Clone)]
48    kind: Command,
49    name: TpmRsaDecryptCommand,
50    cc: TpmCc::RsaDecrypt,
51    no_sessions: false,
52    with_sessions: true,
53    handles: {
54        pub key_handle: crate::data::TpmiDhObject,
55    },
56    parameters: {
57        pub cipher_text: Tpm2bPublicKeyRsa,
58        pub in_scheme: TpmtRsaDecrypt,
59        pub label: Tpm2bData,
60    }
61}
62
63tpm_struct! {
64    #[derive(Debug, PartialEq, Eq, Clone)]
65    kind: Response,
66    name: TpmRsaDecryptResponse,
67    cc: TpmCc::RsaDecrypt,
68    no_sessions: false,
69    with_sessions: true,
70    handles: {},
71    parameters: {
72        pub message: Tpm2bPublicKeyRsa,
73    }
74}
75
76tpm_struct! {
77    #[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
78    kind: Command,
79    name: TpmEcdhKeyGenCommand,
80    cc: TpmCc::EcdhKeyGen,
81    no_sessions: true,
82    with_sessions: true,
83    handles: {
84        pub key_handle: crate::data::TpmiDhObject,
85    },
86    parameters: {}
87}
88
89tpm_struct! {
90    #[derive(Debug, PartialEq, Eq, Clone)]
91    kind: Response,
92    name: TpmEcdhKeyGenResponse,
93    cc: TpmCc::EcdhKeyGen,
94    no_sessions: true,
95    with_sessions: true,
96    handles: {},
97    parameters: {
98        pub z_point: Tpm2bEccPoint,
99        pub pub_point: Tpm2bEccPoint,
100    }
101}
102
103tpm_struct! {
104    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
105    kind: Command,
106    name: TpmEcdhZGenCommand,
107    cc: TpmCc::EcdhZGen,
108    no_sessions: false,
109    with_sessions: true,
110    handles: {
111        pub key_handle: crate::data::TpmiDhObject,
112    },
113    parameters: {
114        pub in_point: Tpm2bEccPoint,
115    }
116}
117
118tpm_struct! {
119    #[derive(Debug, PartialEq, Eq, Clone)]
120    kind: Response,
121    name: TpmEcdhZGenResponse,
122    cc: TpmCc::EcdhZGen,
123    no_sessions: false,
124    with_sessions: true,
125    handles: {},
126    parameters: {
127        pub out_point: Tpm2bEccPoint,
128    }
129}
130
131tpm_struct! {
132    #[derive(Debug, PartialEq, Eq, Copy, Clone)]
133    kind: Command,
134    name: TpmEccParametersCommand,
135    cc: TpmCc::EccParameters,
136    no_sessions: true,
137    with_sessions: true,
138    handles: {},
139    parameters: {
140        pub curve_id: TpmEccCurve,
141    }
142}
143
144tpm_struct! {
145    #[derive(Debug, PartialEq, Eq, Clone)]
146    kind: Response,
147    name: TpmEccParametersResponse,
148    cc: TpmCc::EccParameters,
149    no_sessions: true,
150    with_sessions: true,
151    handles: {},
152    parameters: {
153        pub parameters: TpmsAlgorithmDetailEcc,
154    }
155}
156
157tpm_struct! {
158    #[derive(Debug, PartialEq, Eq, Clone)]
159    kind: Command,
160    name: TpmZGen2PhaseCommand,
161    cc: TpmCc::ZGen2Phase,
162    no_sessions: false,
163    with_sessions: true,
164    handles: {
165        pub key_a: crate::data::TpmiDhObject,
166    },
167    parameters: {
168        pub in_qsb: Tpm2bEccPoint,
169        pub in_qeb: Tpm2bEccPoint,
170        pub in_scheme: TpmiEccKeyExchange,
171        pub counter: u16,
172    }
173}
174
175tpm_struct! {
176    #[derive(Debug, PartialEq, Eq, Clone)]
177    kind: Response,
178    name: TpmZGen2PhaseResponse,
179    cc: TpmCc::ZGen2Phase,
180    no_sessions: false,
181    with_sessions: true,
182    handles: {},
183    parameters: {
184        pub out_z1: Tpm2bEccPoint,
185        pub out_z2: Tpm2bEccPoint,
186    }
187}
188
189tpm_struct! {
190    #[derive(Debug, PartialEq, Eq, Clone)]
191    kind: Command,
192    name: TpmEccEncryptCommand,
193    cc: TpmCc::EccEncrypt,
194    no_sessions: true,
195    with_sessions: true,
196    handles: {
197        pub key_handle: crate::data::TpmiDhObject,
198    },
199    parameters: {
200        pub plaintext: Tpm2bMaxBuffer,
201        pub in_scheme: TpmtKdfScheme,
202    }
203}
204
205tpm_struct! {
206    #[derive(Debug, PartialEq, Eq, Clone)]
207    kind: Response,
208    name: TpmEccEncryptResponse,
209    cc: TpmCc::EccEncrypt,
210    no_sessions: true,
211    with_sessions: true,
212    handles: {},
213    parameters: {
214        pub c1: Tpm2bEccPoint,
215        pub c2: crate::data::Tpm2bMaxBuffer,
216        pub c3: crate::data::Tpm2bDigest,
217    }
218}
219
220tpm_struct! {
221    #[derive(Debug, PartialEq, Eq, Clone)]
222    kind: Command,
223    name: TpmEccDecryptCommand,
224    cc: TpmCc::EccDecrypt,
225    no_sessions: false,
226    with_sessions: true,
227    handles: {
228        pub key_handle: crate::data::TpmiDhObject,
229    },
230    parameters: {
231        pub c1: Tpm2bEccPoint,
232        pub c2: crate::data::Tpm2bMaxBuffer,
233        pub c3: crate::data::Tpm2bDigest,
234        pub in_scheme: TpmtKdfScheme,
235    }
236}
237
238tpm_struct! {
239    #[derive(Debug, PartialEq, Eq, Clone)]
240    kind: Response,
241    name: TpmEccDecryptResponse,
242    cc: TpmCc::EccDecrypt,
243    no_sessions: false,
244    with_sessions: true,
245    handles: {},
246    parameters: {
247        pub plaintext: crate::data::Tpm2bMaxBuffer,
248    }
249}