]>
Commit | Line | Data |
---|---|---|
39c9604a SB |
1 | /********************************************************************************/ |
2 | /* */ | |
3 | /* LibTPM TPM 1.2 call interface functions */ | |
4 | /* Written by Stefan Berger */ | |
5 | /* IBM Thomas J. Watson Research Center */ | |
6 | /* */ | |
7 | /* (c) Copyright IBM Corporation 2015. */ | |
8 | /* */ | |
9 | /* All rights reserved. */ | |
10 | /* */ | |
11 | /* Redistribution and use in source and binary forms, with or without */ | |
12 | /* modification, are permitted provided that the following conditions are */ | |
13 | /* met: */ | |
14 | /* */ | |
15 | /* Redistributions of source code must retain the above copyright notice, */ | |
16 | /* this list of conditions and the following disclaimer. */ | |
17 | /* */ | |
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. */ | |
21 | /* */ | |
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. */ | |
25 | /* */ | |
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 | /********************************************************************************/ | |
38 | ||
39 | #include <config.h> | |
40 | ||
41 | #include <assert.h> | |
42 | #include <stdio.h> | |
43 | #include <stdlib.h> | |
44 | ||
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" | |
51 | ||
52 | TPM_RESULT TPM12_MainInit(void) | |
53 | { | |
54 | return TPM_MainInit(); | |
55 | } | |
56 | ||
57 | void TPM12_Terminate(void) | |
58 | { | |
59 | TPM_Global_Delete(tpm_instances[0]); | |
60 | free(tpm_instances[0]); | |
61 | tpm_instances[0] = NULL; | |
62 | } | |
63 | ||
64 | TPM_RESULT TPM12_Process(unsigned char **respbuffer, uint32_t *resp_size, | |
65 | uint32_t *respbufsize, | |
66 | unsigned char *command, uint32_t command_size) | |
67 | { | |
68 | *resp_size = 0; | |
69 | return TPM_ProcessA(respbuffer, resp_size, respbufsize, | |
70 | command, command_size); | |
71 | } | |
72 | ||
73 | TPM_RESULT TPM12_VolatileAllStore(unsigned char **buffer, | |
74 | uint32_t *buflen) | |
75 | { | |
76 | TPM_RESULT rc; | |
77 | TPM_STORE_BUFFER tsb; | |
78 | TPM_Sbuffer_Init(&tsb); | |
79 | uint32_t total; | |
80 | ||
81 | #ifdef TPM_DEBUG | |
82 | assert(tpm_instances[0] != NULL); | |
83 | #endif | |
84 | ||
85 | rc = TPM_VolatileAll_Store(&tsb, tpm_instances[0]); | |
86 | ||
87 | if (rc == TPM_SUCCESS) { | |
88 | /* caller now owns the buffer and needs to free it */ | |
89 | TPM_Sbuffer_GetAll(&tsb, buffer, buflen, &total); | |
90 | } else { | |
91 | TPM_Sbuffer_Delete(&tsb); | |
92 | *buflen = 0; | |
93 | *buffer = NULL; | |
94 | } | |
95 | ||
96 | return rc; | |
97 | } | |
98 | ||
99 | TPM_RESULT TPM12_GetTPMProperty(enum TPMLIB_TPMProperty prop, | |
100 | int *result) | |
101 | { | |
102 | switch (prop) { | |
103 | case TPMPROP_TPM_RSA_KEY_LENGTH_MAX: | |
104 | *result = TPM_RSA_KEY_LENGTH_MAX; | |
105 | break; | |
106 | ||
107 | case TPMPROP_TPM_KEY_HANDLES: | |
108 | *result = TPM_KEY_HANDLES; | |
109 | break; | |
110 | ||
111 | case TPMPROP_TPM_OWNER_EVICT_KEY_HANDLES: | |
112 | *result = TPM_OWNER_EVICT_KEY_HANDLES; | |
113 | break; | |
114 | ||
115 | case TPMPROP_TPM_MIN_AUTH_SESSIONS: | |
116 | *result = TPM_MIN_AUTH_SESSIONS; | |
117 | break; | |
118 | ||
119 | case TPMPROP_TPM_MIN_TRANS_SESSIONS: | |
120 | *result = TPM_MIN_TRANS_SESSIONS; | |
121 | break; | |
122 | ||
123 | case TPMPROP_TPM_MIN_DAA_SESSIONS: | |
124 | *result = TPM_MIN_DAA_SESSIONS; | |
125 | break; | |
126 | ||
127 | case TPMPROP_TPM_MIN_SESSION_LIST: | |
128 | *result = TPM_MIN_SESSION_LIST; | |
129 | break; | |
130 | ||
131 | case TPMPROP_TPM_MIN_COUNTERS: | |
132 | *result = TPM_MIN_COUNTERS; | |
133 | break; | |
134 | ||
135 | case TPMPROP_TPM_NUM_FAMILY_TABLE_ENTRY_MIN: | |
136 | *result = TPM_NUM_FAMILY_TABLE_ENTRY_MIN; | |
137 | break; | |
138 | ||
139 | case TPMPROP_TPM_NUM_DELEGATE_TABLE_ENTRY_MIN: | |
140 | *result = TPM_NUM_DELEGATE_TABLE_ENTRY_MIN; | |
141 | break; | |
142 | ||
143 | case TPMPROP_TPM_SPACE_SAFETY_MARGIN: | |
144 | *result = TPM_SPACE_SAFETY_MARGIN; | |
145 | break; | |
146 | ||
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); | |
151 | break; | |
152 | ||
153 | case TPMPROP_TPM_MAX_SAVESTATE_SPACE: | |
154 | *result = TPM_MAX_SAVESTATE_SPACE; | |
155 | break; | |
156 | ||
157 | case TPMPROP_TPM_MAX_VOLATILESTATE_SPACE: | |
158 | *result = TPM_MAX_VOLATILESTATE_SPACE; | |
159 | break; | |
160 | ||
161 | default: | |
162 | return TPM_FAIL; | |
163 | } | |
164 | ||
165 | return TPM_SUCCESS; | |
166 | } | |
167 | ||
ae3f105a SB |
168 | uint32_t TPM12_SetBufferSize(uint32_t wanted_size, |
169 | uint32_t *min_size, | |
170 | uint32_t *max_size) | |
bc195a34 SB |
171 | { |
172 | /* TPM 1.2 has a fixed buffer size; the TIS can handle that */ | |
ae3f105a SB |
173 | if (min_size) |
174 | *min_size = TPM_BUFFER_MAX; | |
175 | if (max_size) | |
176 | *max_size = TPM_BUFFER_MAX; | |
bc195a34 SB |
177 | return TPM_BUFFER_MAX; |
178 | } | |
179 | ||
39c9604a SB |
180 | const struct tpm_interface TPM12Interface = { |
181 | .MainInit = TPM12_MainInit, | |
182 | .Terminate = TPM12_Terminate, | |
183 | .Process = TPM12_Process, | |
184 | .VolatileAllStore = TPM12_VolatileAllStore, | |
185 | .GetTPMProperty = TPM12_GetTPMProperty, | |
186 | .TpmEstablishedGet = TPM12_IO_TpmEstablished_Get, | |
187 | .HashStart = TPM12_IO_Hash_Start, | |
188 | .HashData = TPM12_IO_Hash_Data, | |
189 | .HashEnd = TPM12_IO_Hash_End, | |
bc195a34 | 190 | .SetBufferSize = TPM12_SetBufferSize, |
39c9604a | 191 | }; |