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. 2007
8  *
9  */
10 
11 
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include "trousers/tss.h"
16 #include "trousers/trousers.h"
17 #include "trousers_types.h"
18 #include "spi_utils.h"
19 #include "capabilities.h"
20 #include "tsplog.h"
21 #include "obj.h"
22 
23 
24 #ifdef TSS_BUILD_TRANSPORT
25 TSS_RESULT
Transport_DirWriteAuth(TSS_HCONTEXT tspContext,TCPA_DIRINDEX dirIndex,TCPA_DIRVALUE * newContents,TPM_AUTH * ownerAuth)26 Transport_DirWriteAuth(TSS_HCONTEXT tspContext,    /* in */
27 		       TCPA_DIRINDEX dirIndex,     /* in */
28 		       TCPA_DIRVALUE *newContents,  /* in */
29 		       TPM_AUTH * ownerAuth)       /* in, out */
30 {
31 	TSS_RESULT result;
32 	UINT32 handlesLen = 0;
33 	UINT64 offset;
34 	BYTE data[sizeof(TCPA_DIRINDEX) + sizeof(TCPA_DIRVALUE)];
35 
36 
37 	if ((result = obj_context_transport_init(tspContext)))
38 		return result;
39 
40 	LogDebugFn("Executing in a transport session");
41 
42 	offset = 0;
43 	Trspi_LoadBlob_UINT32(&offset, dirIndex, data);
44 	Trspi_LoadBlob_DIGEST(&offset, data, (TPM_DIGEST *)newContents);
45 
46 	result = obj_context_transport_execute(tspContext, TPM_ORD_DirWriteAuth, sizeof(data), data,
47 					       NULL, &handlesLen, NULL, ownerAuth, NULL, NULL,
48 					       NULL);
49 
50 	return result;
51 }
52 
53 TSS_RESULT
Transport_DirRead(TSS_HCONTEXT tspContext,TCPA_DIRINDEX dirIndex,TCPA_DIRVALUE * dirValue)54 Transport_DirRead(TSS_HCONTEXT tspContext, /* in */
55 		  TCPA_DIRINDEX dirIndex,  /* in */
56 		  TCPA_DIRVALUE * dirValue)        /* out */
57 {
58 	TSS_RESULT result;
59 	UINT32 handlesLen = 0, decLen;
60 	UINT64 offset;
61 	BYTE data[sizeof(TCPA_DIRINDEX)], *dec;
62 
63 
64 	if ((result = obj_context_transport_init(tspContext)))
65 		return result;
66 
67 	LogDebugFn("Executing in a transport session");
68 
69 	offset = 0;
70 	Trspi_LoadBlob_UINT32(&offset, dirIndex, data);
71 
72 	if ((result = obj_context_transport_execute(tspContext, TPM_ORD_DirRead, sizeof(data), data,
73 						    NULL, &handlesLen, NULL, NULL, NULL, &decLen,
74 						    &dec)))
75 		return result;
76 
77 	offset = 0;
78 	Trspi_UnloadBlob_DIGEST(&offset, dec, dirValue);
79 
80 	return result;
81 }
82 #endif
83 
84