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 30TSS_RESULT 31TCSP_Sign_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 32 TCS_KEY_HANDLE keyHandle, /* in */ 33 UINT32 areaToSignSize, /* in */ 34 BYTE * areaToSign, /* in */ 35 TPM_AUTH * privAuth, /* in, out */ 36 UINT32 * sigSize, /* out */ 37 BYTE ** sig /* out */ 38 ) 39{ 40 UINT64 offset = 0; 41 UINT32 paramSize; 42 TSS_RESULT result; 43 TCPA_KEY_HANDLE keySlot; 44 BYTE txBlob[TSS_TPM_TXBLOB_SIZE]; 45 46 LogDebug("Entering Sign"); 47 if ((result = ctx_verify_context(hContext))) 48 return result; 49 50 if (privAuth != NULL) { 51 LogDebug("Auth Used"); 52 if ((result = auth_mgr_check(hContext, &privAuth->AuthHandle))) 53 goto done; 54 } else { 55 LogDebug("No Auth"); 56 } 57 58 if ((result = ensureKeyIsLoaded(hContext, keyHandle, &keySlot))) 59 goto done; 60 61 if ((result = tpm_rqu_build(TPM_ORD_Sign, &offset, txBlob, keySlot, areaToSignSize, 62 areaToSign, privAuth))) 63 return result; 64 65 if ((result = req_mgr_submit_req(txBlob))) 66 goto done; 67 68 result = UnloadBlob_Header(txBlob, ¶mSize); 69 if (!result) { 70 result = tpm_rsp_parse(TPM_ORD_Sign, txBlob, paramSize, sigSize, sig, privAuth, 71 NULL); 72 } 73 LogResult("sign", result); 74done: 75 auth_mgr_release_auth(privAuth, NULL, hContext); 76 return result; 77} 78 79