VirtualBox

source: vbox/trunk/include/iprt/formats/tpm.h

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: tpm.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT, TPM common definitions (this is actually a protocol and not a format).
4 */
5
6/*
7 * Copyright (C) 2021-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_formats_tpm_h
38#define IPRT_INCLUDED_formats_tpm_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/asm.h>
44#include <iprt/cdefs.h>
45#include <iprt/types.h>
46#include <iprt/assertcompile.h>
47#include <iprt/string.h>
48
49
50/**
51 * TPM request header (everything big endian).
52 */
53#pragma pack(1)
54typedef struct TPMREQHDR
55{
56 /** The tag for this request. */
57 uint16_t u16Tag;
58 /** Size of the request in bytes. */
59 uint32_t cbReq;
60 /** The request ordinal to execute. */
61 uint32_t u32Ordinal;
62} TPMREQHDR;
63#pragma pack()
64AssertCompileSize(TPMREQHDR, 2 + 4 + 4);
65/** Pointer to a TPM request header. */
66typedef TPMREQHDR *PTPMREQHDR;
67/** Pointer to a const TPM request header. */
68typedef const TPMREQHDR *PCTPMREQHDR;
69
70
71/** @name TPM 1.2 request tags
72 * @{ */
73/** Command with no authentication. */
74#define TPM_TAG_RQU_COMMAND UINT16_C(0x00c1)
75/** An authenticated command with one authentication handle. */
76#define TPM_TAG_RQU_AUTH1_COMMAND UINT16_C(0x00c2)
77/** An authenticated command with two authentication handles. */
78#define TPM_TAG_RQU_AUTH2_COMMAND UINT16_C(0x00c3)
79/** @} */
80
81
82/** @name TPM 2.0 request/response tags
83 * @{ */
84/** Command with no associated session. */
85#define TPM2_ST_NO_SESSIONS UINT16_C(0x8001)
86/** Command with an associated session. */
87#define TPM2_ST_SESSIONS UINT16_C(0x8002)
88/** @} */
89
90
91/** @name TPM 1.2 request ordinals.
92 * @{ */
93/** Perform a full self test. */
94#define TPM_ORD_SELFTESTFULL UINT32_C(80)
95/** Continue the selftest. */
96#define TPM_ORD_CONTINUESELFTEST UINT32_C(83)
97/** Return the test result. */
98#define TPM_ORD_GETTESTRESULT UINT32_C(84)
99/** Get a capability. */
100#define TPM_ORD_GETCAPABILITY UINT32_C(101)
101/** @} */
102
103
104/** @name TPM 2.0 command codes.
105 * @{ */
106/** Get a capability. */
107#define TPM2_CC_GET_CAPABILITY UINT32_C(378)
108/** @} */
109
110
111/** @name Defines related to TPM_ORD_GETCAPABILITY.
112 * @{ */
113/** Return a TPM related property. */
114#define TPM_CAP_PROPERTY UINT32_C(5)
115
116/** Returns the size of the input buffer. */
117#define TPM_CAP_PROP_INPUT_BUFFER UINT32_C(0x124)
118
119/**
120 * TPM_ORD_GETCAPABILITY request.
121 */
122#pragma pack(1)
123typedef struct TPMREQGETCAPABILITY
124{
125 /** Request header. */
126 TPMREQHDR Hdr;
127 /** The capability group to query. */
128 uint32_t u32Cap;
129 /** Length of the capability. */
130 uint32_t u32Length;
131 /** The sub capability to query. */
132 uint32_t u32SubCap;
133} TPMREQGETCAPABILITY;
134#pragma pack()
135/** Pointer to a TPM_ORD_GETCAPABILITY request. */
136typedef TPMREQGETCAPABILITY *PTPMREQGETCAPABILITY;
137/** Pointer to a const TPM_ORD_GETCAPABILITY request. */
138typedef const TPMREQGETCAPABILITY *PCTPMREQGETCAPABILITY;
139/** @} */
140
141
142/** @name Defines related to TPM2_CC_GET_CAPABILITY.
143 * @{ */
144/** Return a TPM related property. */
145#define TPM2_CAP_TPM_PROPERTIES UINT32_C(6)
146
147/** Returns the size of the input buffer. */
148#define TPM2_PT_INPUT_BUFFER UINT32_C(0x10d)
149
150/**
151 * TPM2_CC_GET_CAPABILITY request.
152 */
153#pragma pack(1)
154typedef struct TPM2REQGETCAPABILITY
155{
156 /** Request header. */
157 TPMREQHDR Hdr;
158 /** The capability group to query. */
159 uint32_t u32Cap;
160 /** Property to query. */
161 uint32_t u32Property;
162 /** Number of values to return. */
163 uint32_t u32Count;
164} TPM2REQGETCAPABILITY;
165#pragma pack()
166/** Pointer to a TPM2_CC_GET_CAPABILITY request. */
167typedef TPM2REQGETCAPABILITY *PTPM2REQGETCAPABILITY;
168/** Pointer to a const TPM2_CC_GET_CAPABILITY request. */
169typedef const TPM2REQGETCAPABILITY *PCTPM2REQGETCAPABILITY;
170/** @} */
171
172
173/**
174 * TPM response header (everything big endian).
175 */
176#pragma pack(1)
177typedef struct TPMRESPHDR
178{
179 /** The tag for this request. */
180 uint16_t u16Tag;
181 /** Size of the response in bytes. */
182 uint32_t cbResp;
183 /** The error code for the response. */
184 uint32_t u32ErrCode;
185} TPMRESPHDR;
186#pragma pack()
187AssertCompileSize(TPMRESPHDR, 2 + 4 + 4);
188/** Pointer to a TPM response header. */
189typedef TPMRESPHDR *PTPMRESPHDR;
190/** Pointer to a const TPM response header. */
191typedef const TPMRESPHDR *PCTPMRESPHDR;
192
193
194/** @name TPM 1.2 response tags
195 * @{ */
196/** A response from a command with no authentication. */
197#define TPM_TAG_RSP_COMMAND UINT16_C(0x00c4)
198/** An authenticated response with one authentication handle. */
199#define TPM_TAG_RSP_AUTH1_COMMAND UINT16_C(0x00c5)
200/** An authenticated response with two authentication handles. */
201#define TPM_TAG_RSP_AUTH2_COMMAND UINT16_C(0x00c6)
202/** @} */
203
204
205/** @name TPM status codes.
206 * @{ */
207#ifndef TPM_SUCCESS
208/** Request executed successfully. */
209# define TPM_SUCCESS UINT32_C(0)
210#endif
211#ifndef TPM_AUTHFAIL
212/** Authentication failed. */
213# define TPM_AUTHFAIL UINT32_C(1)
214#endif
215#ifndef TPM_BADINDEX
216/** An index is malformed. */
217# define TPM_BADINDEX UINT32_C(2)
218#endif
219#ifndef TPM_BAD_PARAMETER
220/** A request parameter is invalid. */
221# define TPM_BAD_PARAMETER UINT32_C(3)
222#endif
223#ifndef TPM_FAIL
224/** The TPM failed to execute the request. */
225# define TPM_FAIL UINT32_C(9)
226#endif
227/** @todo Extend as need arises. */
228/** @} */
229
230
231/* Some inline helpers to account for the unaligned members of the request and response headers. */
232
233/**
234 * Returns the request tag of the given TPM request header.
235 *
236 * @returns TPM request tag in bytes.
237 * @param pTpmReqHdr Pointer to the TPM request header.
238 */
239DECLINLINE(uint16_t) RTTpmReqGetTag(PCTPMREQHDR pTpmReqHdr)
240{
241 return RT_BE2H_U16(pTpmReqHdr->u16Tag);
242}
243
244
245/**
246 * Returns the request size of the given TPM request header.
247 *
248 * @returns TPM request size in bytes.
249 * @param pTpmReqHdr Pointer to the TPM request header.
250 */
251DECLINLINE(size_t) RTTpmReqGetSz(PCTPMREQHDR pTpmReqHdr)
252{
253 uint32_t cbReq;
254 memcpy(&cbReq, &pTpmReqHdr->cbReq, sizeof(pTpmReqHdr->cbReq));
255 return RT_BE2H_U32(cbReq);
256}
257
258
259/**
260 * Returns the request ordinal of the given TPM request header.
261 *
262 * @returns TPM request ordinal in bytes.
263 * @param pTpmReqHdr Pointer to the TPM request header.
264 */
265DECLINLINE(uint32_t) RTTpmReqGetOrdinal(PCTPMREQHDR pTpmReqHdr)
266{
267 uint32_t u32Ordinal;
268 memcpy(&u32Ordinal, &pTpmReqHdr->u32Ordinal, sizeof(pTpmReqHdr->u32Ordinal));
269 return RT_BE2H_U32(u32Ordinal);
270}
271
272
273/**
274 * Returns the response tag of the given TPM response header.
275 *
276 * @returns TPM request tag in bytes.
277 * @param pTpmRespHdr Pointer to the TPM response header.
278 */
279DECLINLINE(uint16_t) RTTpmRespGetTag(PCTPMRESPHDR pTpmRespHdr)
280{
281 return RT_BE2H_U16(pTpmRespHdr->u16Tag);
282}
283
284
285/**
286 * Returns the response size included in the given TPM response header.
287 *
288 * @returns TPM response size in bytes.
289 * @param pTpmRespHdr Pointer to the TPM response header.
290 */
291DECLINLINE(size_t) RTTpmRespGetSz(PCTPMRESPHDR pTpmRespHdr)
292{
293 uint32_t cbResp;
294 memcpy(&cbResp, &pTpmRespHdr->cbResp, sizeof(pTpmRespHdr->cbResp));
295 return RT_BE2H_U32(cbResp);
296}
297
298
299/**
300 * Returns the error code of the given TPM response header.
301 *
302 * @returns TPM response error code.
303 * @param pTpmRespHdr Pointer to the TPM response header.
304 */
305DECLINLINE(uint32_t) RTTpmRespGetErrCode(PCTPMRESPHDR pTpmRespHdr)
306{
307 uint32_t u32ErrCode;
308 memcpy(&u32ErrCode, &pTpmRespHdr->u32ErrCode, sizeof(pTpmRespHdr->u32ErrCode));
309 return RT_BE2H_U32(u32ErrCode);
310}
311
312#endif /* !IPRT_INCLUDED_formats_tpm_h */
313
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use