1 2 /* 3 * Licensed Materials - Property of IBM 4 * 5 * trousers - An open source TCG Software Stack 6 * 7 * (C) Copyright International Business Machines Corp. 2004-2007 8 * 9 */ 10 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <string.h> 15 #include <time.h> 16 #include <errno.h> 17 18 #include "trousers/tss.h" 19 #include "trousers/trousers.h" 20 #include "trousers_types.h" 21 #include "spi_utils.h" 22 #include "capabilities.h" 23 #include "tsplog.h" 24 #include "obj.h" 25 26 27 #ifdef TSS_BUILD_TRANSPORT 28 TSS_RESULT 29 Transport_Extend(TSS_HCONTEXT tspContext, /* in */ 30 TCPA_PCRINDEX pcrNum, /* in */ 31 TCPA_DIGEST inDigest, /* in */ 32 TCPA_PCRVALUE * outDigest) /* out */ 33 { 34 TSS_RESULT result; 35 UINT64 offset; 36 TCS_HANDLE handlesLen = 0; 37 UINT32 decLen; 38 BYTE data[sizeof(TCPA_PCRINDEX) + sizeof(TCPA_DIGEST)], *dec; 39 40 if ((result = obj_context_transport_init(tspContext))) 41 return result; 42 43 LogDebugFn("Executing in a transport session"); 44 45 offset = 0; 46 Trspi_LoadBlob_UINT32(&offset, pcrNum, data); 47 Trspi_LoadBlob(&offset, TPM_SHA1_160_HASH_LEN, data, inDigest.digest); 48 49 if ((result = obj_context_transport_execute(tspContext, TPM_ORD_Extend, sizeof(data), data, 50 NULL, &handlesLen, NULL, NULL, NULL, &decLen, 51 &dec))) 52 return result; 53 54 offset = 0; 55 Trspi_UnloadBlob(&offset, decLen, dec, outDigest->digest); 56 57 free(dec); 58 59 return TSS_SUCCESS; 60 } 61 62 TSS_RESULT 63 Transport_PcrRead(TSS_HCONTEXT tspContext, /* in */ 64 TCPA_PCRINDEX pcrNum, /* in */ 65 TCPA_PCRVALUE * outDigest) /* out */ 66 { 67 TSS_RESULT result; 68 UINT64 offset; 69 TCS_HANDLE handlesLen = 0; 70 UINT32 decLen; 71 BYTE data[sizeof(TCPA_PCRINDEX)], *dec; 72 73 if ((result = obj_context_transport_init(tspContext))) 74 return result; 75 76 LogDebugFn("Executing in a transport session"); 77 78 offset = 0; 79 Trspi_LoadBlob_UINT32(&offset, pcrNum, data); 80 81 if ((result = obj_context_transport_execute(tspContext, TPM_ORD_PcrRead, sizeof(data), 82 data, NULL, &handlesLen, NULL, NULL, NULL, 83 &decLen, &dec))) 84 return result; 85 86 offset = 0; 87 Trspi_UnloadBlob(&offset, decLen, dec, outDigest->digest); 88 89 free(dec); 90 91 return TSS_SUCCESS; 92 } 93 94 95 TSS_RESULT 96 Transport_PcrReset(TSS_HCONTEXT tspContext, /* in */ 97 UINT32 pcrDataSizeIn, /* in */ 98 BYTE * pcrDataIn) /* in */ 99 { 100 TSS_RESULT result; 101 TCS_HANDLE handlesLen = 0; 102 103 if ((result = obj_context_transport_init(tspContext))) 104 return result; 105 106 LogDebugFn("Executing in a transport session"); 107 108 return obj_context_transport_execute(tspContext, TPM_ORD_PCR_Reset, pcrDataSizeIn, 109 pcrDataIn, NULL, &handlesLen, NULL, NULL, NULL, NULL, 110 NULL); 111 } 112 #endif 113