]> git.proxmox.com Git - libtpms.git/blob - src/tpm_tpm2_tis.c
tpm2: rev162: Add (unused) macros for bignums
[libtpms.git] / src / tpm_tpm2_tis.c
1 /********************************************************************************/
2 /* */
3 /* TPM TIS I/O */
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 <stdint.h>
42
43 #include "tpm2/Tpm.h"
44 #include "tpm2/TpmTypes.h"
45 #include "tpm2/TpmBuildSwitches.h"
46 #include "tpm2/_TPM_Hash_Start_fp.h"
47 #include "tpm2/_TPM_Hash_Data_fp.h"
48 #include "tpm2/_TPM_Hash_End_fp.h"
49 #include "tpm2/TpmTcpProtocol.h"
50 #include "tpm2/Platform_fp.h"
51 #include "tpm2/Simulator_fp.h"
52
53 #define TPM_HAVE_TPM2_DECLARATIONS
54 #include "tpm_library_intern.h"
55 #include "tpm_error.h"
56
57 TPM_RESULT TPM2_IO_TpmEstablished_Get(TPM_BOOL *tpmEstablished)
58 {
59 *tpmEstablished = _rpc__Signal_GetTPMEstablished();
60
61 return TPM_SUCCESS;
62 }
63
64 TPM_RESULT TPM2_IO_TpmEstablished_Reset(void)
65 {
66 TPM_RESULT ret = TPM_SUCCESS;
67 struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks();
68 TPM_MODIFIER_INDICATOR locality = 0;
69 uint32_t tpm_number = 0;
70
71 if (cbs->tpm_io_getlocality) {
72 cbs->tpm_io_getlocality(&locality, tpm_number);
73 }
74
75 _plat__LocalitySet(locality);
76
77 if (locality == 3 || locality == 4) {
78 _rpc__Signal_ResetTPMEstablished();
79 } else {
80 ret = TPM_BAD_LOCALITY;
81 }
82
83 return ret;
84 }
85
86 TPM_RESULT TPM2_IO_Hash_Start(void)
87 {
88 _TPM_Hash_Start();
89
90 _rpc__Signal_SetTPMEstablished();
91
92 return TPM_SUCCESS;
93 }
94
95 TPM_RESULT TPM2_IO_Hash_Data(const unsigned char *data,
96 uint32_t data_length)
97 {
98 _TPM_Hash_Data(data_length, (unsigned char *)data);
99
100 return TPM_SUCCESS;
101 }
102
103 TPM_RESULT TPM2_IO_Hash_End(void)
104 {
105 _TPM_Hash_End();
106
107 return TPM_SUCCESS;
108 }