1 /********************************************************************************/
3 /* LibTPM TPM 1.2 call interface functions */
4 /* Written by Stefan Berger */
5 /* IBM Thomas J. Watson Research Center */
7 /* (c) Copyright IBM Corporation 2015. */
9 /* All rights reserved. */
11 /* Redistribution and use in source and binary forms, with or without */
12 /* modification, are permitted provided that the following conditions are */
15 /* Redistributions of source code must retain the above copyright notice, */
16 /* this list of conditions and the following disclaimer. */
18 /* Redistributions in binary form must reproduce the above copyright */
19 /* notice, this list of conditions and the following disclaimer in the */
20 /* documentation and/or other materials provided with the distribution. */
22 /* Neither the names of the IBM Corporation nor the names of its */
23 /* contributors may be used to endorse or promote products derived from */
24 /* this software without specific prior written permission. */
26 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
27 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
28 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
29 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
30 /* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
31 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
32 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
33 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
34 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
35 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
36 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
37 /********************************************************************************/
45 #include "tpm12/tpm_debug.h"
46 #include "tpm_error.h"
47 #include "tpm12/tpm_init.h"
48 #include "tpm_library_intern.h"
49 #include "tpm12/tpm_process.h"
50 #include "tpm12/tpm_startup.h"
52 TPM_RESULT
TPM12_MainInit(void)
54 return TPM_MainInit();
57 void TPM12_Terminate(void)
59 TPM_Global_Delete(tpm_instances
[0]);
60 free(tpm_instances
[0]);
61 tpm_instances
[0] = NULL
;
64 TPM_RESULT
TPM12_Process(unsigned char **respbuffer
, uint32_t *resp_size
,
65 uint32_t *respbufsize
,
66 unsigned char *command
, uint32_t command_size
)
69 return TPM_ProcessA(respbuffer
, resp_size
, respbufsize
,
70 command
, command_size
);
73 TPM_RESULT
TPM12_VolatileAllStore(unsigned char **buffer
,
78 TPM_Sbuffer_Init(&tsb
);
82 assert(tpm_instances
[0] != NULL
);
85 rc
= TPM_VolatileAll_Store(&tsb
, tpm_instances
[0]);
87 if (rc
== TPM_SUCCESS
) {
88 /* caller now owns the buffer and needs to free it */
89 TPM_Sbuffer_GetAll(&tsb
, buffer
, buflen
, &total
);
91 TPM_Sbuffer_Delete(&tsb
);
99 TPM_RESULT
TPM12_GetTPMProperty(enum TPMLIB_TPMProperty prop
,
103 case TPMPROP_TPM_RSA_KEY_LENGTH_MAX
:
104 *result
= TPM_RSA_KEY_LENGTH_MAX
;
107 case TPMPROP_TPM_KEY_HANDLES
:
108 *result
= TPM_KEY_HANDLES
;
111 case TPMPROP_TPM_OWNER_EVICT_KEY_HANDLES
:
112 *result
= TPM_OWNER_EVICT_KEY_HANDLES
;
115 case TPMPROP_TPM_MIN_AUTH_SESSIONS
:
116 *result
= TPM_MIN_AUTH_SESSIONS
;
119 case TPMPROP_TPM_MIN_TRANS_SESSIONS
:
120 *result
= TPM_MIN_TRANS_SESSIONS
;
123 case TPMPROP_TPM_MIN_DAA_SESSIONS
:
124 *result
= TPM_MIN_DAA_SESSIONS
;
127 case TPMPROP_TPM_MIN_SESSION_LIST
:
128 *result
= TPM_MIN_SESSION_LIST
;
131 case TPMPROP_TPM_MIN_COUNTERS
:
132 *result
= TPM_MIN_COUNTERS
;
135 case TPMPROP_TPM_NUM_FAMILY_TABLE_ENTRY_MIN
:
136 *result
= TPM_NUM_FAMILY_TABLE_ENTRY_MIN
;
139 case TPMPROP_TPM_NUM_DELEGATE_TABLE_ENTRY_MIN
:
140 *result
= TPM_NUM_DELEGATE_TABLE_ENTRY_MIN
;
143 case TPMPROP_TPM_SPACE_SAFETY_MARGIN
:
144 *result
= TPM_SPACE_SAFETY_MARGIN
;
147 case TPMPROP_TPM_MAX_NV_SPACE
:
148 /* fill up 20 kb.; this provides some safety margin (currently
149 >4Kb) for possible future expansion of this blob */
150 *result
= ROUNDUP(TPM_MAX_NV_SPACE
, 20 * 1024);
153 case TPMPROP_TPM_MAX_SAVESTATE_SPACE
:
154 *result
= TPM_MAX_SAVESTATE_SPACE
;
157 case TPMPROP_TPM_MAX_VOLATILESTATE_SPACE
:
158 *result
= TPM_MAX_VOLATILESTATE_SPACE
;
168 static uint32_t tpm12_buffersize
= TPM_BUFFER_MAX
;
170 uint32_t TPM12_SetBufferSize(uint32_t wanted_size
,
174 if (wanted_size
== 0)
175 return tpm12_buffersize
;
178 *min_size
= TPM_BUFFER_MIN
;
180 *max_size
= TPM_BUFFER_MAX
;
182 if (wanted_size
> TPM_BUFFER_MAX
)
183 wanted_size
= TPM_BUFFER_MAX
;
184 else if (wanted_size
< TPM_BUFFER_MIN
)
185 wanted_size
= TPM_BUFFER_MIN
;
187 tpm12_buffersize
= wanted_size
;
189 return tpm12_buffersize
;
192 uint32_t TPM12_GetBufferSize(void)
194 return TPM12_SetBufferSize(0, NULL
, NULL
);
197 const struct tpm_interface TPM12Interface
= {
198 .MainInit
= TPM12_MainInit
,
199 .Terminate
= TPM12_Terminate
,
200 .Process
= TPM12_Process
,
201 .VolatileAllStore
= TPM12_VolatileAllStore
,
202 .GetTPMProperty
= TPM12_GetTPMProperty
,
203 .TpmEstablishedGet
= TPM12_IO_TpmEstablished_Get
,
204 .HashStart
= TPM12_IO_Hash_Start
,
205 .HashData
= TPM12_IO_Hash_Data
,
206 .HashEnd
= TPM12_IO_Hash_End
,
207 .SetBufferSize
= TPM12_SetBufferSize
,