1 /* 2 * The Initial Developer of the Original Code is International 3 * Business Machines Corporation. Portions created by IBM 4 * Corporation are Copyright (C) 2005 International Business 5 * Machines Corporation. All Rights Reserved. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the Common Public License as published by 9 * IBM Corporation; either version 1 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * Common Public License for more details. 16 * 17 * You should have received a copy of the Common Public License 18 * along with this program; if not, a copy can be viewed at 19 * http://www.opensource.org/licenses/cpl1.0.php. 20 */ 21 22 #ifndef __TPM_TSPI_H 23 #define __TPM_TSPI_H 24 25 #include <stdlib.h> 26 #include <trousers/tss.h> 27 #include <trousers/trousers.h> 28 #include <tpm_utils.h> 29 30 extern TSS_UUID SRK_UUID; 31 32 #define NULL_HOBJECT 0 33 #define NULL_HKEY NULL_HOBJECT 34 #define NULL_HPCRS NULL_HOBJECT 35 36 //Display functions 37 const char *displayKeyUsageMap(UINT32 a_uiData); 38 39 const char *displayKeyFlagsMap(UINT32 a_uiFlags); 40 41 const char *displayAuthUsageMap(UINT32 a_uiData); 42 43 const char *displayAlgorithmMap(UINT32 a_uiData); 44 45 const char *displayEncSchemeMap(UINT32 a_uiData); 46 47 const char *displaySigSchemeMap(UINT32 a_uiData); 48 49 TSS_RESULT displayKey(TSS_HKEY a_hKey); 50 51 //Generic query functions 52 BOOL isTpmOwned(TSS_HCONTEXT hContext); 53 54 //TSPI logging functions 55 void tspiDebug(const char *a_szName, TSS_RESULT a_iResult); 56 void tspiError(const char *a_szName, TSS_RESULT a_iResult); 57 void tspiResult(const char *a_szName, TSS_RESULT a_tResult); 58 59 // Map a TSS_BOOL into a BOOL 60 BOOL mapTssBool(TSS_BOOL a_bValue); 61 62 //TSPI generic setup/teardown functions 63 TSS_RESULT contextCreate(TSS_HCONTEXT * a_hContext); 64 TSS_RESULT contextClose(TSS_HCONTEXT a_hContext); 65 TSS_RESULT contextConnect(TSS_HCONTEXT a_hContext); 66 TSS_RESULT contextCreateObject(TSS_HCONTEXT a_hContext, 67 TSS_FLAG a_fType, 68 TSS_FLAG a_fAttrs, TSS_HOBJECT * a_hObject); 69 TSS_RESULT contextCloseObject(TSS_HCONTEXT a_hContext, 70 TSS_HOBJECT a_hObject); 71 TSS_RESULT contextGetTpm(TSS_HCONTEXT a_hContext, TSS_HTPM * a_hTpm); 72 TSS_RESULT policyGet(TSS_HOBJECT a_hObject, TSS_HPOLICY * a_hPolicy); 73 TSS_RESULT policyAssign(TSS_HPOLICY a_hPolicy, TSS_HOBJECT a_hObject); 74 TSS_RESULT policySetSecret(TSS_HPOLICY a_hPolicy, 75 UINT32 a_uiSecretLen, BYTE * a_chSecret); 76 77 TSS_RESULT policyFlushSecret(TSS_HPOLICY a_hPolicy); 78 79 //Common TSPI functions 80 TSS_RESULT tpmGetPubEk(TSS_HTPM a_hTpm, TSS_BOOL a_fOwner, 81 TSS_VALIDATION * a_pValData, TSS_HKEY * a_phEPubKey); 82 TSS_RESULT tpmGetRandom(TSS_HTPM a_hTpm, UINT32 a_length, BYTE ** a_data); 83 TSS_RESULT tpmSetStatus(TSS_HTPM a_hTpm, 84 TSS_FLAG a_fStatus, TSS_BOOL a_bValue); 85 TSS_RESULT tpmGetStatus(TSS_HTPM a_hTpm, 86 TSS_FLAG a_fStatus, TSS_BOOL * a_bValue); 87 TSS_RESULT getCapability(TSS_HTPM a_hTpm, 88 TSS_FLAG a_fCapArea, 89 UINT32 a_uiSubCapLen, 90 BYTE * a_pSubCap, 91 UINT32 * a_uiResultLen, BYTE ** a_pResult); 92 TSS_RESULT getAttribData(TSS_HOBJECT a_hObject, 93 TSS_FLAG a_fAttr, 94 TSS_FLAG a_fSubAttr, 95 UINT32 * a_uiSize, BYTE ** a_pData); 96 TSS_RESULT getAttribUint32(TSS_HOBJECT a_hObject, 97 TSS_FLAG a_fAttr, 98 TSS_FLAG a_fSubAttr, UINT32 * a_uiData); 99 100 //TSPI key functions 101 TSS_RESULT keyLoadKey(TSS_HKEY a_hKey, TSS_HKEY a_hWrapKey); 102 TSS_RESULT keyLoadKeyByUUID(TSS_HCONTEXT a_hContext, 103 TSS_FLAG a_fStoreType, 104 TSS_UUID a_uKeyId, TSS_HKEY * a_hKey); 105 TSS_RESULT keyGetPubKey(TSS_HKEY a_hKey, 106 UINT32 * a_uiKeyLen, BYTE ** a_pKey); 107 TSS_RESULT keyGetKeyByUUID(TSS_HCONTEXT a_hContext, 108 TSS_FLAG a_fStoreType, 109 TSS_UUID a_uKeyId, TSS_HKEY * a_hKey); 110 111 TSS_RESULT keyCreateKey(TSS_HKEY a_hKey, TSS_HKEY a_hWrapKey, 112 TSS_HPCRS a_hPcrs); 113 TSS_RESULT dataSeal(TSS_HENCDATA a_hEncdata, TSS_HKEY a_hKey, 114 UINT32 a_len, BYTE * a_data, 115 TSS_HPCRS a_hPcrs); 116 TSS_RESULT tpmPcrRead(TSS_HTPM a_hTpm, UINT32 a_Idx, 117 UINT32 *a_PcrSize, BYTE **a_PcrValue); 118 TSS_RESULT pcrcompositeSetPcrValue(TSS_HPCRS a_hPcrs, UINT32 a_Idx, 119 UINT32 a_PcrSize, BYTE *a_PcrValue); 120 #ifdef TSS_LIB_IS_12 121 TSS_RESULT unloadVersionInfo(UINT64 *offset, BYTE *blob, TPM_CAP_VERSION_INFO *v); 122 TSS_RESULT pcrcompositeSetPcrLocality(TSS_HPCRS a_hPcrs, UINT32 localityValue); 123 124 TSS_RESULT NVDefineSpace(TSS_HNVSTORE hNVStore, 125 TSS_HPCRS hReadPcrComposite, 126 TSS_HPCRS hWritePcrComposite); 127 128 TSS_RESULT NVReleaseSpace(TSS_HNVSTORE hNVStore); 129 130 TSS_RESULT NVWriteValue(TSS_HNVSTORE hNVStore, UINT32 offset, 131 UINT32 ulDataLength, BYTE *rgbDataToWrite); 132 133 TSS_RESULT NVReadValue(TSS_HNVSTORE hNVStore, UINT32 offset, 134 UINT32 *ulDataLength, BYTE **rgbDataRead); 135 136 TSS_RESULT unloadNVDataPublic(UINT64 *offset, BYTE *blob, UINT32 bloblen, 137 TPM_NV_DATA_PUBLIC *v); 138 #endif 139 140 #endif 141