1 | /** @file
|
---|
2 | * IPRT Trusted Platform Module API abstracting host specific APIs.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2021-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_tpm_h
|
---|
27 | #define IPRT_INCLUDED_tpm_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/types.h>
|
---|
33 |
|
---|
34 | #include <iprt/formats/tpm.h>
|
---|
35 |
|
---|
36 |
|
---|
37 | RT_C_DECLS_BEGIN
|
---|
38 |
|
---|
39 | /** @defgroup grp_rt_tpm IPRT Trusted Platform Module API
|
---|
40 | * @ingroup grp_rt
|
---|
41 | *
|
---|
42 | * This API provides a uniform way to access a Trusted Platform Module across all
|
---|
43 | * supported hosts.
|
---|
44 | *
|
---|
45 | * @{
|
---|
46 | */
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * TPM version.
|
---|
51 | */
|
---|
52 | typedef enum RTTPMVERSION
|
---|
53 | {
|
---|
54 | /** The usual invalid option. */
|
---|
55 | RTTPMVERSION_INVALID = 0,
|
---|
56 | /** TPM conforms to version 1.2 of the TCG specification. */
|
---|
57 | RTTPMVERSION_1_2,
|
---|
58 | /** TPM conforms to version 2.0 of the TCG specification. */
|
---|
59 | RTTPMVERSION_2_0,
|
---|
60 | /** TPM version couldn't be acquired. */
|
---|
61 | RTTPMVERSION_UNKNOWN,
|
---|
62 | /** Usual 32bit hack. */
|
---|
63 | RTTPMVERSION_32BIT_HACK = 0x7fffffff
|
---|
64 | } RTTPMVERSION;
|
---|
65 | /** Pointer to a TPM version. */
|
---|
66 | typedef RTTPMVERSION *PRTTPMVERSION;
|
---|
67 |
|
---|
68 | /** TPM handle. */
|
---|
69 | typedef struct RTTPMINT *RTTPM;
|
---|
70 | /** Pointer to a TPM handle. */
|
---|
71 | typedef RTTPM *PRTTPM;
|
---|
72 | /** NIL TPM handle value. */
|
---|
73 | #define NIL_RTTPM ((RTTPM)0)
|
---|
74 |
|
---|
75 |
|
---|
76 | /** Default TPM of the host. */
|
---|
77 | #define RTTPM_ID_DEFAULT UINT32_C(0xffffffff)
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Tries to open the given TPM returning a handle.
|
---|
81 | *
|
---|
82 | * @returns IPRT status code.
|
---|
83 | * @param phTpm Where to store the handle to the TPM module on success.
|
---|
84 | * @param idTpm The TPM to open, use RTTPM_ID_DEFAULT for the default TPM of the system.
|
---|
85 | */
|
---|
86 | RTDECL(int) RTTpmOpen(PRTTPM phTpm, uint32_t idTpm);
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Closes the given TPM handle freeing all allocated resources.
|
---|
91 | *
|
---|
92 | * @returns IPRT status code.
|
---|
93 | * @param hTpm Handle of the TPM to close.
|
---|
94 | */
|
---|
95 | RTDECL(int) RTTpmClose(RTTPM hTpm);
|
---|
96 |
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Returns the version of the TPM for the given handle.
|
---|
100 | *
|
---|
101 | * @returns Version implemented by the TPM.
|
---|
102 | * @param hTpm Handle of the TPM.
|
---|
103 | */
|
---|
104 | RTDECL(RTTPMVERSION) RTTpmGetVersion(RTTPM hTpm);
|
---|
105 |
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Returns the maximum locality supported by the given TPM.
|
---|
109 | *
|
---|
110 | * @returns Maximum locality supported (0-4).
|
---|
111 | * @param hTpm Handle of the TPM.
|
---|
112 | */
|
---|
113 | RTDECL(uint32_t) RTTpmGetLocalityMax(RTTPM hTpm);
|
---|
114 |
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Cancels a currently executed request for the given TPM handle.
|
---|
118 | *
|
---|
119 | * @returns IPRT status code.
|
---|
120 | * @param hTpm Handle of the TPM.
|
---|
121 | */
|
---|
122 | RTDECL(int) RTTpmReqCancel(RTTPM hTpm);
|
---|
123 |
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Executes the given request on the given TPM handle.
|
---|
127 | *
|
---|
128 | * @returns IPRT status code.
|
---|
129 | * @param hTpm Handle of the TPM.
|
---|
130 | * @param bLoc The locality to use (only 0 might be supported on some hosts).
|
---|
131 | * @param pvReq The request data.
|
---|
132 | * @param cbReq Size of the request in bytes.
|
---|
133 | * @param pvResp Where to store the response data.
|
---|
134 | * @param cbRespMax Size of the response buffer.
|
---|
135 | * @param pcbResp Where to store the actual size of the response, optional.
|
---|
136 | */
|
---|
137 | RTDECL(int) RTTpmReqExec(RTTPM hTpm, uint8_t bLoc, const void *pvReq, size_t cbReq,
|
---|
138 | void *pvResp, size_t cbRespMax, size_t *pcbResp);
|
---|
139 |
|
---|
140 |
|
---|
141 | /** @} */
|
---|
142 |
|
---|
143 | RT_C_DECLS_END
|
---|
144 |
|
---|
145 | #endif /* !IPRT_INCLUDED_tpm_h */
|
---|
146 |
|
---|