VirtualBox

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

Last change on this file since 94480 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette