1*723e4046Schristos 
2*723e4046Schristos /*
3*723e4046Schristos  * Licensed Materials - Property of IBM
4*723e4046Schristos  *
5*723e4046Schristos  * trousers - An open source TCG Software Stack
6*723e4046Schristos  *
7*723e4046Schristos  * (C) Copyright International Business Machines Corp. 2007
8*723e4046Schristos  *
9*723e4046Schristos  */
10*723e4046Schristos 
11*723e4046Schristos 
12*723e4046Schristos #include <stdlib.h>
13*723e4046Schristos #include <string.h>
14*723e4046Schristos 
15*723e4046Schristos #include "trousers/tss.h"
16*723e4046Schristos #include "trousers/trousers.h"
17*723e4046Schristos #include "trousers_types.h"
18*723e4046Schristos #include "spi_utils.h"
19*723e4046Schristos #include "capabilities.h"
20*723e4046Schristos #include "tsplog.h"
21*723e4046Schristos #include "obj.h"
22*723e4046Schristos 
23*723e4046Schristos 
24*723e4046Schristos #ifdef TSS_BUILD_TRANSPORT
25*723e4046Schristos TSS_RESULT
Transport_UnBind(TSS_HCONTEXT tspContext,TCS_KEY_HANDLE keyHandle,UINT32 inDataSize,BYTE * inData,TPM_AUTH * privAuth,UINT32 * outDataSize,BYTE ** outData)26*723e4046Schristos Transport_UnBind(TSS_HCONTEXT tspContext,	/* in */
27*723e4046Schristos 		 TCS_KEY_HANDLE keyHandle,	/* in */
28*723e4046Schristos 		 UINT32 inDataSize,	/* in */
29*723e4046Schristos 		 BYTE * inData,	/* in */
30*723e4046Schristos 		 TPM_AUTH * privAuth,	/* in, out */
31*723e4046Schristos 		 UINT32 * outDataSize,	/* out */
32*723e4046Schristos 		 BYTE ** outData)	/* out */
33*723e4046Schristos {
34*723e4046Schristos 	TSS_RESULT result;
35*723e4046Schristos 	UINT32 handlesLen, dataLen, decLen;
36*723e4046Schristos 	TCS_HANDLE *handles, handle;
37*723e4046Schristos 	TPM_DIGEST pubKeyHash;
38*723e4046Schristos 	Trspi_HashCtx hashCtx;
39*723e4046Schristos 	BYTE *dec, *data;
40*723e4046Schristos 	UINT64 offset;
41*723e4046Schristos 
42*723e4046Schristos 	if ((result = obj_context_transport_init(tspContext)))
43*723e4046Schristos 		return result;
44*723e4046Schristos 
45*723e4046Schristos 	LogDebugFn("Executing in a transport session");
46*723e4046Schristos 
47*723e4046Schristos 	if ((result = obj_tcskey_get_pubkeyhash(keyHandle, pubKeyHash.digest)))
48*723e4046Schristos 		return result;
49*723e4046Schristos 
50*723e4046Schristos 	result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
51*723e4046Schristos 	result |= Trspi_Hash_DIGEST(&hashCtx, pubKeyHash.digest);
52*723e4046Schristos 	if ((result |= Trspi_HashFinal(&hashCtx, pubKeyHash.digest)))
53*723e4046Schristos 		return result;
54*723e4046Schristos 
55*723e4046Schristos 	handlesLen = 1;
56*723e4046Schristos 	handle = keyHandle;
57*723e4046Schristos 	handles = &handle;
58*723e4046Schristos 
59*723e4046Schristos 	dataLen = sizeof(UINT32) + inDataSize;
60*723e4046Schristos 	if ((data = malloc(dataLen)) == NULL) {
61*723e4046Schristos 		LogError("malloc of %u bytes failed", dataLen);
62*723e4046Schristos 		return TSPERR(TSS_E_OUTOFMEMORY);
63*723e4046Schristos 	}
64*723e4046Schristos 
65*723e4046Schristos 	offset = 0;
66*723e4046Schristos 	Trspi_LoadBlob_UINT32(&offset, inDataSize, data);
67*723e4046Schristos 	Trspi_LoadBlob(&offset, inDataSize, data, inData);
68*723e4046Schristos 
69*723e4046Schristos 	if ((result = obj_context_transport_execute(tspContext, TPM_ORD_UnBind, dataLen, data,
70*723e4046Schristos 						    &pubKeyHash, &handlesLen, &handles,
71*723e4046Schristos 						    privAuth, NULL, &decLen, &dec))) {
72*723e4046Schristos 		free(data);
73*723e4046Schristos 		return result;
74*723e4046Schristos 	}
75*723e4046Schristos 	free(data);
76*723e4046Schristos 
77*723e4046Schristos 	offset = 0;
78*723e4046Schristos 	Trspi_UnloadBlob_UINT32(&offset, outDataSize, dec);
79*723e4046Schristos 
80*723e4046Schristos 	if ((*outData = malloc(*outDataSize)) == NULL) {
81*723e4046Schristos 		free(dec);
82*723e4046Schristos 		LogError("malloc of %u bytes failed", *outDataSize);
83*723e4046Schristos 		return TSPERR(TSS_E_OUTOFMEMORY);
84*723e4046Schristos 	}
85*723e4046Schristos 	Trspi_UnloadBlob(&offset, *outDataSize, dec, *outData);
86*723e4046Schristos 
87*723e4046Schristos 	free(dec);
88*723e4046Schristos 
89*723e4046Schristos 	return TSS_SUCCESS;
90*723e4046Schristos }
91*723e4046Schristos #endif
92*723e4046Schristos 
93