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 8 * (C) Christian Kummer 2007 9 * 10 */ 11 12 13#include <stdlib.h> 14#include <stdio.h> 15#include <string.h> 16#include <inttypes.h> 17 18#include "trousers/tss.h" 19#include "trousers_types.h" 20#include "tcs_tsp.h" 21#include "tcsps.h" 22#include "tcs_utils.h" 23#include "tcs_int_literals.h" 24#include "capabilities.h" 25#include "tcslog.h" 26#include "req_mgr.h" 27#include "tcsd_wrap.h" 28#include "tcsd.h" 29 30 31TSS_RESULT 32TCSP_Extend_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 33 TCPA_PCRINDEX pcrNum, /* in */ 34 TCPA_DIGEST inDigest, /* in */ 35 TCPA_PCRVALUE * outDigest) /* out */ 36{ 37 UINT64 offset = 0; 38 TSS_RESULT result; 39 UINT32 paramSize; 40 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 41 42 LogDebug("Entering Extend"); 43 if ((result = ctx_verify_context(hContext))) 44 return result; 45 46 /* PCRs are numbered 0 - (NUM_PCRS - 1), thus the >= */ 47 if (pcrNum >= tpm_metrics.num_pcrs) 48 return TCSERR(TSS_E_BAD_PARAMETER); 49 50 if (tcsd_options.kernel_pcrs & (1 << pcrNum)) { 51 LogInfo("PCR %d is configured to be kernel controlled. Extend request denied.", 52 pcrNum); 53 return TCSERR(TSS_E_FAIL); 54 } 55 56 if (tcsd_options.firmware_pcrs & (1 << pcrNum)) { 57 LogInfo("PCR %d is configured to be firmware controlled. Extend request denied.", 58 pcrNum); 59 return TCSERR(TSS_E_FAIL); 60 } 61 62 if ((result = tpm_rqu_build(TPM_ORD_Extend, &offset, txBlob, pcrNum, TPM_DIGEST_SIZE, 63 inDigest.digest, NULL, NULL))) 64 return result; 65 66 if ((result = req_mgr_submit_req(txBlob))) 67 return result; 68 69 result = UnloadBlob_Header(txBlob, ¶mSize); 70 if (!result) { 71 result = tpm_rsp_parse(TPM_ORD_Extend, txBlob, paramSize, NULL, outDigest->digest); 72 } 73 LogResult("Extend", result); 74 return result; 75} 76 77TSS_RESULT 78TCSP_PcrRead_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 79 TCPA_PCRINDEX pcrNum, /* in */ 80 TCPA_PCRVALUE * outDigest) /* out */ 81{ 82 UINT64 offset = 0; 83 TSS_RESULT result; 84 UINT32 paramSize; 85 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 86 87 LogDebug("Entering PCRRead"); 88 89 if ((result = ctx_verify_context(hContext))) 90 return result; 91 92 /* PCRs are numbered 0 - (NUM_PCRS - 1), thus the >= */ 93 if (pcrNum >= tpm_metrics.num_pcrs) 94 return TCSERR(TSS_E_BAD_PARAMETER); 95 96 if ((result = tpm_rqu_build(TPM_ORD_PcrRead, &offset, txBlob, pcrNum, NULL))) 97 return result; 98 99 if ((result = req_mgr_submit_req(txBlob))) 100 return result; 101 102 result = UnloadBlob_Header(txBlob, ¶mSize); 103 if (!result) { 104 result = tpm_rsp_parse(TPM_ORD_PcrRead, txBlob, paramSize, NULL, outDigest->digest); 105 } 106 LogResult("PCR Read", result); 107 return result; 108} 109 110TSS_RESULT 111TCSP_PcrReset_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 112 UINT32 pcrDataSizeIn, /* in */ 113 BYTE * pcrDataIn) /* in */ 114{ 115 UINT64 offset = 0; 116 TSS_RESULT result; 117 UINT32 paramSize; 118 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 119 120 LogDebug("Entering PCRReset"); 121 122 if ((result = ctx_verify_context(hContext))) 123 return result; 124 125 if ((result = tpm_rqu_build(TPM_ORD_PCR_Reset, &offset, txBlob, pcrDataSizeIn, pcrDataIn))) 126 return result; 127 128 if ((result = req_mgr_submit_req(txBlob))) 129 return result; 130 131 result = UnloadBlob_Header(txBlob, ¶mSize); 132 LogResult("PCR Reset", result); 133 return result; 134} 135