1 | /********************************************************************************/
|
---|
2 | /* */
|
---|
3 | /* LibTPM internal interface functions */
|
---|
4 | /* Written by Stefan Berger */
|
---|
5 | /* IBM Thomas J. Watson Research Center */
|
---|
6 | /* $Id: tpm_library_intern.h 4432 2011-02-11 15:30:31Z kgoldman $ */
|
---|
7 | /* */
|
---|
8 | /* (c) Copyright IBM Corporation 2011. */
|
---|
9 | /* */
|
---|
10 | /* All rights reserved. */
|
---|
11 | /* */
|
---|
12 | /* Redistribution and use in source and binary forms, with or without */
|
---|
13 | /* modification, are permitted provided that the following conditions are */
|
---|
14 | /* met: */
|
---|
15 | /* */
|
---|
16 | /* Redistributions of source code must retain the above copyright notice, */
|
---|
17 | /* this list of conditions and the following disclaimer. */
|
---|
18 | /* */
|
---|
19 | /* Redistributions in binary form must reproduce the above copyright */
|
---|
20 | /* notice, this list of conditions and the following disclaimer in the */
|
---|
21 | /* documentation and/or other materials provided with the distribution. */
|
---|
22 | /* */
|
---|
23 | /* Neither the names of the IBM Corporation nor the names of its */
|
---|
24 | /* contributors may be used to endorse or promote products derived from */
|
---|
25 | /* this software without specific prior written permission. */
|
---|
26 | /* */
|
---|
27 | /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
|
---|
28 | /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
|
---|
29 | /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
|
---|
30 | /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
|
---|
31 | /* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
|
---|
32 | /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
|
---|
33 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
---|
34 | /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
|
---|
35 | /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
|
---|
36 | /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
|
---|
37 | /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
---|
38 | /********************************************************************************/
|
---|
39 | #ifndef TPM_LIBRARY_INTERN_H
|
---|
40 | #define TPM_LIBRARY_INTERN_H
|
---|
41 |
|
---|
42 | #include <stdbool.h>
|
---|
43 | #include "compiler.h"
|
---|
44 | #include "tpm_library.h"
|
---|
45 |
|
---|
46 | #define ROUNDUP(VAL, SIZE) \
|
---|
47 | ( ( (VAL) + (SIZE) - 1 ) / (SIZE) ) * (SIZE)
|
---|
48 |
|
---|
49 | #define _STRINGIFY(x) #x
|
---|
50 | #define STRINGIFY(x) _STRINGIFY(x)
|
---|
51 |
|
---|
52 | struct libtpms_callbacks *TPMLIB_GetCallbacks(void);
|
---|
53 |
|
---|
54 | /* additional TPM 2 error codes from TPM 1.2 */
|
---|
55 | #define TPM_RC_BAD_PARAMETER 0x03
|
---|
56 | #define TPM_RC_BAD_VERSION 0x2e
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * TPM functionality must all be accessible with this interface
|
---|
60 | */
|
---|
61 | struct tpm_interface {
|
---|
62 | TPM_RESULT (*MainInit)(void);
|
---|
63 | void (*Terminate)(void);
|
---|
64 | uint32_t (*SetBufferSize)(uint32_t wanted_size, uint32_t *min_size,
|
---|
65 | uint32_t *max_size);
|
---|
66 | TPM_RESULT (*Process)(unsigned char **respbuffer, uint32_t *resp_size,
|
---|
67 | uint32_t *respbufsize,
|
---|
68 | unsigned char *command, uint32_t command_size);
|
---|
69 | TPM_RESULT (*VolatileAllStore)(unsigned char **buffer, uint32_t *buflen);
|
---|
70 | TPM_RESULT (*CancelCommand)(void);
|
---|
71 | TPM_RESULT (*GetTPMProperty)(enum TPMLIB_TPMProperty prop,
|
---|
72 | int *result);
|
---|
73 | char *(*GetInfo)(enum TPMLIB_InfoFlags flags);
|
---|
74 | TPM_RESULT (*TpmEstablishedGet)(TPM_BOOL *tpmEstablished);
|
---|
75 | TPM_RESULT (*TpmEstablishedReset)(void);
|
---|
76 | TPM_RESULT (*HashStart)(void);
|
---|
77 | TPM_RESULT (*HashData)(const unsigned char *data,
|
---|
78 | uint32_t data_length);
|
---|
79 | TPM_RESULT (*HashEnd)(void);
|
---|
80 | TPM_RESULT (*ValidateState)(enum TPMLIB_StateType st,
|
---|
81 | unsigned int flags);
|
---|
82 | TPM_RESULT (*SetState)(enum TPMLIB_StateType st,
|
---|
83 | const unsigned char *buffer, uint32_t buflen);
|
---|
84 | TPM_RESULT (*GetState)(enum TPMLIB_StateType st,
|
---|
85 | unsigned char **buffer, uint32_t *buflen);
|
---|
86 | };
|
---|
87 |
|
---|
88 | extern const struct tpm_interface DisabledInterface;
|
---|
89 | extern const struct tpm_interface TPM12Interface;
|
---|
90 | extern const struct tpm_interface TPM2Interface;
|
---|
91 |
|
---|
92 | /* prototypes for TPM 1.2 */
|
---|
93 | TPM_RESULT TPM12_IO_Hash_Start(void);
|
---|
94 | TPM_RESULT TPM12_IO_Hash_Data(const unsigned char *data,
|
---|
95 | uint32_t data_length);
|
---|
96 | TPM_RESULT TPM12_IO_Hash_End(void);
|
---|
97 | TPM_RESULT TPM12_IO_TpmEstablished_Get(TPM_BOOL *tpmEstablished);
|
---|
98 |
|
---|
99 | uint32_t TPM12_GetBufferSize(void);
|
---|
100 |
|
---|
101 | TPM_RESULT TPM12_IO_TpmEstablished_Reset(void);
|
---|
102 |
|
---|
103 | /* internal logging function */
|
---|
104 | int TPMLIB_LogPrintf(const char *format, ...);
|
---|
105 | void TPMLIB_LogPrintfA(unsigned int indent, const char *format, ...) \
|
---|
106 | ATTRIBUTE_FORMAT(2, 3);
|
---|
107 | void TPMLIB_LogArray(unsigned int indent, const unsigned char *data,
|
---|
108 | size_t datalen);
|
---|
109 |
|
---|
110 | #ifndef VBOX
|
---|
111 | #define TPMLIB_LogError(format, ...) \
|
---|
112 | TPMLIB_LogPrintfA(~0, "libtpms: "format, __VA_ARGS__)
|
---|
113 | #define TPMLIB_LogTPM12Error(format, ...) \
|
---|
114 | TPMLIB_LogPrintfA(~0, "libtpms/tpm12: "format, __VA_ARGS__)
|
---|
115 | #define TPMLIB_LogTPM2Error(format, ...) \
|
---|
116 | TPMLIB_LogPrintfA(~0, "libtpms/tpm2: "format, __VA_ARGS__)
|
---|
117 | #else
|
---|
118 | # define TPMLIB_LogError(format, ...)
|
---|
119 | # define TPMLIB_LogTPM12Error(format, ...)
|
---|
120 | # define TPMLIB_LogTPM2Error(format, ...)
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | /* prototypes for TPM2 */
|
---|
124 | TPM_RESULT TPM2_IO_Hash_Start(void);
|
---|
125 | TPM_RESULT TPM2_IO_Hash_Data(const unsigned char *data,
|
---|
126 | uint32_t data_length);
|
---|
127 | TPM_RESULT TPM2_IO_Hash_End(void);
|
---|
128 | TPM_RESULT TPM2_IO_TpmEstablished_Get(TPM_BOOL *tpmEstablished);
|
---|
129 | TPM_RESULT TPM2_IO_TpmEstablished_Reset(void);
|
---|
130 |
|
---|
131 | struct sized_buffer {
|
---|
132 | unsigned char *buffer;
|
---|
133 | uint32_t buflen;
|
---|
134 | #define BUFLEN_EMPTY_BUFFER 0xFFFFFFFF
|
---|
135 | };
|
---|
136 |
|
---|
137 | void ClearCachedState(enum TPMLIB_StateType st);
|
---|
138 | void ClearAllCachedState(void);
|
---|
139 | void SetCachedState(enum TPMLIB_StateType st,
|
---|
140 | unsigned char *buffer, uint32_t buflen);
|
---|
141 | void GetCachedState(enum TPMLIB_StateType st,
|
---|
142 | unsigned char **buffer, uint32_t *buflen,
|
---|
143 | bool *is_empty_buffer);
|
---|
144 | bool HasCachedState(enum TPMLIB_StateType st);
|
---|
145 | TPM_RESULT CopyCachedState(enum TPMLIB_StateType st,
|
---|
146 | unsigned char **buffer, uint32_t *buflen,
|
---|
147 | bool *is_empty_buffer);
|
---|
148 |
|
---|
149 | const char *TPMLIB_StateTypeToName(enum TPMLIB_StateType st);
|
---|
150 | enum TPMLIB_StateType TPMLIB_NameToStateType(const char *name);
|
---|
151 |
|
---|
152 | uint32_t TPM2_GetBufferSize(void);
|
---|
153 | TPM_RESULT TPM2_PersistentAllStore(unsigned char **buf, uint32_t *buflen);
|
---|
154 |
|
---|
155 | #endif /* TPM_LIBRARY_INTERN_H */
|
---|