1 /********************************************************************************/
2 /*										*/
3 /*			TSS and Application Utilities				*/
4 /*			     Written by Ken Goldman				*/
5 /*		       IBM Thomas J. Watson Research Center			*/
6 /*	      $Id: tssutils.h 1324 2018-08-31 16:36:12Z kgoldman $		*/
7 /*										*/
8 /* (c) Copyright IBM Corporation 2015, 2018.					*/
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 
40 /* This is a semi-public header. The API is subject to change.
41 
42    It is useful rapid application development, and as sample code.  It is risky for production code.
43 
44 */
45 
46 #ifndef TSSUTILS_H
47 #define TSSUTILS_H
48 
49 #include <stdio.h>
50 
51 #include <ibmtss/TPM_Types.h>
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57     typedef TPM_RC (*UnmarshalFunction_t)(void *target, uint8_t **buffer, uint32_t *size);
58     typedef TPM_RC (*UnmarshalFunctionFlag_t)(void *target, uint8_t **buffer, uint32_t *size, BOOL allowNull);
59     typedef TPM_RC (*MarshalFunction_t)(void *source, uint16_t *written, uint8_t **buffer, uint32_t *size);
60 
61     LIB_EXPORT
62     TPM_RC TSS_Malloc(unsigned char **buffer, uint32_t size);
63     LIB_EXPORT
64     TPM_RC TSS_Realloc(unsigned char **buffer, uint32_t size);
65 
66     LIB_EXPORT
67     TPM_RC TSS_Structure_Marshal(uint8_t		**buffer,
68 				 uint16_t		*written,
69 				 void 		*structure,
70 				 MarshalFunction_t 	marshalFunction);
71 
72     LIB_EXPORT
73     TPM_RC TSS_TPM2B_Copy(TPM2B *target, TPM2B *source, uint16_t targetSize);
74 
75     LIB_EXPORT
76     TPM_RC TSS_TPM2B_Append(TPM2B *target, TPM2B *source, uint16_t targetSize);
77 
78     LIB_EXPORT
79     TPM_RC TSS_TPM2B_Create(TPM2B *target, uint8_t *buffer, uint16_t size, uint16_t targetSize);
80 
81     LIB_EXPORT
82     TPM_RC TSS_TPM2B_CreateUint32(TPM2B *target, uint32_t source, uint16_t targetSize);
83 
84     LIB_EXPORT
85     TPM_RC TSS_TPM2B_StringCopy(TPM2B *target, const char *source, uint16_t targetSize);
86 
87     LIB_EXPORT
88     BOOL TSS_TPM2B_Compare(TPM2B *expect, TPM2B *actual);
89 
90     LIB_EXPORT
91     uint16_t TSS_GetDigestSize(TPM_ALG_ID hashAlg);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #ifndef TPM_TSS_NOFILE
98 #include <ibmtss/tssfile.h>
99 #endif
100 
101 #endif
102