3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004-2007
16
#include "trousers/tss.h"
17
#include "trousers/trousers.h"
18
#include "trousers_types.h"
19
#include "spi_utils.h"
20
#include "capabilities.h"
26
Transport_LoadKeyByBlob(TSS_HCONTEXT hContext,
27
TPM_COMMAND_CODE ordinal,
32
TCS_KEY_HANDLE* phKey,
33
TPM_KEY_HANDLE* phSlot)
36
UINT32 handleListSize, decLen;
37
TCS_KEY_HANDLE hTCSParentKey;
38
TCS_HANDLE *handleList;
40
TPM_DIGEST pubKeyHash;
41
Trspi_HashCtx hashCtx;
44
if ((result = obj_context_transport_init(hContext)) == TSS_TSPATTRIB_DISABLE_TRANSPORT) {
45
if ((result = obj_rsakey_get_tcs_handle(hParentKey, &hTCSParentKey)))
48
return TCSP_LoadKeyByBlob(hContext, hTCSParentKey, ulBlobLength, rgbBlobData, pAuth,
50
} else if (result != TSS_TSPATTRIB_ENABLE_TRANSPORT)
53
LogDebugFn("Executing in a transport session");
55
if ((result = obj_rsakey_get_transport_attribs(hParentKey, &hTCSParentKey, &pubKeyHash)))
58
result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
59
result |= Trspi_Hash_DIGEST(&hashCtx, pubKeyHash.digest);
60
if ((result |= Trspi_HashFinal(&hashCtx, pubKeyHash.digest)))
63
/* Call ExecuteTransport */
65
if ((handleList = malloc(sizeof(TCS_HANDLE))) == NULL) {
66
LogError("malloc of %zd bytes failed", sizeof(TCS_HANDLE));
67
return TSPERR(TSS_E_OUTOFMEMORY);
70
*handleList = hTCSParentKey;
72
if ((result = obj_context_transport_execute(hContext, ordinal, ulBlobLength,
73
rgbBlobData, &pubKeyHash, &handleListSize,
74
&handleList, pAuth, NULL, &decLen, &dec))) {
79
if (handleListSize == 1)
80
*phKey = *(TCS_KEY_HANDLE *)handleList;
82
result = TSPERR(TSS_E_INTERNAL_ERROR);