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 * 9 */ 10 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <string.h> 15 #include <inttypes.h> 16 17 #include "trousers/tss.h" 18 #include "trousers_types.h" 19 #include "tcs_tsp.h" 20 #include "tcsps.h" 21 #include "tcs_utils.h" 22 #include "tcs_int_literals.h" 23 #include "capabilities.h" 24 #include "tcslog.h" 25 #include "req_mgr.h" 26 #include "tcsd_wrap.h" 27 #include "tcsd.h" 28 29 30 TSS_RESULT 31 TCSP_SelfTestFull_Internal(TCS_CONTEXT_HANDLE hContext) /* in */ 32 { 33 UINT64 offset = 0; 34 UINT32 paramSize; 35 TSS_RESULT result; 36 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 37 38 LogDebug("Entering Self Test Full"); 39 if ((result = ctx_verify_context(hContext))) 40 return result; 41 42 if ((result = tpm_rqu_build(TPM_ORD_SelfTestFull, &offset, txBlob, NULL))) 43 return result; 44 45 if ((result = req_mgr_submit_req(txBlob))) 46 return result; 47 48 result = UnloadBlob_Header(txBlob, ¶mSize); 49 LogResult("Self Test Full", result); 50 return result; 51 } 52 53 TSS_RESULT 54 TCSP_CertifySelfTest_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 55 TCS_KEY_HANDLE keyHandle, /* in */ 56 TCPA_NONCE antiReplay, /* in */ 57 TPM_AUTH * privAuth, /* in, out */ 58 UINT32 * sigSize, /* out */ 59 BYTE ** sig) /* out */ 60 { 61 UINT64 offset = 0; 62 UINT32 paramSize; 63 TSS_RESULT result; 64 TCPA_KEY_HANDLE keySlot; 65 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 66 67 LogDebug("Entering Certify Self Test"); 68 69 if ((result = ctx_verify_context(hContext))) 70 goto done; 71 72 if (privAuth != NULL) { 73 LogDebug("Auth Used"); 74 if ((result = auth_mgr_check(hContext, &privAuth->AuthHandle))) 75 goto done; 76 } else { 77 LogDebug("No Auth"); 78 } 79 80 if ((result = ensureKeyIsLoaded(hContext, keyHandle, &keySlot))) 81 goto done; 82 83 if ((result = tpm_rqu_build(TPM_ORD_CertifySelfTest, &offset, txBlob, keySlot, 84 TPM_NONCE_SIZE, antiReplay.nonce, privAuth, NULL))) 85 return result; 86 87 if ((result = req_mgr_submit_req(txBlob))) 88 goto done; 89 90 result = UnloadBlob_Header(txBlob, ¶mSize); 91 if (!result) { 92 result = tpm_rsp_parse(TPM_ORD_CertifySelfTest, txBlob, paramSize, sigSize, sig, 93 privAuth, NULL); 94 } 95 LogResult("Certify Self Test", result); 96 done: 97 auth_mgr_release_auth(privAuth, NULL, hContext); 98 return result; 99 } 100 101 TSS_RESULT 102 TCSP_GetTestResult_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 103 UINT32 * outDataSize, /* out */ 104 BYTE ** outData) /* out */ 105 { 106 TSS_RESULT result; 107 UINT32 paramSize; 108 UINT64 offset = 0; 109 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 110 111 LogDebug("Entering Get Test Result"); 112 if ((result = ctx_verify_context(hContext))) 113 return result; 114 115 if ((result = tpm_rqu_build(TPM_ORD_GetTestResult, &offset, txBlob, NULL))) 116 return result; 117 118 if ((result = req_mgr_submit_req(txBlob))) 119 return result; 120 121 result = UnloadBlob_Header(txBlob, ¶mSize); 122 if (!result) { 123 result = tpm_rsp_parse(TPM_ORD_GetTestResult, txBlob, paramSize, outDataSize, 124 outData, NULL, NULL); 125 } 126 LogResult("Get Test Result", result); 127 return result; 128 } 129 130