~ubuntu-branches/ubuntu/precise/trousers/precise-proposed

« back to all changes in this revision

Viewing changes to src/tcsd_api/tcstp.c

  • Committer: Bazaar Package Importer
  • Author(s): William Lima
  • Date: 2007-04-18 16:39:38 UTC
  • Revision ID: james.westby@ubuntu.com-20070418163938-opscl2mvvi76jiec
Tags: upstream-0.2.9.1
ImportĀ upstreamĀ versionĀ 0.2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2006
 
8
 *
 
9
 */
 
10
 
 
11
#include <stdlib.h>
 
12
#include <stdio.h>
 
13
#include <string.h>
 
14
#include <assert.h>
 
15
 
 
16
#include "trousers/tss.h"
 
17
#include "trousers/trousers.h"
 
18
#include "spi_internal_types.h"
 
19
#include "spi_utils.h"
 
20
#include "capabilities.h"
 
21
#include "tsplog.h"
 
22
#include "hosttable.h"
 
23
#include "tcsd_wrap.h"
 
24
#include "obj.h"
 
25
#include "tcsd.h"
 
26
 
 
27
TSS_RESULT send_init(struct host_table_entry *);
 
28
TSS_RESULT sendit(struct host_table_entry *);
 
29
 
 
30
void
 
31
initData(struct tcsd_comm_data *comm, int parm_count)
 
32
{
 
33
        /* min packet size should be the size of the header */
 
34
        memset(&comm->hdr, 0, sizeof(struct tcsd_packet_hdr));
 
35
        comm->hdr.packet_size = sizeof(struct tcsd_packet_hdr);
 
36
        if (parm_count > 0) {
 
37
                comm->hdr.type_offset = sizeof(struct tcsd_packet_hdr);
 
38
                comm->hdr.parm_offset = comm->hdr.type_offset +
 
39
                                        (sizeof(TCSD_PACKET_TYPE) * parm_count);
 
40
                comm->hdr.packet_size = comm->hdr.parm_offset;
 
41
        }
 
42
 
 
43
        memset(comm->buf, 0, comm->buf_size);
 
44
}
 
45
 
 
46
int
 
47
loadData(UINT64 *offset, TCSD_PACKET_TYPE data_type, void *data, int data_size, BYTE *blob)
 
48
{
 
49
        switch (data_type) {
 
50
        case TCSD_PACKET_TYPE_BYTE:
 
51
                Trspi_LoadBlob_BYTE(offset, *((BYTE *) (data)), blob);
 
52
                break;
 
53
        case TCSD_PACKET_TYPE_BOOL:
 
54
                Trspi_LoadBlob_BOOL(offset, *((TSS_BOOL *) (data)), blob);
 
55
                break;
 
56
        case TCSD_PACKET_TYPE_UINT16:
 
57
                Trspi_LoadBlob_UINT16(offset, *((UINT16 *) (data)), blob);
 
58
                break;
 
59
        case TCSD_PACKET_TYPE_UINT32:
 
60
                Trspi_LoadBlob_UINT32(offset, *((UINT32 *) (data)), blob);
 
61
                break;
 
62
        case TCSD_PACKET_TYPE_PBYTE:
 
63
                Trspi_LoadBlob(offset, data_size, blob, (BYTE *)data);
 
64
                break;
 
65
        case TCSD_PACKET_TYPE_NONCE:
 
66
                Trspi_LoadBlob(offset, 20, blob, ((TCPA_NONCE *)data)->nonce);
 
67
                break;
 
68
        case TCSD_PACKET_TYPE_DIGEST:
 
69
                Trspi_LoadBlob(offset, 20, blob, ((TCPA_DIGEST *)data)->digest);
 
70
                break;
 
71
        case TCSD_PACKET_TYPE_AUTH:
 
72
                LoadBlob_AUTH(offset, blob, ((TPM_AUTH *)data));
 
73
                break;
 
74
        case TCSD_PACKET_TYPE_UUID:
 
75
                Trspi_LoadBlob_UUID(offset, blob, *((TSS_UUID *)data));
 
76
                break;
 
77
        case TCSD_PACKET_TYPE_ENCAUTH:
 
78
                Trspi_LoadBlob(offset, 20, blob, ((TCPA_ENCAUTH *)data)->authdata);
 
79
                break;
 
80
        case TCSD_PACKET_TYPE_VERSION:
 
81
                Trspi_LoadBlob_TCPA_VERSION(offset, blob, *((TCPA_VERSION *)data));
 
82
                break;
 
83
        case TCSD_PACKET_TYPE_LOADKEY_INFO:
 
84
                LoadBlob_LOADKEY_INFO(offset, blob, ((TCS_LOADKEY_INFO *)data));
 
85
                break;
 
86
        case TCSD_PACKET_TYPE_PCR_EVENT:
 
87
                Trspi_LoadBlob_PCR_EVENT(offset, blob, ((TSS_PCR_EVENT *)data));
 
88
                break;
 
89
        default:
 
90
                LogError("TCSD packet type unknown! (0x%x)", data_type & 0xff);
 
91
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
92
        }
 
93
 
 
94
        return TSS_SUCCESS;
 
95
}
 
96
 
 
97
int
 
98
setData(TCSD_PACKET_TYPE dataType, int index, void *theData, int theDataSize, struct tcsd_comm_data *comm)
 
99
{
 
100
        UINT64 old_offset, offset;
 
101
        TSS_RESULT result;
 
102
        TCSD_PACKET_TYPE *type;
 
103
 
 
104
        /* Calculate the size of the area needed (use NULL for blob address) */
 
105
        offset = 0;
 
106
        if ((result = loadData(&offset, dataType, theData, theDataSize, NULL)) != TSS_SUCCESS)
 
107
                return result;
 
108
        if (((int)comm->hdr.packet_size + (int)offset) < 0) {
 
109
                LogError("Too much data to be transmitted!");
 
110
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
111
        }
 
112
        if (((int)comm->hdr.packet_size + (int)offset) > comm->buf_size) {
 
113
                /* reallocate the buffer */
 
114
                BYTE *buffer;
 
115
                int buffer_size = comm->hdr.packet_size + offset;
 
116
 
 
117
                LogDebug("Increasing communication buffer to %d bytes.", buffer_size);
 
118
                buffer = realloc(comm->buf, buffer_size);
 
119
                if (buffer == NULL) {
 
120
                        LogError("realloc of %d bytes failed.", buffer_size);
 
121
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
122
                }
 
123
                comm->buf_size = buffer_size;
 
124
                comm->buf = buffer;
 
125
        }
 
126
 
 
127
        offset = old_offset = comm->hdr.parm_offset + comm->hdr.parm_size;
 
128
        if ((result = loadData(&offset, dataType, theData, theDataSize, comm->buf)) != TSS_SUCCESS)
 
129
                return result;
 
130
        type = (TCSD_PACKET_TYPE *)(comm->buf + comm->hdr.type_offset) + index;
 
131
        *type = dataType;
 
132
        comm->hdr.type_size += sizeof(TCSD_PACKET_TYPE);
 
133
        comm->hdr.parm_size += (offset - old_offset);
 
134
 
 
135
        comm->hdr.packet_size = offset;
 
136
        comm->hdr.num_parms++;
 
137
 
 
138
        return TSS_SUCCESS;
 
139
}
 
140
 
 
141
UINT32
 
142
getData(TCSD_PACKET_TYPE dataType, int index, void *theData, int theDataSize, struct tcsd_comm_data *comm)
 
143
{
 
144
        UINT64 old_offset, offset;
 
145
        TCSD_PACKET_TYPE *type = (TCSD_PACKET_TYPE *)(comm->buf + comm->hdr.type_offset) +
 
146
                                 index;
 
147
 
 
148
        if ((UINT32)index >= comm->hdr.num_parms ||
 
149
            dataType != *type) {
 
150
                LogDebug("Data type of TCS packet element %d doesn't match.", index);
 
151
                return TSS_TCP_RPC_BAD_PACKET_TYPE;
 
152
        }
 
153
        old_offset = offset = comm->hdr.parm_offset;
 
154
        switch (dataType) {
 
155
        case TCSD_PACKET_TYPE_BYTE:
 
156
                Trspi_UnloadBlob_BYTE(&offset, (BYTE *)theData, comm->buf);
 
157
                break;
 
158
        case TCSD_PACKET_TYPE_BOOL:
 
159
                Trspi_UnloadBlob_BOOL(&offset, (TSS_BOOL *)theData, comm->buf);
 
160
                break;
 
161
        case TCSD_PACKET_TYPE_UINT16:
 
162
                Trspi_UnloadBlob_UINT16(&offset, (UINT16 *)theData, comm->buf);
 
163
                break;
 
164
        case TCSD_PACKET_TYPE_UINT32:
 
165
                Trspi_UnloadBlob_UINT32(&offset, (UINT32 *)theData, comm->buf);
 
166
                break;
 
167
        case TCSD_PACKET_TYPE_PBYTE:
 
168
                Trspi_UnloadBlob(&offset, theDataSize, comm->buf, (BYTE *)theData);
 
169
                break;
 
170
        case TCSD_PACKET_TYPE_NONCE:
 
171
                Trspi_UnloadBlob(&offset, sizeof(TCPA_NONCE), comm->buf, ((TCPA_NONCE *)theData)->nonce);
 
172
                break;
 
173
        case TCSD_PACKET_TYPE_DIGEST:
 
174
                Trspi_UnloadBlob(&offset, sizeof(TCPA_DIGEST), comm->buf, ((TCPA_DIGEST *)theData)->digest);
 
175
                break;
 
176
        case TCSD_PACKET_TYPE_AUTH:
 
177
                UnloadBlob_AUTH(&offset, comm->buf, ((TPM_AUTH *)theData));
 
178
                break;
 
179
        case TCSD_PACKET_TYPE_UUID:
 
180
                Trspi_UnloadBlob_UUID(&offset, comm->buf, ((TSS_UUID *)theData));
 
181
                break;
 
182
        case TCSD_PACKET_TYPE_ENCAUTH:
 
183
                Trspi_UnloadBlob(&offset, sizeof(TPM_AUTH), comm->buf, ((TCPA_ENCAUTH *)theData)->authdata);
 
184
                break;
 
185
        case TCSD_PACKET_TYPE_VERSION:
 
186
                Trspi_UnloadBlob_TCPA_VERSION(&offset, comm->buf, ((TCPA_VERSION *) theData));
 
187
                break;
 
188
        case TCSD_PACKET_TYPE_KM_KEYINFO:
 
189
                Trspi_UnloadBlob_KM_KEYINFO(&offset, comm->buf, ((TSS_KM_KEYINFO *)theData ) );
 
190
                break;
 
191
        case TCSD_PACKET_TYPE_LOADKEY_INFO:
 
192
                UnloadBlob_LOADKEY_INFO(&offset, comm->buf, ((TCS_LOADKEY_INFO *)theData));
 
193
                break;
 
194
        case TCSD_PACKET_TYPE_PCR_EVENT:
 
195
                Trspi_UnloadBlob_PCR_EVENT(&offset, comm->buf, ((TSS_PCR_EVENT *)theData));
 
196
                break;
 
197
        default:
 
198
                LogError("unknown data type (%d) in TCSD packet!", dataType);
 
199
                return -1;
 
200
        }
 
201
        comm->hdr.parm_offset = offset;
 
202
        comm->hdr.parm_size -= (offset - old_offset);
 
203
 
 
204
        return TSS_SUCCESS;
 
205
}
 
206
 
 
207
#if 0
 
208
void
 
209
printBuffer(BYTE * b, int size)
 
210
{
 
211
        int i;
 
212
        return;
 
213
        for (i = 0; i < size; i++) {
 
214
                if ((i % 16) == 0)
 
215
                        printf("\n");
 
216
                printf("%.2X ", b[i]);
 
217
        }
 
218
        printf("\n");
 
219
        return;
 
220
}
 
221
#endif
 
222
 
 
223
TSS_RESULT
 
224
sendTCSDPacket(struct host_table_entry *hte)
 
225
{
 
226
        TSS_RESULT rc;
 
227
        UINT64 offset = 0;
 
228
 
 
229
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.packet_size, hte->comm.buf);
 
230
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.u.ordinal, hte->comm.buf);
 
231
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.num_parms, hte->comm.buf);
 
232
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.type_size, hte->comm.buf);
 
233
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.type_offset, hte->comm.buf);
 
234
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.parm_size, hte->comm.buf);
 
235
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.parm_offset, hte->comm.buf);
 
236
 
 
237
#if 0
 
238
        /* ---  Send it */
 
239
        printBuffer(hte->comm.buf, hte->comm.hdr.packet_size);
 
240
        LogInfo("Sending Packet with TCSD ordinal 0x%X", hte->comm.hdr.u.ordinal);
 
241
#endif
 
242
        /* if the ordinal is open context, there are some host table entry
 
243
         * manipulations that must be done, so call _init
 
244
         */
 
245
        if (hte->comm.hdr.u.ordinal == TCSD_ORD_OPENCONTEXT) {
 
246
                if ((rc = send_init(hte))) {
 
247
                        LogError("Failed to send packet");
 
248
                        return rc;
 
249
                }
 
250
        } else {
 
251
                if ((rc = sendit(hte))) {
 
252
                        LogError("Failed to send packet");
 
253
                        return rc;
 
254
                }
 
255
        }
 
256
 
 
257
        /* create a platform version of the tcsd header */
 
258
        offset = 0;
 
259
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.packet_size, hte->comm.buf);
 
260
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.u.result, hte->comm.buf);
 
261
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.num_parms, hte->comm.buf);
 
262
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.type_size, hte->comm.buf);
 
263
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.type_offset, hte->comm.buf);
 
264
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.parm_size, hte->comm.buf);
 
265
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.parm_offset, hte->comm.buf);
 
266
 
 
267
        return TSS_SUCCESS;
 
268
}
 
269
 
 
270
/* ---------------------------------------------- */
 
271
/*      TCS Commands                              */
 
272
/* ---------------------------------------------- */
 
273
 
 
274
TSS_RESULT
 
275
TCS_OpenContext_RPC_TP(struct host_table_entry *hte, TCS_CONTEXT_HANDLE *hContext)
 
276
{
 
277
        TSS_RESULT result;
 
278
 
 
279
        initData(&hte->comm, 0);
 
280
 
 
281
        hte->comm.hdr.u.ordinal = TCSD_ORD_OPENCONTEXT;
 
282
        result = sendTCSDPacket(hte);
 
283
 
 
284
        if (result == TSS_SUCCESS)
 
285
                result = hte->comm.hdr.u.result;
 
286
 
 
287
        if (result == TSS_SUCCESS) {
 
288
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, hContext, 0, &hte->comm))
 
289
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
290
 
 
291
                LogDebugFn("Received TCS Context: 0x%x", *hContext);
 
292
        }
 
293
 
 
294
        return result;
 
295
}
 
296
 
 
297
TSS_RESULT
 
298
TCSP_GetRegisteredKeyByPublicInfo_TP(struct host_table_entry *hte,
 
299
                                     TCPA_ALGORITHM_ID algID,   /* in */
 
300
                                     UINT32 ulPublicInfoLength, /* in */
 
301
                                     BYTE * rgbPublicInfo,      /* in */
 
302
                                     UINT32 * keySize,          /* out */
 
303
                                     BYTE ** keyBlob)           /* out */
 
304
{
 
305
        TSS_RESULT result;
 
306
 
 
307
        initData(&hte->comm, 4);
 
308
 
 
309
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETREGISTEREDKEYBYPUBLICINFO;
 
310
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
311
 
 
312
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
313
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
314
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &algID, 0, &hte->comm))
 
315
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
316
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &ulPublicInfoLength, 0, &hte->comm))
 
317
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
318
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbPublicInfo, ulPublicInfoLength, &hte->comm))
 
319
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
320
 
 
321
        result = sendTCSDPacket(hte);
 
322
 
 
323
        if (result == TSS_SUCCESS)
 
324
                result = hte->comm.hdr.u.result;
 
325
 
 
326
        if (result == TSS_SUCCESS) {
 
327
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, keySize, 0, &hte->comm))
 
328
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
329
                *keyBlob = (BYTE *) malloc(*keySize);
 
330
                if (*keyBlob == NULL) {
 
331
                        LogError("malloc of %u bytes failed.", *keySize);
 
332
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
333
                }
 
334
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *keyBlob, *keySize, &hte->comm)) {
 
335
                        free(*keyBlob);
 
336
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
337
                }
 
338
        }
 
339
 
 
340
        return result;
 
341
}
 
342
 
 
343
TSS_RESULT
 
344
TSC_PhysicalPresence_TP(UINT16 physPres)
 
345
{
 
346
        return TSPERR(TSS_E_NOTIMPL);
 
347
}
 
348
 
 
349
TSS_RESULT
 
350
TCS_CloseContext_TP(struct host_table_entry *hte)
 
351
{
 
352
        TSS_RESULT result;
 
353
 
 
354
        initData(&hte->comm, 1);
 
355
 
 
356
        hte->comm.hdr.u.ordinal = TCSD_ORD_CLOSECONTEXT;
 
357
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
358
 
 
359
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
360
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
361
 
 
362
        result = sendTCSDPacket(hte);
 
363
 
 
364
        if (result == TSS_SUCCESS)
 
365
                result = hte->comm.hdr.u.result;
 
366
 
 
367
        return result;
 
368
}
 
369
 
 
370
TSS_RESULT
 
371
TCS_FreeMemory_TP(struct host_table_entry *hte,
 
372
                              BYTE * pMemory    /*  in */
 
373
    ) {
 
374
        free(pMemory);
 
375
 
 
376
        return TSS_SUCCESS;
 
377
}
 
378
 
 
379
TSS_RESULT
 
380
TCS_LogPcrEvent_TP(struct host_table_entry *hte,
 
381
                               TSS_PCR_EVENT Event,     /*  in  */
 
382
                               UINT32 * pNumber /*  out */
 
383
    ) {
 
384
        TSS_RESULT result;
 
385
 
 
386
        initData(&hte->comm, 2);
 
387
 
 
388
        hte->comm.hdr.u.ordinal = TCSD_ORD_LOGPCREVENT;
 
389
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
390
 
 
391
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
392
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
393
 
 
394
        if (setData(TCSD_PACKET_TYPE_PCR_EVENT, 1, &Event, 0, &hte->comm))
 
395
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
396
 
 
397
        result = sendTCSDPacket(hte);
 
398
 
 
399
        if (result == TSS_SUCCESS)
 
400
                result = hte->comm.hdr.u.result;
 
401
 
 
402
        if (result == TSS_SUCCESS) {
 
403
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, pNumber, 0, &hte->comm))
 
404
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
405
        }
 
406
 
 
407
        return result;
 
408
}
 
409
 
 
410
TSS_RESULT
 
411
TCS_GetPcrEvent_TP(struct host_table_entry *hte,
 
412
                               UINT32 PcrIndex, /* in */
 
413
                               UINT32 * pNumber,        /* in, out */
 
414
                               TSS_PCR_EVENT ** ppEvent /* out */
 
415
    ) {
 
416
        TSS_RESULT result;
 
417
        BYTE lengthOnly = (ppEvent == NULL) ? TRUE : FALSE;
 
418
 
 
419
        initData(&hte->comm, 4);
 
420
 
 
421
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETPCREVENT;
 
422
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
423
 
 
424
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
425
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
426
 
 
427
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &PcrIndex, 0, &hte->comm))
 
428
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
429
 
 
430
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, pNumber, 0, &hte->comm))
 
431
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
432
 
 
433
        if (setData(TCSD_PACKET_TYPE_BYTE, 3, &lengthOnly, 0, &hte->comm))
 
434
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
435
 
 
436
        result = sendTCSDPacket(hte);
 
437
 
 
438
        if (result == TSS_SUCCESS)
 
439
                result = hte->comm.hdr.u.result;
 
440
 
 
441
        if (result == TSS_SUCCESS) {
 
442
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, pNumber, 0, &hte->comm))
 
443
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
444
 
 
445
                if (ppEvent) {
 
446
                        *ppEvent = malloc(sizeof(TSS_PCR_EVENT));
 
447
                        if (*ppEvent == NULL) {
 
448
                                LogError("malloc of %zd bytes failed.",
 
449
                                         sizeof(TSS_PCR_EVENT));
 
450
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
451
                        }
 
452
 
 
453
                        if (getData(TCSD_PACKET_TYPE_PCR_EVENT, 1, *ppEvent, 0, &hte->comm)) {
 
454
                                free(*ppEvent);
 
455
                                *ppEvent = NULL;
 
456
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
457
                        }
 
458
                }
 
459
        }
 
460
 
 
461
        return result;
 
462
}
 
463
 
 
464
TSS_RESULT
 
465
TCS_GetPcrEventsByPcr_TP(struct host_table_entry *hte,
 
466
                                     UINT32 PcrIndex,   /* in */
 
467
                                     UINT32 FirstEvent, /* in */
 
468
                                     UINT32 * pEventCount,      /* in, out */
 
469
                                     TSS_PCR_EVENT ** ppEvents  /* out */
 
470
    ) {
 
471
        TSS_RESULT result;
 
472
        UINT32 i, j;
 
473
 
 
474
        initData(&hte->comm, 4);
 
475
 
 
476
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETPCREVENTBYPCR;
 
477
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
478
 
 
479
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
480
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
481
 
 
482
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &PcrIndex, 0, &hte->comm))
 
483
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
484
 
 
485
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &FirstEvent, 0, &hte->comm))
 
486
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
487
 
 
488
        if (setData(TCSD_PACKET_TYPE_UINT32, 3, pEventCount, 0, &hte->comm))
 
489
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
490
 
 
491
        result = sendTCSDPacket(hte);
 
492
 
 
493
        if (result == TSS_SUCCESS)
 
494
                result = hte->comm.hdr.u.result;
 
495
 
 
496
        if (result == TSS_SUCCESS) {
 
497
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, pEventCount, 0, &hte->comm))
 
498
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
499
 
 
500
                if (*pEventCount > 0) {
 
501
                        *ppEvents = calloc_tspi(hte->tspContext,
 
502
                                                sizeof(TSS_PCR_EVENT) * (*pEventCount));
 
503
                        if (*ppEvents == NULL) {
 
504
                                LogError("malloc of %zd bytes failed.",
 
505
                                         sizeof(TSS_PCR_EVENT) * (*pEventCount));
 
506
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
507
                        }
 
508
 
 
509
                        i = 1;
 
510
                        for (j = 0; j < (*pEventCount); j++) {
 
511
                                if (getData(TCSD_PACKET_TYPE_PCR_EVENT, i++, &((*ppEvents)[j]), 0,
 
512
                                            &hte->comm)) {
 
513
                                        free(*ppEvents);
 
514
                                        *ppEvents = NULL;
 
515
                                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
516
                                }
 
517
                        }
 
518
                } else {
 
519
                        *ppEvents = NULL;
 
520
                }
 
521
        }
 
522
 
 
523
        return result;
 
524
}
 
525
 
 
526
TSS_RESULT
 
527
TCS_GetPcrEventLog_TP(struct host_table_entry *hte,
 
528
                                  UINT32 * pEventCount, /* out */
 
529
                                  TSS_PCR_EVENT ** ppEvents     /* out */
 
530
    ) {
 
531
        TSS_RESULT result;
 
532
        int i, j;
 
533
 
 
534
        initData(&hte->comm, 1);
 
535
 
 
536
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETPCREVENTLOG;
 
537
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
538
 
 
539
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
540
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
541
 
 
542
        result = sendTCSDPacket(hte);
 
543
 
 
544
        if (result == TSS_SUCCESS)
 
545
                result = hte->comm.hdr.u.result;
 
546
 
 
547
        if (result == TSS_SUCCESS) {
 
548
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, pEventCount, 0, &hte->comm))
 
549
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
550
 
 
551
                if (*pEventCount > 0) {
 
552
                        *ppEvents = calloc_tspi(hte->tspContext,
 
553
                                                sizeof(TSS_PCR_EVENT) * (*pEventCount));
 
554
                        if (*ppEvents == NULL) {
 
555
                                LogError("malloc of %zd bytes failed.", sizeof(TSS_PCR_EVENT) * (*pEventCount));
 
556
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
557
                        }
 
558
 
 
559
                        i = 1;
 
560
                        for (j = 0; (UINT32)j < (*pEventCount); j++) {
 
561
                                if (getData(TCSD_PACKET_TYPE_PCR_EVENT, i++, &((*ppEvents)[j]), 0, &hte->comm)) {
 
562
                                        free(*ppEvents);
 
563
                                        *ppEvents = NULL;
 
564
                                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
565
                                }
 
566
                        }
 
567
                } else {
 
568
                        *ppEvents = NULL;
 
569
                }
 
570
        }
 
571
 
 
572
        return result;
 
573
}
 
574
 
 
575
TSS_RESULT
 
576
TCS_RegisterKey_TP(struct host_table_entry *hte,
 
577
                               TSS_UUID WrappingKeyUUID,        /* in */
 
578
                               TSS_UUID KeyUUID,        /* in */
 
579
                               UINT32 cKeySize, /* in */
 
580
                               BYTE * rgbKey,   /* in */
 
581
                               UINT32 cVendorData,      /* in */
 
582
                               BYTE * gbVendorData      /* in */
 
583
    ) {
 
584
        TSS_RESULT result;
 
585
 
 
586
        initData(&hte->comm, 7);
 
587
 
 
588
        hte->comm.hdr.u.ordinal = TCSD_ORD_REGISTERKEY;
 
589
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
590
 
 
591
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
592
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
593
        if (setData(TCSD_PACKET_TYPE_UUID, 1, &WrappingKeyUUID, 0, &hte->comm))
 
594
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
595
        if (setData(TCSD_PACKET_TYPE_UUID, 2, &KeyUUID, 0, &hte->comm))
 
596
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
597
        if (setData(TCSD_PACKET_TYPE_UINT32, 3, &cKeySize, 0, &hte->comm))
 
598
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
599
        if (setData(TCSD_PACKET_TYPE_PBYTE, 4, rgbKey, cKeySize, &hte->comm))
 
600
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
601
        if (setData(TCSD_PACKET_TYPE_UINT32, 5, &cVendorData, 0, &hte->comm))
 
602
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
603
        if (setData(TCSD_PACKET_TYPE_PBYTE, 6, gbVendorData, cVendorData, &hte->comm))
 
604
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
605
 
 
606
        result = sendTCSDPacket(hte);
 
607
 
 
608
        if (result == TSS_SUCCESS)
 
609
                result = hte->comm.hdr.u.result;
 
610
 
 
611
        return result;
 
612
}
 
613
 
 
614
TSS_RESULT
 
615
TCSP_UnregisterKey_TP(struct host_table_entry *hte,
 
616
                                  TSS_UUID KeyUUID      /* in */
 
617
    ) {
 
618
        TSS_RESULT result;
 
619
 
 
620
        initData(&hte->comm, 2);
 
621
 
 
622
        hte->comm.hdr.u.ordinal = TCSD_ORD_UNREGISTERKEY;
 
623
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
624
 
 
625
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
626
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
627
        if (setData(TCSD_PACKET_TYPE_UUID, 1, &KeyUUID, 0, &hte->comm))
 
628
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
629
 
 
630
        result = sendTCSDPacket(hte);
 
631
 
 
632
        if (result == TSS_SUCCESS)
 
633
                result = hte->comm.hdr.u.result;
 
634
 
 
635
        return result;
 
636
}
 
637
 
 
638
TSS_RESULT
 
639
TCS_EnumRegisteredKeys_TP(struct host_table_entry *hte,
 
640
                                      TSS_UUID * pKeyUUID,      /* in */
 
641
                                      UINT32 * pcKeyHierarchySize,      /* out */
 
642
                                      TSS_KM_KEYINFO ** ppKeyHierarchy  /* out */
 
643
    ) {
 
644
        TSS_RESULT result;
 
645
        int i, j;
 
646
 
 
647
        initData(&hte->comm, 2);
 
648
 
 
649
        hte->comm.hdr.u.ordinal = TCSD_ORD_ENUMREGISTEREDKEYS;
 
650
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
651
 
 
652
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
653
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
654
 
 
655
        if (pKeyUUID != NULL) {
 
656
                if (setData(TCSD_PACKET_TYPE_UUID, 1, pKeyUUID, 0, &hte->comm))
 
657
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
658
        }
 
659
 
 
660
        result = sendTCSDPacket(hte);
 
661
 
 
662
        if (result == TSS_SUCCESS)
 
663
                result = hte->comm.hdr.u.result;
 
664
 
 
665
        if (result == TSS_SUCCESS) {
 
666
                i = 0;
 
667
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcKeyHierarchySize, 0, &hte->comm))
 
668
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
669
 
 
670
                if (*pcKeyHierarchySize > 0) {
 
671
                        *ppKeyHierarchy = malloc((*pcKeyHierarchySize) * sizeof(TSS_KM_KEYINFO));
 
672
                        if (*ppKeyHierarchy == NULL) {
 
673
                                LogError("malloc of %zu bytes failed.", (*pcKeyHierarchySize) *
 
674
                                         sizeof(TSS_KM_KEYINFO));
 
675
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
676
                        }
 
677
                        for (j = 0; (UINT32)j < *pcKeyHierarchySize; j++) {
 
678
                                if (getData(TCSD_PACKET_TYPE_KM_KEYINFO, i++,
 
679
                                            &((*ppKeyHierarchy)[j]), 0, &hte->comm)) {
 
680
                                        free(*ppKeyHierarchy);
 
681
                                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
682
                                }
 
683
                        }
 
684
                } else {
 
685
                        *ppKeyHierarchy = NULL;
 
686
                }
 
687
        }
 
688
 
 
689
        return result;
 
690
}
 
691
 
 
692
TSS_RESULT
 
693
TCS_GetRegisteredKey_TP(struct host_table_entry *hte,
 
694
                                    TSS_UUID KeyUUID,   /* in */
 
695
                                    TSS_KM_KEYINFO ** ppKeyInfo /* out */
 
696
    ) {
 
697
        return TSPERR(TSS_E_NOTIMPL);
 
698
}
 
699
 
 
700
TSS_RESULT
 
701
TCS_GetRegisteredKeyBlob_TP(struct host_table_entry *hte,
 
702
                                        TSS_UUID KeyUUID,       /* in */
 
703
                                        UINT32 * pcKeySize,     /* out */
 
704
                                        BYTE ** prgbKey /* out */
 
705
    ) {
 
706
        TSS_RESULT result;
 
707
 
 
708
        initData(&hte->comm, 2);
 
709
 
 
710
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETREGISTEREDKEYBLOB;
 
711
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
712
 
 
713
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
714
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
715
        if (setData(TCSD_PACKET_TYPE_UUID, 1, &KeyUUID, 0, &hte->comm))
 
716
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
717
 
 
718
        result = sendTCSDPacket(hte);
 
719
 
 
720
        if (result == TSS_SUCCESS)
 
721
                result = hte->comm.hdr.u.result;
 
722
 
 
723
        if (result == TSS_SUCCESS) {
 
724
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, pcKeySize, 0, &hte->comm))
 
725
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
726
                *prgbKey = malloc(*pcKeySize);
 
727
                if (*prgbKey == NULL) {
 
728
                        LogError("malloc of %u bytes failed.", *pcKeySize);
 
729
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
730
                }
 
731
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *prgbKey, *pcKeySize, &hte->comm)) {
 
732
                        free(*prgbKey);
 
733
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
734
                }
 
735
        }
 
736
 
 
737
        return result;
 
738
}
 
739
 
 
740
TSS_RESULT
 
741
TCSP_LoadKeyByBlob_TP(struct host_table_entry *hte,
 
742
                                  TCS_KEY_HANDLE hUnwrappingKey,        /* in */
 
743
                                  UINT32 cWrappedKeyBlobSize,   /* in */
 
744
                                  BYTE * rgbWrappedKeyBlob,     /* in */
 
745
                                  TPM_AUTH * pAuth,     /* in, out */
 
746
                                  TCS_KEY_HANDLE * phKeyTCSI,   /* out */
 
747
                                  TCS_KEY_HANDLE * phKeyHMAC    /* out */
 
748
    ) {
 
749
        TSS_RESULT result;
 
750
        int i;
 
751
 
 
752
        initData(&hte->comm, 5);
 
753
 
 
754
        hte->comm.hdr.u.ordinal = TCSD_ORD_LOADKEYBYBLOB;
 
755
        LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext);
 
756
 
 
757
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
758
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
759
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hUnwrappingKey, 0, &hte->comm))
 
760
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
761
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &cWrappedKeyBlobSize, 0, &hte->comm))
 
762
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
763
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbWrappedKeyBlob, cWrappedKeyBlobSize, &hte->comm))
 
764
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
765
 
 
766
        if (pAuth != NULL) {
 
767
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, pAuth, 0, &hte->comm))
 
768
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
769
        }
 
770
 
 
771
        result = sendTCSDPacket(hte);
 
772
 
 
773
        if (result == TSS_SUCCESS)
 
774
                result = hte->comm.hdr.u.result;
 
775
 
 
776
        if (result == TSS_SUCCESS) {
 
777
                i = 0;
 
778
                if (pAuth != NULL) {
 
779
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm))
 
780
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
781
                }
 
782
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, phKeyTCSI, 0, &hte->comm))
 
783
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
784
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, phKeyHMAC, 0, &hte->comm))
 
785
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
786
 
 
787
                LogDebugFn("OUT: TCS key handle: 0x%x, TPM key slot: 0x%x", *phKeyTCSI,
 
788
                           *phKeyHMAC);
 
789
        }
 
790
 
 
791
        return result;
 
792
}
 
793
 
 
794
TSS_RESULT
 
795
TCSP_LoadKeyByUUID_TP(struct host_table_entry *hte,
 
796
                                  TSS_UUID KeyUUID,     /* in */
 
797
                                  TCS_LOADKEY_INFO * pLoadKeyInfo,      /* in, out */
 
798
                                  TCS_KEY_HANDLE * phKeyTCSI    /* out */
 
799
    ) {
 
800
        TSS_RESULT result;
 
801
 
 
802
        initData(&hte->comm, 3);
 
803
 
 
804
        hte->comm.hdr.u.ordinal = TCSD_ORD_LOADKEYBYUUID;
 
805
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
806
 
 
807
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
808
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
809
        if (setData(TCSD_PACKET_TYPE_UUID, 1, &KeyUUID, 0, &hte->comm))
 
810
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
811
 
 
812
        if (pLoadKeyInfo != NULL) {
 
813
                if (setData(TCSD_PACKET_TYPE_LOADKEY_INFO, 2, pLoadKeyInfo, 0, &hte->comm))
 
814
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
815
        }
 
816
 
 
817
        result = sendTCSDPacket(hte);
 
818
 
 
819
        if (result == TSS_SUCCESS)
 
820
                result = hte->comm.hdr.u.result;
 
821
 
 
822
        if (result == TSS_SUCCESS) {
 
823
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, phKeyTCSI, 0, &hte->comm))
 
824
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
825
 
 
826
                LogDebugFn("TCS key handle: 0x%x", *phKeyTCSI);
 
827
        } else if (pLoadKeyInfo && (result == TCSERR(TCS_E_KM_LOADFAILED))) {
 
828
                if (getData(TCSD_PACKET_TYPE_LOADKEY_INFO, 0, pLoadKeyInfo, 0, &hte->comm))
 
829
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
830
        }
 
831
 
 
832
        return result;
 
833
}
 
834
 
 
835
TSS_RESULT
 
836
TCSP_EvictKey_TP(struct host_table_entry *hte,
 
837
                             TCS_KEY_HANDLE hKey        /* in */
 
838
    ) {
 
839
        TSS_RESULT result;
 
840
 
 
841
        initData(&hte->comm, 2);
 
842
 
 
843
        hte->comm.hdr.u.ordinal = TCSD_ORD_EVICTKEY;
 
844
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
845
 
 
846
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
847
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
848
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm))
 
849
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
850
 
 
851
        result = sendTCSDPacket(hte);
 
852
 
 
853
        if (result == TSS_SUCCESS)
 
854
                result = hte->comm.hdr.u.result;
 
855
 
 
856
        return result;
 
857
}
 
858
 
 
859
TSS_RESULT
 
860
TCSP_CreateWrapKey_TP(struct host_table_entry *hte,
 
861
                                  TCS_KEY_HANDLE hWrappingKey,  /* in */
 
862
                                  TCPA_ENCAUTH KeyUsageAuth,    /* in */
 
863
                                  TCPA_ENCAUTH KeyMigrationAuth,        /* in */
 
864
                                  UINT32 keyInfoSize,   /* in */
 
865
                                  BYTE * keyInfo,       /* in */
 
866
                                  UINT32 * keyDataSize, /* out */
 
867
                                  BYTE ** keyData,      /* out */
 
868
                                  TPM_AUTH * pAuth      /* in, out */
 
869
    ) {
 
870
        TSS_RESULT result;
 
871
 
 
872
        initData(&hte->comm, 7);
 
873
 
 
874
        hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEWRAPKEY;
 
875
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
876
 
 
877
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
878
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
879
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hWrappingKey, 0, &hte->comm))
 
880
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
881
        if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, &KeyUsageAuth, 0, &hte->comm))
 
882
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
883
        if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, &KeyMigrationAuth, 0, &hte->comm))
 
884
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
885
        if (setData(TCSD_PACKET_TYPE_UINT32, 4, &keyInfoSize, 0, &hte->comm))
 
886
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
887
        if (setData(TCSD_PACKET_TYPE_PBYTE, 5, keyInfo, keyInfoSize, &hte->comm))
 
888
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
889
        if (setData(TCSD_PACKET_TYPE_AUTH, 6, pAuth, 0, &hte->comm))
 
890
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
891
 
 
892
        result = sendTCSDPacket(hte);
 
893
 
 
894
        if (result == TSS_SUCCESS)
 
895
                result = hte->comm.hdr.u.result;
 
896
 
 
897
        if (result == TSS_SUCCESS) {
 
898
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, keyDataSize, 0, &hte->comm))
 
899
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
900
                *keyData = (BYTE *) malloc(*keyDataSize);
 
901
                if (*keyData == NULL) {
 
902
                        LogError("malloc of %u bytes failed.", *keyDataSize);
 
903
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
904
                }
 
905
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *keyData, *keyDataSize, &hte->comm)) {
 
906
                        free(*keyData);
 
907
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
908
                }
 
909
                if (getData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm)) {
 
910
                        free(*keyData);
 
911
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
912
                }
 
913
        }
 
914
 
 
915
        return result;
 
916
}
 
917
 
 
918
TSS_RESULT
 
919
TCSP_GetPubKey_TP(struct host_table_entry *hte,
 
920
                              TCS_KEY_HANDLE hKey,      /* in */
 
921
                              TPM_AUTH * pAuth, /* in, out */
 
922
                              UINT32 * pcPubKeySize,    /* out */
 
923
                              BYTE ** prgbPubKey        /* out */
 
924
    ) {
 
925
        TSS_RESULT result;
 
926
        int i;
 
927
 
 
928
        initData(&hte->comm, 3);
 
929
 
 
930
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETPUBKEY;
 
931
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
932
 
 
933
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
934
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
935
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm))
 
936
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
937
        if (pAuth != NULL) {
 
938
                if (setData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm))
 
939
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
940
        }
 
941
 
 
942
        result = sendTCSDPacket(hte);
 
943
 
 
944
        if (result == TSS_SUCCESS)
 
945
                result = hte->comm.hdr.u.result;
 
946
 
 
947
        i = 0;
 
948
        if (result == TSS_SUCCESS) {
 
949
                if (pAuth != NULL) {
 
950
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm))
 
951
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
952
                }
 
953
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcPubKeySize, 0, &hte->comm))
 
954
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
955
 
 
956
                *prgbPubKey = (BYTE *) calloc_tspi(hte->tspContext, *pcPubKeySize);
 
957
                if (*prgbPubKey == NULL) {
 
958
                        LogError("malloc of %u bytes failed.", *pcPubKeySize);
 
959
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
960
                }
 
961
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbPubKey, *pcPubKeySize, &hte->comm)) {
 
962
                        free_tspi(hte->tspContext, *prgbPubKey);
 
963
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
964
                }
 
965
        }
 
966
 
 
967
        return result;
 
968
}
 
969
 
 
970
TSS_RESULT
 
971
TCSP_MakeIdentity_TP(struct host_table_entry *hte,
 
972
                                 TCPA_ENCAUTH identityAuth,     /* in */
 
973
                                 TCPA_CHOSENID_HASH IDLabel_PrivCAHash, /* in */
 
974
                                 UINT32 idKeyInfoSize,  /* in */
 
975
                                 BYTE * idKeyInfo,      /* in */
 
976
                                 TPM_AUTH * pSrkAuth,   /* in, out */
 
977
                                 TPM_AUTH * pOwnerAuth, /* in, out */
 
978
                                 UINT32 * idKeySize,    /* out */
 
979
                                 BYTE ** idKey, /* out */
 
980
                                 UINT32 * pcIdentityBindingSize,        /* out */
 
981
                                 BYTE ** prgbIdentityBinding,   /* out */
 
982
                                 UINT32 * pcEndorsementCredentialSize,  /* out */
 
983
                                 BYTE ** prgbEndorsementCredential,     /* out */
 
984
                                 UINT32 * pcPlatformCredentialSize,     /* out */
 
985
                                 BYTE ** prgbPlatformCredential,        /* out */
 
986
                                 UINT32 * pcConformanceCredentialSize,  /* out */
 
987
                                 BYTE ** prgbConformanceCredential      /* out */
 
988
    ) {
 
989
        TSS_RESULT result;
 
990
        int i;
 
991
 
 
992
        initData(&hte->comm, 7);
 
993
 
 
994
        hte->comm.hdr.u.ordinal = TCSD_ORD_MAKEIDENTITY;
 
995
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
996
 
 
997
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
998
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
999
        if (setData(TCSD_PACKET_TYPE_ENCAUTH, 1, &identityAuth, 0, &hte->comm))
 
1000
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1001
        if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &IDLabel_PrivCAHash, 0, &hte->comm))
 
1002
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1003
        if (setData(TCSD_PACKET_TYPE_UINT32, 3, &idKeyInfoSize, 0, &hte->comm))
 
1004
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1005
        if (setData(TCSD_PACKET_TYPE_PBYTE, 4, idKeyInfo, idKeyInfoSize, &hte->comm))
 
1006
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1007
        i = 5;
 
1008
        if (pSrkAuth) {
 
1009
                if (setData(TCSD_PACKET_TYPE_AUTH, i++, pSrkAuth, 0, &hte->comm))
 
1010
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1011
        }
 
1012
        if (setData(TCSD_PACKET_TYPE_AUTH, i++, pOwnerAuth, 0, &hte->comm))
 
1013
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1014
 
 
1015
        result = sendTCSDPacket(hte);
 
1016
 
 
1017
        if (result == TSS_SUCCESS)
 
1018
                result = hte->comm.hdr.u.result;
 
1019
 
 
1020
        i = 0;
 
1021
        if (result == TSS_SUCCESS) {
 
1022
                i = 0;
 
1023
                if (pSrkAuth) {
 
1024
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, pSrkAuth, 0, &hte->comm))
 
1025
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1026
                }
 
1027
                if (getData(TCSD_PACKET_TYPE_AUTH, i++, pOwnerAuth, 0, &hte->comm))
 
1028
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1029
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, idKeySize, 0, &hte->comm))
 
1030
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1031
 
 
1032
                *idKey = (BYTE *) malloc(*idKeySize);
 
1033
                if (*idKey == NULL) {
 
1034
                        LogError("malloc of %u bytes failed.", *idKeySize);
 
1035
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1036
                }
 
1037
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *idKey, *idKeySize, &hte->comm)) {
 
1038
                        free(*idKey);
 
1039
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1040
                }
 
1041
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcIdentityBindingSize, 0, &hte->comm)) {
 
1042
                        free(*idKey);
 
1043
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1044
                }
 
1045
 
 
1046
                *prgbIdentityBinding = (BYTE *) malloc(*pcIdentityBindingSize);
 
1047
                if (*prgbIdentityBinding == NULL) {
 
1048
                        LogError("malloc of %u bytes failed.", *pcIdentityBindingSize);
 
1049
                        free(*idKey);
 
1050
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1051
                }
 
1052
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbIdentityBinding, *pcIdentityBindingSize, &hte->comm)) {
 
1053
                        free(*idKey);
 
1054
                        free(*prgbIdentityBinding);
 
1055
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1056
                }
 
1057
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcEndorsementCredentialSize, 0, &hte->comm)) {
 
1058
                        free(*idKey);
 
1059
                        free(*prgbIdentityBinding);
 
1060
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1061
                }
 
1062
 
 
1063
                *prgbEndorsementCredential = (BYTE *) malloc(*pcEndorsementCredentialSize);
 
1064
                if (*prgbEndorsementCredential == NULL) {
 
1065
                        LogError("malloc of %u bytes failed.", *pcEndorsementCredentialSize);
 
1066
                        free(*idKey);
 
1067
                        free(*prgbIdentityBinding);
 
1068
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1069
                }
 
1070
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbEndorsementCredential, *pcEndorsementCredentialSize, &hte->comm)) {
 
1071
                        free(*idKey);
 
1072
                        free(*prgbIdentityBinding);
 
1073
                        free(*prgbEndorsementCredential);
 
1074
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1075
                }
 
1076
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcPlatformCredentialSize, 0, &hte->comm)) {
 
1077
                        free(*idKey);
 
1078
                        free(*prgbIdentityBinding);
 
1079
                        free(*prgbEndorsementCredential);
 
1080
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1081
                }
 
1082
 
 
1083
                *prgbPlatformCredential = (BYTE *) malloc(*pcPlatformCredentialSize);
 
1084
                if (*prgbPlatformCredential == NULL) {
 
1085
                        LogError("malloc of %u bytes failed.", *pcPlatformCredentialSize);
 
1086
                        free(*idKey);
 
1087
                        free(*prgbIdentityBinding);
 
1088
                        free(*prgbEndorsementCredential);
 
1089
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1090
                }
 
1091
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbPlatformCredential, *pcPlatformCredentialSize, &hte->comm)) {
 
1092
                        free(*idKey);
 
1093
                        free(*prgbIdentityBinding);
 
1094
                        free(*prgbEndorsementCredential);
 
1095
                        free(*prgbPlatformCredential);
 
1096
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1097
                }
 
1098
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcConformanceCredentialSize, 0, &hte->comm)) {
 
1099
                        free(*idKey);
 
1100
                        free(*prgbIdentityBinding);
 
1101
                        free(*prgbEndorsementCredential);
 
1102
                        free(*prgbPlatformCredential);
 
1103
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1104
                }
 
1105
 
 
1106
                *prgbConformanceCredential = (BYTE *) malloc(*pcConformanceCredentialSize);
 
1107
                if (*prgbConformanceCredential == NULL) {
 
1108
                        LogError("malloc of %u bytes failed.", *pcConformanceCredentialSize);
 
1109
                        free(*idKey);
 
1110
                        free(*prgbIdentityBinding);
 
1111
                        free(*prgbEndorsementCredential);
 
1112
                        free(*prgbPlatformCredential);
 
1113
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1114
                }
 
1115
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbConformanceCredential, *pcConformanceCredentialSize, &hte->comm)) {
 
1116
                        free(*idKey);
 
1117
                        free(*prgbIdentityBinding);
 
1118
                        free(*prgbEndorsementCredential);
 
1119
                        free(*prgbPlatformCredential);
 
1120
                        free(*prgbConformanceCredential);
 
1121
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1122
                }
 
1123
        }
 
1124
 
 
1125
        return result;
 
1126
}
 
1127
 
 
1128
TSS_RESULT
 
1129
TCSP_SetOwnerInstall_TP(struct host_table_entry *hte,
 
1130
                                    TSS_BOOL state      /* in */
 
1131
    ) {
 
1132
        TSS_RESULT result;
 
1133
 
 
1134
        initData(&hte->comm, 2);
 
1135
 
 
1136
        hte->comm.hdr.u.ordinal = TCSD_ORD_SETOWNERINSTALL;
 
1137
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1138
 
 
1139
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1140
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1141
        if (setData(TCSD_PACKET_TYPE_BOOL, 1, &state, 0, &hte->comm))
 
1142
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1143
 
 
1144
        result = sendTCSDPacket(hte);
 
1145
 
 
1146
        if (result == TSS_SUCCESS)
 
1147
                result = hte->comm.hdr.u.result;
 
1148
 
 
1149
        return result;
 
1150
}
 
1151
 
 
1152
TSS_RESULT
 
1153
TCSP_TakeOwnership_TP(struct host_table_entry *hte,
 
1154
                                  UINT16 protocolID,    /* in */
 
1155
                                  UINT32 encOwnerAuthSize,      /* in */
 
1156
                                  BYTE * encOwnerAuth,  /* in */
 
1157
                                  UINT32 encSrkAuthSize,        /* in */
 
1158
                                  BYTE * encSrkAuth,    /* in */
 
1159
                                  UINT32 srkInfoSize,   /* in */
 
1160
                                  BYTE * srkInfo,       /* in */
 
1161
                                  TPM_AUTH * ownerAuth, /* in, out */
 
1162
                                  UINT32 * srkKeySize, BYTE ** srkKey) {
 
1163
        TSS_RESULT result;
 
1164
 
 
1165
        initData(&hte->comm, 9);
 
1166
 
 
1167
        hte->comm.hdr.u.ordinal = TCSD_ORD_TAKEOWNERSHIP;
 
1168
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1169
 
 
1170
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1171
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1172
        if (setData(TCSD_PACKET_TYPE_UINT16, 1, &protocolID, 0, &hte->comm))
 
1173
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1174
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &encOwnerAuthSize, 0, &hte->comm))
 
1175
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1176
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, encOwnerAuth, encOwnerAuthSize, &hte->comm))
 
1177
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1178
        if (setData(TCSD_PACKET_TYPE_UINT32, 4, &encSrkAuthSize, 0, &hte->comm))
 
1179
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1180
        if (setData(TCSD_PACKET_TYPE_PBYTE, 5, encSrkAuth, encSrkAuthSize, &hte->comm))
 
1181
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1182
        if (setData(TCSD_PACKET_TYPE_UINT32, 6, &srkInfoSize, 0, &hte->comm))
 
1183
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1184
        if (setData(TCSD_PACKET_TYPE_PBYTE, 7, srkInfo, srkInfoSize, &hte->comm))
 
1185
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1186
        if (setData(TCSD_PACKET_TYPE_AUTH, 8, ownerAuth, 0, &hte->comm))
 
1187
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1188
 
 
1189
        result = sendTCSDPacket(hte);
 
1190
 
 
1191
        if (result == TSS_SUCCESS)
 
1192
                result = hte->comm.hdr.u.result;
 
1193
 
 
1194
        if (result == TSS_SUCCESS) {
 
1195
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
1196
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1197
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, srkKeySize, 0, &hte->comm))
 
1198
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1199
 
 
1200
                *srkKey = (BYTE *) malloc(*srkKeySize);
 
1201
                if (*srkKey == NULL) {
 
1202
                        LogError("malloc of %u bytes failed.", *srkKeySize);
 
1203
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1204
                }
 
1205
                if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *srkKey, *srkKeySize, &hte->comm)) {
 
1206
                        free(*srkKey);
 
1207
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1208
                }
 
1209
        }
 
1210
 
 
1211
        return result;
 
1212
}
 
1213
 
 
1214
TSS_RESULT
 
1215
TCSP_OIAP_TP(struct host_table_entry *hte,
 
1216
                         TCS_AUTHHANDLE * authHandle,   /* out */
 
1217
                         TCPA_NONCE * nonce0    /* out */
 
1218
    ) {
 
1219
        TSS_RESULT result;
 
1220
 
 
1221
        initData(&hte->comm, 1);
 
1222
 
 
1223
        hte->comm.hdr.u.ordinal = TCSD_ORD_OIAP;
 
1224
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1225
 
 
1226
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1227
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1228
 
 
1229
        result = sendTCSDPacket(hte);
 
1230
 
 
1231
        if (result == TSS_SUCCESS)
 
1232
                result = hte->comm.hdr.u.result;
 
1233
 
 
1234
        if (result == TSS_SUCCESS) {
 
1235
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, authHandle, 0, &hte->comm))
 
1236
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1237
                if (getData(TCSD_PACKET_TYPE_NONCE, 1, nonce0, 0, &hte->comm))
 
1238
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1239
        }
 
1240
 
 
1241
        return result;
 
1242
}
 
1243
 
 
1244
TSS_RESULT
 
1245
TCSP_OSAP_TP(struct host_table_entry *hte,
 
1246
                         TCPA_ENTITY_TYPE entityType,   /* in */
 
1247
                         UINT32 entityValue,    /* in */
 
1248
                         TCPA_NONCE nonceOddOSAP,       /* in */
 
1249
                         TCS_AUTHHANDLE * authHandle,   /* out */
 
1250
                         TCPA_NONCE * nonceEven,        /* out */
 
1251
                         TCPA_NONCE * nonceEvenOSAP     /* out */
 
1252
    ) {
 
1253
        TSS_RESULT result;
 
1254
 
 
1255
        initData(&hte->comm, 4);
 
1256
 
 
1257
        hte->comm.hdr.u.ordinal = TCSD_ORD_OSAP;
 
1258
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1259
 
 
1260
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1261
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1262
        if (setData(TCSD_PACKET_TYPE_UINT16, 1, &entityType, 0, &hte->comm))
 
1263
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1264
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &entityValue, 0, &hte->comm))
 
1265
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1266
        if (setData(TCSD_PACKET_TYPE_NONCE, 3, &nonceOddOSAP, 0, &hte->comm))
 
1267
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1268
 
 
1269
        result = sendTCSDPacket(hte);
 
1270
 
 
1271
        if (result == TSS_SUCCESS)
 
1272
                result = hte->comm.hdr.u.result;
 
1273
 
 
1274
        if (result == TSS_SUCCESS) {
 
1275
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, authHandle, 0, &hte->comm))
 
1276
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1277
                if (getData(TCSD_PACKET_TYPE_NONCE, 1, nonceEven, 0, &hte->comm))
 
1278
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1279
                if (getData(TCSD_PACKET_TYPE_NONCE, 2, nonceEvenOSAP, 0, &hte->comm))
 
1280
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1281
        }
 
1282
 
 
1283
        return result;
 
1284
}
 
1285
 
 
1286
TSS_RESULT
 
1287
TCSP_ChangeAuth_TP(struct host_table_entry *hte,
 
1288
                               TCS_KEY_HANDLE parentHandle,     /* in */
 
1289
                               TCPA_PROTOCOL_ID protocolID,     /* in */
 
1290
                               TCPA_ENCAUTH newAuth,    /* in */
 
1291
                               TCPA_ENTITY_TYPE entityType,     /* in */
 
1292
                               UINT32 encDataSize,      /* in */
 
1293
                               BYTE * encData,  /* in */
 
1294
                               TPM_AUTH * ownerAuth,    /* in, out */
 
1295
                               TPM_AUTH * entityAuth,   /* in, out */
 
1296
                               UINT32 * outDataSize,    /* out */
 
1297
                               BYTE ** outData  /* out */
 
1298
    ) {
 
1299
        TSS_RESULT result;
 
1300
 
 
1301
        initData(&hte->comm, 9);
 
1302
 
 
1303
        hte->comm.hdr.u.ordinal = TCSD_ORD_CHANGEAUTH;
 
1304
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1305
 
 
1306
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1307
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1308
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm))
 
1309
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1310
        if (setData(TCSD_PACKET_TYPE_UINT16, 2, &protocolID, 0, &hte->comm))
 
1311
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1312
        if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, &newAuth, 0, &hte->comm))
 
1313
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1314
        if (setData(TCSD_PACKET_TYPE_UINT16, 4, &entityType, 0, &hte->comm))
 
1315
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1316
        if (setData(TCSD_PACKET_TYPE_UINT32, 5, &encDataSize, 0, &hte->comm))
 
1317
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1318
        if (setData(TCSD_PACKET_TYPE_PBYTE, 6, encData, encDataSize, &hte->comm))
 
1319
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1320
        if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm))
 
1321
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1322
        if (setData(TCSD_PACKET_TYPE_AUTH, 8, entityAuth, 0, &hte->comm))
 
1323
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1324
 
 
1325
        result = sendTCSDPacket(hte);
 
1326
 
 
1327
        if (result == TSS_SUCCESS)
 
1328
                result = hte->comm.hdr.u.result;
 
1329
 
 
1330
        if (result == TSS_SUCCESS) {
 
1331
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
1332
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1333
                if (getData(TCSD_PACKET_TYPE_AUTH, 1, entityAuth, 0, &hte->comm))
 
1334
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1335
                if (getData(TCSD_PACKET_TYPE_UINT32, 2, outDataSize, 0, &hte->comm))
 
1336
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1337
 
 
1338
                *outData = (BYTE *) malloc(*outDataSize);
 
1339
                if (*outData == NULL) {
 
1340
                        LogError("malloc of %u bytes failed.", *outDataSize);
 
1341
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1342
                }
 
1343
                if (getData(TCSD_PACKET_TYPE_PBYTE, 3, *outData, *outDataSize, &hte->comm)) {
 
1344
                        free(*outData);
 
1345
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1346
                }
 
1347
        }
 
1348
 
 
1349
        return result;
 
1350
}
 
1351
 
 
1352
TSS_RESULT
 
1353
TCSP_ChangeAuthOwner_TP(struct host_table_entry *hte,
 
1354
                                    TCPA_PROTOCOL_ID protocolID,        /* in */
 
1355
                                    TCPA_ENCAUTH newAuth,       /* in */
 
1356
                                    TCPA_ENTITY_TYPE entityType,        /* in */
 
1357
                                    TPM_AUTH * ownerAuth        /* in, out */
 
1358
    ) {
 
1359
        TSS_RESULT result;
 
1360
 
 
1361
        initData(&hte->comm, 5);
 
1362
 
 
1363
        hte->comm.hdr.u.ordinal = TCSD_ORD_CHANGEAUTHOWNER;
 
1364
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1365
 
 
1366
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1367
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1368
        if (setData(TCSD_PACKET_TYPE_UINT16, 1, &protocolID, 0, &hte->comm))
 
1369
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1370
        if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, &newAuth, 0, &hte->comm))
 
1371
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1372
        if (setData(TCSD_PACKET_TYPE_UINT16, 3, &entityType, 0, &hte->comm))
 
1373
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1374
        if (setData(TCSD_PACKET_TYPE_AUTH, 4, ownerAuth, 0, &hte->comm))
 
1375
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1376
 
 
1377
        result = sendTCSDPacket(hte);
 
1378
 
 
1379
        if (result == TSS_SUCCESS)
 
1380
                result = hte->comm.hdr.u.result;
 
1381
 
 
1382
        if (result == TSS_SUCCESS) {
 
1383
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
1384
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1385
        }
 
1386
 
 
1387
        return result;
 
1388
}
 
1389
 
 
1390
TSS_RESULT
 
1391
TCSP_ChangeAuthAsymStart_TP(struct host_table_entry *hte,
 
1392
                                        TCS_KEY_HANDLE idHandle,        /* in */
 
1393
                                        TCPA_NONCE antiReplay,  /* in */
 
1394
                                        UINT32 KeySizeIn,       /* in */
 
1395
                                        BYTE * KeyDataIn,       /* in */
 
1396
                                        TPM_AUTH * pAuth,       /* in, out */
 
1397
                                        UINT32 * KeySizeOut,    /* out */
 
1398
                                        BYTE ** KeyDataOut,     /* out */
 
1399
                                        UINT32 * CertifyInfoSize,       /* out */
 
1400
                                        BYTE ** CertifyInfo,    /* out */
 
1401
                                        UINT32 * sigSize,       /* out */
 
1402
                                        BYTE ** sig,    /* out */
 
1403
                                        TCS_KEY_HANDLE * ephHandle      /* out */
 
1404
    ) {
 
1405
        return TSPERR(TSS_E_NOTIMPL);
 
1406
}
 
1407
 
 
1408
TSS_RESULT
 
1409
TCSP_ChangeAuthAsymFinish_TP(struct host_table_entry *hte,
 
1410
                                         TCS_KEY_HANDLE parentHandle,   /* in */
 
1411
                                         TCS_KEY_HANDLE ephHandle,      /* in */
 
1412
                                         TCPA_ENTITY_TYPE entityType,   /* in */
 
1413
                                         TCPA_HMAC newAuthLink, /* in */
 
1414
                                         UINT32 newAuthSize,    /* in */
 
1415
                                         BYTE * encNewAuth,     /* in */
 
1416
                                         UINT32 encDataSizeIn,  /* in */
 
1417
                                         BYTE * encDataIn,      /* in */
 
1418
                                         TPM_AUTH * ownerAuth,  /* in, out */
 
1419
                                         UINT32 * encDataSizeOut,       /* out */
 
1420
                                         BYTE ** encDataOut,    /* out */
 
1421
                                         TCPA_SALT_NONCE * saltNonce,   /* out */
 
1422
                                         TCPA_DIGEST * changeProof      /* out */
 
1423
    ) {
 
1424
        return TSPERR(TSS_E_NOTIMPL);
 
1425
}
 
1426
 
 
1427
TSS_RESULT
 
1428
TCSP_TerminateHandle_TP(struct host_table_entry *hte,
 
1429
                                    TCS_AUTHHANDLE handle       /* in */
 
1430
    ) {
 
1431
        TSS_RESULT result;
 
1432
 
 
1433
        initData(&hte->comm, 2);
 
1434
 
 
1435
        hte->comm.hdr.u.ordinal = TCSD_ORD_TERMINATEHANDLE;
 
1436
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1437
 
 
1438
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1439
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1440
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm))
 
1441
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1442
 
 
1443
        result = sendTCSDPacket(hte);
 
1444
 
 
1445
        if (result == TSS_SUCCESS)
 
1446
                result = hte->comm.hdr.u.result;
 
1447
 
 
1448
        return result;
 
1449
}
 
1450
 
 
1451
TSS_RESULT
 
1452
TCSP_ActivateTPMIdentity_TP(struct host_table_entry *hte,
 
1453
                                        TCS_KEY_HANDLE idKey,   /* in */
 
1454
                                        UINT32 blobSize,        /* in */
 
1455
                                        BYTE * blob,    /* in */
 
1456
                                        TPM_AUTH * idKeyAuth,   /* in, out */
 
1457
                                        TPM_AUTH * ownerAuth,   /* in, out */
 
1458
                                        UINT32 * SymmetricKeySize,      /* out */
 
1459
                                        BYTE ** SymmetricKey    /* out */
 
1460
    ) {
 
1461
        TSS_RESULT result;
 
1462
        int i = 0;
 
1463
 
 
1464
        initData(&hte->comm, 6);
 
1465
 
 
1466
        hte->comm.hdr.u.ordinal = TCSD_ORD_ACTIVATETPMIDENTITY;
 
1467
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1468
 
 
1469
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm))
 
1470
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1471
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &idKey, 0, &hte->comm))
 
1472
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1473
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &blobSize, 0, &hte->comm))
 
1474
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1475
        if (setData(TCSD_PACKET_TYPE_PBYTE, i++, blob, blobSize, &hte->comm))
 
1476
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1477
 
 
1478
        if (idKeyAuth) {
 
1479
                if (setData(TCSD_PACKET_TYPE_AUTH, i++, idKeyAuth, 0, &hte->comm))
 
1480
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1481
        }
 
1482
        if (setData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm))
 
1483
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1484
 
 
1485
        result = sendTCSDPacket(hte);
 
1486
 
 
1487
        if (result == TSS_SUCCESS)
 
1488
                result = hte->comm.hdr.u.result;
 
1489
 
 
1490
        if (result == TSS_SUCCESS) {
 
1491
                i = 0;
 
1492
                if (idKeyAuth) {
 
1493
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, idKeyAuth, 0, &hte->comm))
 
1494
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1495
                }
 
1496
                if (getData(TCSD_PACKET_TYPE_AUTH, i++, ownerAuth, 0, &hte->comm))
 
1497
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1498
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, SymmetricKeySize, 0, &hte->comm))
 
1499
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1500
 
 
1501
                *SymmetricKey = malloc(*SymmetricKeySize);
 
1502
                if (*SymmetricKey == NULL) {
 
1503
                        LogError("malloc of %u bytes failed.", *SymmetricKeySize);
 
1504
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1505
                }
 
1506
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *SymmetricKey, *SymmetricKeySize, &hte->comm)) {
 
1507
                        free(*SymmetricKey);
 
1508
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1509
                }
 
1510
        }
 
1511
 
 
1512
        return result;
 
1513
}
 
1514
 
 
1515
TSS_RESULT
 
1516
TCSP_Extend_TP(struct host_table_entry *hte,
 
1517
                           TCPA_PCRINDEX pcrNum,        /* in */
 
1518
                           TCPA_DIGEST inDigest,        /* in */
 
1519
                           TCPA_PCRVALUE * outDigest    /* out */
 
1520
    ) {
 
1521
        TSS_RESULT result;
 
1522
 
 
1523
        initData(&hte->comm, 3);
 
1524
 
 
1525
        hte->comm.hdr.u.ordinal = TCSD_ORD_EXTEND;
 
1526
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1527
 
 
1528
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1529
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1530
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &pcrNum, 0, &hte->comm))
 
1531
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1532
        if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &inDigest, 0, &hte->comm))
 
1533
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1534
 
 
1535
        result = sendTCSDPacket(hte);
 
1536
 
 
1537
        if (result == TSS_SUCCESS)
 
1538
                result = hte->comm.hdr.u.result;
 
1539
 
 
1540
        if (result == TSS_SUCCESS) {
 
1541
                if (getData(TCSD_PACKET_TYPE_DIGEST, 0, outDigest, 0, &hte->comm))
 
1542
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1543
        }
 
1544
 
 
1545
        return result;
 
1546
}
 
1547
 
 
1548
TSS_RESULT
 
1549
TCSP_PcrRead_TP(struct host_table_entry *hte,
 
1550
                            TCPA_PCRINDEX pcrNum,       /* in */
 
1551
                            TCPA_PCRVALUE * outDigest   /* out */
 
1552
    ) {
 
1553
        TSS_RESULT result;
 
1554
 
 
1555
        initData(&hte->comm, 2);
 
1556
 
 
1557
        hte->comm.hdr.u.ordinal = TCSD_ORD_PCRREAD;
 
1558
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1559
 
 
1560
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1561
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1562
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &pcrNum, 0, &hte->comm))
 
1563
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1564
 
 
1565
        result = sendTCSDPacket(hte);
 
1566
 
 
1567
        if (result == TSS_SUCCESS)
 
1568
                result = hte->comm.hdr.u.result;
 
1569
 
 
1570
        if (result == TSS_SUCCESS) {
 
1571
                if (getData(TCSD_PACKET_TYPE_DIGEST, 0, outDigest, 0, &hte->comm))
 
1572
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1573
        }
 
1574
 
 
1575
        return result;
 
1576
}
 
1577
 
 
1578
TSS_RESULT
 
1579
TCSP_Quote_TP(struct host_table_entry *hte,
 
1580
                          TCS_KEY_HANDLE keyHandle,     /* in */
 
1581
                          TCPA_NONCE antiReplay,        /* in */
 
1582
                          UINT32 pcrDataSizeIn, /* in */
 
1583
                          BYTE * pcrDataIn,     /* in */
 
1584
                          TPM_AUTH * privAuth,  /* in, out */
 
1585
                          UINT32 * pcrDataSizeOut,      /* out */
 
1586
                          BYTE ** pcrDataOut,   /* out */
 
1587
                          UINT32 * sigSize,     /* out */
 
1588
                          BYTE ** sig   /* out */
 
1589
    ) {
 
1590
        TSS_RESULT result;
 
1591
        int i;
 
1592
 
 
1593
        initData(&hte->comm, 6);
 
1594
 
 
1595
        hte->comm.hdr.u.ordinal = TCSD_ORD_QUOTE;
 
1596
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1597
 
 
1598
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1599
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1600
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
 
1601
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1602
        if (setData(TCSD_PACKET_TYPE_NONCE, 2, &antiReplay, 0, &hte->comm))
 
1603
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1604
        if (setData(TCSD_PACKET_TYPE_UINT32, 3, &pcrDataSizeIn, 0, &hte->comm))
 
1605
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1606
        if (setData(TCSD_PACKET_TYPE_PBYTE, 4, pcrDataIn, pcrDataSizeIn, &hte->comm))
 
1607
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1608
 
 
1609
        if (privAuth) {
 
1610
                if (setData(TCSD_PACKET_TYPE_AUTH, 5, privAuth, 0, &hte->comm))
 
1611
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1612
        }
 
1613
 
 
1614
        result = sendTCSDPacket(hte);
 
1615
 
 
1616
        if (result == TSS_SUCCESS)
 
1617
                result = hte->comm.hdr.u.result;
 
1618
 
 
1619
        if (result == TSS_SUCCESS) {
 
1620
                i = 0;
 
1621
                if (privAuth) {
 
1622
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm))
 
1623
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1624
                }
 
1625
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcrDataSizeOut, 0, &hte->comm))
 
1626
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1627
 
 
1628
                *pcrDataOut = (BYTE *) malloc(*pcrDataSizeOut);
 
1629
                if (*pcrDataOut == NULL) {
 
1630
                        LogError("malloc of %u bytes failed.", *pcrDataSizeOut);
 
1631
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1632
                }
 
1633
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *pcrDataOut, *pcrDataSizeOut, &hte->comm)) {
 
1634
                        free(*pcrDataOut);
 
1635
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1636
                }
 
1637
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) {
 
1638
                        free(*pcrDataOut);
 
1639
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1640
                }
 
1641
                *sig = (BYTE *) malloc(*sigSize);
 
1642
                if (*sig == NULL) {
 
1643
                        LogError("malloc of %u bytes failed.", *sigSize);
 
1644
                        free(*pcrDataOut);
 
1645
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1646
                }
 
1647
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
 
1648
                        free(*pcrDataOut);
 
1649
                        free(*sig);
 
1650
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1651
                }
 
1652
        }
 
1653
 
 
1654
        return result;
 
1655
}
 
1656
 
 
1657
TSS_RESULT
 
1658
TCSP_DirWriteAuth_TP(struct host_table_entry *hte,
 
1659
                                 TCPA_DIRINDEX dirIndex,        /* in */
 
1660
                                 TCPA_DIRVALUE newContents,     /* in */
 
1661
                                 TPM_AUTH * ownerAuth   /* in, out */
 
1662
    ) {
 
1663
        TSS_RESULT result;
 
1664
 
 
1665
        initData(&hte->comm, 4);
 
1666
 
 
1667
        hte->comm.hdr.u.ordinal = TCSD_ORD_DIRWRITEAUTH;
 
1668
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1669
 
 
1670
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1671
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1672
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &hte->comm))
 
1673
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1674
        if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &newContents, 0, &hte->comm))
 
1675
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1676
        if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm))
 
1677
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1678
 
 
1679
        result = sendTCSDPacket(hte);
 
1680
 
 
1681
        if (result == TSS_SUCCESS)
 
1682
                result = hte->comm.hdr.u.result;
 
1683
 
 
1684
        if (result == TSS_SUCCESS) {
 
1685
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
1686
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1687
        }
 
1688
 
 
1689
        return result;
 
1690
}
 
1691
 
 
1692
TSS_RESULT
 
1693
TCSP_DirRead_TP(struct host_table_entry *hte,
 
1694
                            TCPA_DIRINDEX dirIndex,     /* in */
 
1695
                            TCPA_DIRVALUE * dirValue    /* out */
 
1696
    ) {
 
1697
        TSS_RESULT result;
 
1698
 
 
1699
        initData(&hte->comm, 2);
 
1700
 
 
1701
        hte->comm.hdr.u.ordinal = TCSD_ORD_DIRREAD;
 
1702
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1703
 
 
1704
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1705
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1706
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &hte->comm))
 
1707
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1708
 
 
1709
        result = sendTCSDPacket(hte);
 
1710
 
 
1711
        if (result == TSS_SUCCESS)
 
1712
                result = hte->comm.hdr.u.result;
 
1713
 
 
1714
        if (result == TSS_SUCCESS) {
 
1715
                if (getData(TCSD_PACKET_TYPE_DIGEST, 0, dirValue, 0, &hte->comm))
 
1716
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1717
        }
 
1718
 
 
1719
        return result;
 
1720
}
 
1721
 
 
1722
TSS_RESULT
 
1723
TCSP_Seal_TP(struct host_table_entry *hte,
 
1724
                         TCS_KEY_HANDLE keyHandle,      /* in */
 
1725
                         TCPA_ENCAUTH encAuth,  /* in */
 
1726
                         UINT32 pcrInfoSize,    /* in */
 
1727
                         BYTE * PcrInfo,        /* in */
 
1728
                         UINT32 inDataSize,     /* in */
 
1729
                         BYTE * inData, /* in */
 
1730
                         TPM_AUTH * pubAuth,    /* in, out */
 
1731
                         UINT32 * SealedDataSize,       /* out */
 
1732
                         BYTE ** SealedData     /* out */
 
1733
    ) {
 
1734
        TSS_RESULT result;
 
1735
        int i = 0;
 
1736
 
 
1737
        initData(&hte->comm, 8);
 
1738
 
 
1739
        hte->comm.hdr.u.ordinal = TCSD_ORD_SEAL;
 
1740
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1741
 
 
1742
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm))
 
1743
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1744
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &keyHandle, 0, &hte->comm))
 
1745
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1746
        if (setData(TCSD_PACKET_TYPE_ENCAUTH, i++, &encAuth, 0, &hte->comm))
 
1747
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1748
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &pcrInfoSize, 0, &hte->comm))
 
1749
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1750
        if (pcrInfoSize > 0) {
 
1751
                if (setData(TCSD_PACKET_TYPE_PBYTE, i++, PcrInfo, pcrInfoSize, &hte->comm))
 
1752
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1753
        }
 
1754
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &inDataSize, 0, &hte->comm))
 
1755
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1756
        if (inDataSize > 0) {
 
1757
                if (setData(TCSD_PACKET_TYPE_PBYTE, i++, inData, inDataSize, &hte->comm))
 
1758
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1759
        }
 
1760
 
 
1761
        if (setData(TCSD_PACKET_TYPE_AUTH, i, pubAuth, 0, &hte->comm))
 
1762
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1763
 
 
1764
        result = sendTCSDPacket(hte);
 
1765
 
 
1766
        if (result == TSS_SUCCESS)
 
1767
                result = hte->comm.hdr.u.result;
 
1768
 
 
1769
        if (result == TSS_SUCCESS) {
 
1770
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, pubAuth, 0, &hte->comm))
 
1771
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1772
 
 
1773
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, SealedDataSize, 0, &hte->comm))
 
1774
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1775
 
 
1776
                *SealedData = (BYTE *) malloc(*SealedDataSize);
 
1777
                if (*SealedData == NULL) {
 
1778
                        LogError("malloc of %u bytes failed.", *SealedDataSize);
 
1779
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1780
                }
 
1781
                if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *SealedData, *SealedDataSize, &hte->comm)) {
 
1782
                        free(*SealedData);
 
1783
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1784
                }
 
1785
        }
 
1786
 
 
1787
        return result;
 
1788
}
 
1789
 
 
1790
TSS_RESULT
 
1791
TCSP_Unseal_TP(struct host_table_entry *hte,
 
1792
                           TCS_KEY_HANDLE parentHandle, /* in */
 
1793
                           UINT32 SealedDataSize,       /* in */
 
1794
                           BYTE * SealedData,   /* in */
 
1795
                           TPM_AUTH * parentAuth,       /* in, out */
 
1796
                           TPM_AUTH * dataAuth, /* in, out */
 
1797
                           UINT32 * DataSize,   /* out */
 
1798
                           BYTE ** Data /* out */
 
1799
    ) {
 
1800
        TSS_RESULT result;
 
1801
 
 
1802
        initData(&hte->comm, 6);
 
1803
 
 
1804
        hte->comm.hdr.u.ordinal = TCSD_ORD_UNSEAL;
 
1805
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1806
 
 
1807
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1808
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1809
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm))
 
1810
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1811
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &SealedDataSize, 0, &hte->comm))
 
1812
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1813
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, SealedData, SealedDataSize, &hte->comm))
 
1814
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1815
 
 
1816
        if (parentAuth != NULL) {
 
1817
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, parentAuth, 0, &hte->comm))
 
1818
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1819
        }
 
1820
 
 
1821
        if (setData(TCSD_PACKET_TYPE_AUTH, 5, dataAuth, 0, &hte->comm))
 
1822
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1823
 
 
1824
        result = sendTCSDPacket(hte);
 
1825
 
 
1826
        if (result == TSS_SUCCESS)
 
1827
                result = hte->comm.hdr.u.result;
 
1828
 
 
1829
        if (result == TSS_SUCCESS) {
 
1830
                if (parentAuth != NULL) {
 
1831
                        if (getData(TCSD_PACKET_TYPE_AUTH, 0, parentAuth, 0, &hte->comm))
 
1832
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1833
                }
 
1834
 
 
1835
                if (getData(TCSD_PACKET_TYPE_AUTH, 1, dataAuth, 0, &hte->comm))
 
1836
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1837
 
 
1838
                if (getData(TCSD_PACKET_TYPE_UINT32, 2, DataSize, 0, &hte->comm))
 
1839
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1840
 
 
1841
                *Data = (BYTE *) calloc_tspi(hte->tspContext, *DataSize);
 
1842
                if (*Data == NULL) {
 
1843
                        LogError("malloc of %u bytes failed.", *DataSize);
 
1844
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1845
                }
 
1846
                if (getData(TCSD_PACKET_TYPE_PBYTE, 3, *Data, *DataSize, &hte->comm)) {
 
1847
                        free_tspi(hte->tspContext, *Data);
 
1848
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1849
                }
 
1850
        }
 
1851
 
 
1852
        return result;
 
1853
}
 
1854
 
 
1855
TSS_RESULT
 
1856
TCSP_UnBind_TP(struct host_table_entry *hte,
 
1857
                           TCS_KEY_HANDLE keyHandle,    /* in */
 
1858
                           UINT32 inDataSize,   /* in */
 
1859
                           BYTE * inData,       /* in */
 
1860
                           TPM_AUTH * privAuth, /* in, out */
 
1861
                           UINT32 * outDataSize,        /* out */
 
1862
                           BYTE ** outData      /* out */
 
1863
    ) {
 
1864
        TSS_RESULT result;
 
1865
        int i;
 
1866
 
 
1867
        initData(&hte->comm, 5);
 
1868
 
 
1869
        hte->comm.hdr.u.ordinal = TCSD_ORD_UNBIND;
 
1870
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1871
 
 
1872
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
1873
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1874
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
 
1875
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1876
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &inDataSize, 0, &hte->comm))
 
1877
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1878
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, inData, inDataSize, &hte->comm))
 
1879
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1880
 
 
1881
        if (privAuth != NULL) {
 
1882
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm))
 
1883
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1884
        }
 
1885
 
 
1886
        result = sendTCSDPacket(hte);
 
1887
 
 
1888
        if (result == TSS_SUCCESS)
 
1889
                result = hte->comm.hdr.u.result;
 
1890
 
 
1891
        if (result == TSS_SUCCESS) {
 
1892
                i = 0;
 
1893
                if (privAuth != NULL) {
 
1894
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm))
 
1895
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1896
                }
 
1897
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm))
 
1898
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1899
 
 
1900
                *outData = (BYTE *) calloc_tspi(hte->tspContext, *outDataSize);
 
1901
                if (*outData == NULL) {
 
1902
                        LogError("malloc of %u bytes failed.", *outDataSize);
 
1903
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
1904
                }
 
1905
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) {
 
1906
                        free_tspi(hte->tspContext, *outData);
 
1907
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1908
                }
 
1909
        }
 
1910
 
 
1911
        return result;
 
1912
}
 
1913
 
 
1914
TSS_RESULT
 
1915
TCSP_CreateMigrationBlob_TP(struct host_table_entry *hte,
 
1916
                                        TCS_KEY_HANDLE parentHandle,    /* in */
 
1917
                                        TSS_MIGRATE_SCHEME migrationType,       /* in */
 
1918
                                        UINT32 MigrationKeyAuthSize,    /* in */
 
1919
                                        BYTE * MigrationKeyAuth,        /* in */
 
1920
                                        UINT32 encDataSize,     /* in */
 
1921
                                        BYTE * encData, /* in */
 
1922
                                        TPM_AUTH * parentAuth,  /* in, out */
 
1923
                                        TPM_AUTH * entityAuth,  /* in, out */
 
1924
                                        UINT32 * randomSize,    /* out */
 
1925
                                        BYTE ** random, /* out */
 
1926
                                        UINT32 * outDataSize,   /* out */
 
1927
                                        BYTE ** outData /* out */
 
1928
    ) {
 
1929
        TSS_RESULT result;
 
1930
        TPM_AUTH null_auth;
 
1931
        UINT32 i;
 
1932
 
 
1933
        initData(&hte->comm, 9);
 
1934
 
 
1935
        hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEMIGRATIONBLOB;
 
1936
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
1937
 
 
1938
        memset(&null_auth, 0, sizeof(TPM_AUTH));
 
1939
        i = 0;
 
1940
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &hte->tcsContext, 0, &hte->comm))
 
1941
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1942
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &parentHandle, 0, &hte->comm))
 
1943
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1944
        if (setData(TCSD_PACKET_TYPE_UINT16, i++, &migrationType, 0, &hte->comm))
 
1945
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1946
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &MigrationKeyAuthSize, 0, &hte->comm))
 
1947
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1948
        if (setData(TCSD_PACKET_TYPE_PBYTE, i++, MigrationKeyAuth, MigrationKeyAuthSize, &hte->comm))
 
1949
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1950
        if (setData(TCSD_PACKET_TYPE_UINT32, i++, &encDataSize, 0, &hte->comm))
 
1951
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1952
        if (setData(TCSD_PACKET_TYPE_PBYTE, i++, encData, encDataSize, &hte->comm))
 
1953
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1954
 
 
1955
        if (parentAuth) {
 
1956
                if (setData(TCSD_PACKET_TYPE_AUTH, i++, parentAuth, 0, &hte->comm))
 
1957
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1958
        }
 
1959
 
 
1960
        if (setData(TCSD_PACKET_TYPE_AUTH, i++, entityAuth, 0, &hte->comm))
 
1961
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1962
 
 
1963
        result = sendTCSDPacket(hte);
 
1964
 
 
1965
        if (result == TSS_SUCCESS)
 
1966
                result = hte->comm.hdr.u.result;
 
1967
 
 
1968
        if (result == TSS_SUCCESS) {
 
1969
                i = 0;
 
1970
                if (parentAuth) {
 
1971
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, parentAuth, 0, &hte->comm))
 
1972
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1973
                }
 
1974
                if (getData(TCSD_PACKET_TYPE_AUTH, i++, entityAuth, 0, &hte->comm))
 
1975
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1976
 
 
1977
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, randomSize, 0, &hte->comm))
 
1978
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1979
 
 
1980
                if (*randomSize > 0) {
 
1981
                        *random = (BYTE *)calloc_tspi(hte->tspContext, *randomSize);
 
1982
                        if (*random == NULL) {
 
1983
                                LogError("malloc of %u bytes failed.", *randomSize);
 
1984
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
1985
                        }
 
1986
                        if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *random, *randomSize, &hte->comm)) {
 
1987
                                free_tspi(hte->tspContext, *random);
 
1988
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
1989
                        }
 
1990
                }
 
1991
 
 
1992
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) {
 
1993
                        if (*randomSize > 0)
 
1994
                                free_tspi(hte->tspContext, *random);
 
1995
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
1996
                }
 
1997
 
 
1998
                *outData = (BYTE *)calloc_tspi(hte->tspContext, *outDataSize);
 
1999
                if (*outData == NULL) {
 
2000
                        if (*randomSize > 0)
 
2001
                                free_tspi(hte->tspContext, *random);
 
2002
                        LogError("malloc of %u bytes failed.", *outDataSize);
 
2003
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2004
                }
 
2005
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) {
 
2006
                        if (*randomSize > 0)
 
2007
                                free_tspi(hte->tspContext, *random);
 
2008
                        free_tspi(hte->tspContext, *outData);
 
2009
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2010
                }
 
2011
        }
 
2012
 
 
2013
        return result;
 
2014
}
 
2015
 
 
2016
TSS_RESULT
 
2017
TCSP_ConvertMigrationBlob_TP(struct host_table_entry *hte,
 
2018
                                         TCS_KEY_HANDLE parentHandle,   /* in */
 
2019
                                         UINT32 inDataSize,     /* in */
 
2020
                                         BYTE * inData, /* in */
 
2021
                                         UINT32 randomSize,     /* in */
 
2022
                                         BYTE * random, /* in */
 
2023
                                         TPM_AUTH * parentAuth, /* in, out */
 
2024
                                         UINT32 * outDataSize,  /* out */
 
2025
                                         BYTE ** outData        /* out */
 
2026
    ) {
 
2027
        TSS_RESULT result;
 
2028
        UINT32 i;
 
2029
 
 
2030
        initData(&hte->comm, 7);
 
2031
 
 
2032
        hte->comm.hdr.u.ordinal = TCSD_ORD_CONVERTMIGRATIONBLOB;
 
2033
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2034
 
 
2035
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2036
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2037
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm))
 
2038
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2039
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &inDataSize, 0, &hte->comm))
 
2040
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2041
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, inData, inDataSize, &hte->comm))
 
2042
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2043
        if (setData(TCSD_PACKET_TYPE_UINT32, 4, &randomSize, 0, &hte->comm))
 
2044
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2045
        if (setData(TCSD_PACKET_TYPE_PBYTE, 5, random, randomSize, &hte->comm))
 
2046
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2047
 
 
2048
        if (parentAuth) {
 
2049
                if (setData(TCSD_PACKET_TYPE_AUTH, 6, parentAuth, 0, &hte->comm))
 
2050
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2051
        }
 
2052
 
 
2053
        result = sendTCSDPacket(hte);
 
2054
 
 
2055
        if (result == TSS_SUCCESS)
 
2056
                result = hte->comm.hdr.u.result;
 
2057
 
 
2058
        if (result == TSS_SUCCESS) {
 
2059
                i = 0;
 
2060
                if (parentAuth) {
 
2061
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, parentAuth, 0, &hte->comm))
 
2062
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2063
                }
 
2064
 
 
2065
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm))
 
2066
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2067
 
 
2068
                *outData = (BYTE *)malloc(*outDataSize);
 
2069
                if (*outData == NULL) {
 
2070
                        LogError("malloc of %u bytes failed.", *outDataSize);
 
2071
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2072
                }
 
2073
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) {
 
2074
                        free(*outData);
 
2075
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2076
                }
 
2077
        }
 
2078
 
 
2079
        return result;
 
2080
}
 
2081
 
 
2082
TSS_RESULT
 
2083
TCSP_AuthorizeMigrationKey_TP(struct host_table_entry *hte,
 
2084
                                          TSS_MIGRATE_SCHEME migrateScheme,     /* in */
 
2085
                                          UINT32 MigrationKeySize,      /* in */
 
2086
                                          BYTE * MigrationKey,  /* in */
 
2087
                                          TPM_AUTH * ownerAuth, /* in, out */
 
2088
                                          UINT32 * MigrationKeyAuthSize,        /* out */
 
2089
                                          BYTE ** MigrationKeyAuth      /* out */
 
2090
    ) {
 
2091
        TSS_RESULT result;
 
2092
 
 
2093
        initData(&hte->comm, 5);
 
2094
 
 
2095
        hte->comm.hdr.u.ordinal = TCSD_ORD_AUTHORIZEMIGRATIONKEY;
 
2096
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2097
 
 
2098
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2099
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2100
        if (setData(TCSD_PACKET_TYPE_UINT16, 1, &migrateScheme, 0, &hte->comm))
 
2101
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2102
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &MigrationKeySize, 0, &hte->comm))
 
2103
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2104
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, MigrationKey, MigrationKeySize, &hte->comm))
 
2105
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2106
        if (setData(TCSD_PACKET_TYPE_AUTH, 4, ownerAuth, 0, &hte->comm))
 
2107
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2108
 
 
2109
        result = sendTCSDPacket(hte);
 
2110
 
 
2111
        if (result == TSS_SUCCESS)
 
2112
                result = hte->comm.hdr.u.result;
 
2113
 
 
2114
        if (result == TSS_SUCCESS) {
 
2115
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
2116
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2117
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, MigrationKeyAuthSize, 0, &hte->comm))
 
2118
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2119
 
 
2120
                *MigrationKeyAuth = (BYTE *)calloc_tspi(hte->tspContext, *MigrationKeyAuthSize);
 
2121
                if (*MigrationKeyAuth == NULL) {
 
2122
                        LogError("malloc of %u bytes failed.", *MigrationKeyAuthSize);
 
2123
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2124
                }
 
2125
                if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *MigrationKeyAuth, *MigrationKeyAuthSize,
 
2126
                            &hte->comm)) {
 
2127
                        free(*MigrationKeyAuth);
 
2128
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2129
                }
 
2130
        }
 
2131
 
 
2132
        return result;
 
2133
}
 
2134
 
 
2135
TSS_RESULT
 
2136
TCSP_CertifyKey_TP(struct host_table_entry *hte,
 
2137
                               TCS_KEY_HANDLE certHandle,       /* in */
 
2138
                               TCS_KEY_HANDLE keyHandle,        /* in */
 
2139
                               TCPA_NONCE antiReplay,   /* in */
 
2140
                               TPM_AUTH * certAuth,     /* in, out */
 
2141
                               TPM_AUTH * keyAuth,      /* in, out */
 
2142
                               UINT32 * CertifyInfoSize,        /* out */
 
2143
                               BYTE ** CertifyInfo,     /* out */
 
2144
                               UINT32 * outDataSize,    /* out */
 
2145
                               BYTE ** outData  /* out */
 
2146
    ) {
 
2147
        TSS_RESULT result;
 
2148
        TPM_AUTH null_auth;
 
2149
        int i;
 
2150
 
 
2151
        initData(&hte->comm, 6);
 
2152
 
 
2153
        hte->comm.hdr.u.ordinal = TCSD_ORD_CERTIFYKEY;
 
2154
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2155
 
 
2156
        memset(&null_auth, 0, sizeof(TPM_AUTH));
 
2157
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2158
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2159
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &certHandle, 0, &hte->comm))
 
2160
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2161
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &keyHandle, 0, &hte->comm))
 
2162
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2163
        if (setData(TCSD_PACKET_TYPE_NONCE, 3, &antiReplay, 0, &hte->comm))
 
2164
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2165
        if (certAuth) {
 
2166
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, certAuth, 0, &hte->comm))
 
2167
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2168
        } else {
 
2169
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, &null_auth, 0, &hte->comm))
 
2170
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2171
        }
 
2172
        if (keyAuth) {
 
2173
                if (setData(TCSD_PACKET_TYPE_AUTH, 5, keyAuth, 0, &hte->comm))
 
2174
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2175
        } else {
 
2176
                if (setData(TCSD_PACKET_TYPE_AUTH, 5, &null_auth, 0, &hte->comm))
 
2177
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2178
        }
 
2179
 
 
2180
        result = sendTCSDPacket(hte);
 
2181
 
 
2182
        if (result == TSS_SUCCESS)
 
2183
                result = hte->comm.hdr.u.result;
 
2184
 
 
2185
        if (result == TSS_SUCCESS) {
 
2186
                i = 0;
 
2187
                if (certAuth) {
 
2188
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, certAuth, 0, &hte->comm))
 
2189
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2190
                }
 
2191
                if (keyAuth) {
 
2192
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, keyAuth, 0, &hte->comm))
 
2193
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2194
                }
 
2195
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, CertifyInfoSize, 0, &hte->comm))
 
2196
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2197
 
 
2198
                *CertifyInfo = (BYTE *) malloc(*CertifyInfoSize);
 
2199
                if (*CertifyInfo == NULL) {
 
2200
                        LogError("malloc of %u bytes failed.", *CertifyInfoSize);
 
2201
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2202
                }
 
2203
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *CertifyInfo, *CertifyInfoSize, &hte->comm)) {
 
2204
                        free(*CertifyInfo);
 
2205
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2206
                }
 
2207
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, outDataSize, 0, &hte->comm)) {
 
2208
                        free(*CertifyInfo);
 
2209
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2210
                }
 
2211
 
 
2212
                *outData = (BYTE *) malloc(*outDataSize);
 
2213
                if (*outData == NULL) {
 
2214
                        LogError("malloc of %u bytes failed.", *outDataSize);
 
2215
                        free(*CertifyInfo);
 
2216
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2217
                }
 
2218
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *outData, *outDataSize, &hte->comm)) {
 
2219
                        free(*CertifyInfo);
 
2220
                        free(*outData);
 
2221
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2222
                }
 
2223
        }
 
2224
 
 
2225
        return result;
 
2226
}
 
2227
 
 
2228
TSS_RESULT
 
2229
TCSP_Sign_TP(struct host_table_entry *hte,
 
2230
                         TCS_KEY_HANDLE keyHandle,      /* in */
 
2231
                         UINT32 areaToSignSize, /* in */
 
2232
                         BYTE * areaToSign,     /* in */
 
2233
                         TPM_AUTH * privAuth,   /* in, out */
 
2234
                         UINT32 * sigSize,      /* out */
 
2235
                         BYTE ** sig    /* out */
 
2236
    ) {
 
2237
        TSS_RESULT result;
 
2238
        int i;
 
2239
 
 
2240
        initData(&hte->comm, 5);
 
2241
 
 
2242
        hte->comm.hdr.u.ordinal = TCSD_ORD_SIGN;
 
2243
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2244
 
 
2245
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2246
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2247
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
 
2248
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2249
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &areaToSignSize, 0, &hte->comm))
 
2250
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2251
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, areaToSign, areaToSignSize, &hte->comm))
 
2252
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2253
 
 
2254
        if (privAuth) {
 
2255
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm))
 
2256
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2257
        }
 
2258
 
 
2259
        result = sendTCSDPacket(hte);
 
2260
 
 
2261
        if (result == TSS_SUCCESS)
 
2262
                result = hte->comm.hdr.u.result;
 
2263
 
 
2264
        if (result == TSS_SUCCESS) {
 
2265
                i = 0;
 
2266
                if (privAuth) {
 
2267
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm))
 
2268
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2269
                }
 
2270
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm))
 
2271
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2272
 
 
2273
                *sig = (BYTE *) calloc_tspi(hte->tspContext, *sigSize);
 
2274
                if (*sig == NULL) {
 
2275
                        LogError("malloc of %u bytes failed.", *sigSize);
 
2276
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2277
                }
 
2278
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
 
2279
                        free_tspi(hte->tspContext, *sig);
 
2280
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2281
                }
 
2282
        }
 
2283
 
 
2284
        return result;
 
2285
}
 
2286
 
 
2287
TSS_RESULT
 
2288
TCSP_GetRandom_TP(struct host_table_entry *hte,
 
2289
                              UINT32 bytesRequested,    /* in */
 
2290
                              BYTE ** randomBytes       /* out */
 
2291
    ) {
 
2292
        TSS_RESULT result;
 
2293
 
 
2294
        initData(&hte->comm, 2);
 
2295
 
 
2296
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETRANDOM;
 
2297
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2298
 
 
2299
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2300
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2301
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &bytesRequested, 0, &hte->comm))
 
2302
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2303
 
 
2304
        result = sendTCSDPacket(hte);
 
2305
 
 
2306
        if (result == TSS_SUCCESS)
 
2307
                result = hte->comm.hdr.u.result;
 
2308
 
 
2309
        if (result == TSS_SUCCESS) {
 
2310
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, &bytesRequested, 0, &hte->comm))
 
2311
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2312
                *randomBytes = (BYTE *) calloc_tspi(hte->tspContext, bytesRequested);
 
2313
                if (*randomBytes == NULL) {
 
2314
                        LogError("malloc of %u bytes failed.", bytesRequested);
 
2315
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2316
                }
 
2317
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *randomBytes, bytesRequested, &hte->comm)) {
 
2318
                        free_tspi(hte->tspContext, *randomBytes);
 
2319
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2320
                }
 
2321
        }
 
2322
 
 
2323
        return result;
 
2324
}
 
2325
 
 
2326
TSS_RESULT
 
2327
TCSP_StirRandom_TP(struct host_table_entry *hte,
 
2328
                               UINT32 inDataSize,       /* in */
 
2329
                               BYTE * inData    /* in */
 
2330
    ) {
 
2331
        TSS_RESULT result;
 
2332
 
 
2333
        initData(&hte->comm, 3);
 
2334
 
 
2335
        hte->comm.hdr.u.ordinal = TCSD_ORD_STIRRANDOM;
 
2336
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2337
 
 
2338
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2339
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2340
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &inDataSize, 0, &hte->comm))
 
2341
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2342
        if (setData(TCSD_PACKET_TYPE_PBYTE, 2, inData, inDataSize, &hte->comm))
 
2343
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2344
 
 
2345
        result = sendTCSDPacket(hte);
 
2346
 
 
2347
        if (result == TSS_SUCCESS)
 
2348
                result = hte->comm.hdr.u.result;
 
2349
 
 
2350
        return result;
 
2351
}
 
2352
 
 
2353
TSS_RESULT
 
2354
TCSP_GetCapability_TP(struct host_table_entry *hte,
 
2355
                                  TCPA_CAPABILITY_AREA capArea, /* in */
 
2356
                                  UINT32 subCapSize,    /* in */
 
2357
                                  BYTE * subCap,        /* in */
 
2358
                                  UINT32 * respSize,    /* out */
 
2359
                                  BYTE ** resp  /* out */
 
2360
    ) {
 
2361
        TSS_RESULT result;
 
2362
 
 
2363
        initData(&hte->comm, 4);
 
2364
 
 
2365
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETCAPABILITY;
 
2366
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2367
 
 
2368
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2369
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2370
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm))
 
2371
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2372
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm))
 
2373
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2374
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm))
 
2375
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2376
 
 
2377
        result = sendTCSDPacket(hte);
 
2378
 
 
2379
        if (result == TSS_SUCCESS)
 
2380
                result = hte->comm.hdr.u.result;
 
2381
 
 
2382
        if (result == TSS_SUCCESS) {
 
2383
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, respSize, 0, &hte->comm))
 
2384
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2385
 
 
2386
                *resp = (BYTE *) malloc(*respSize);
 
2387
                if (*resp == NULL) {
 
2388
                        LogError("malloc of %u bytes failed.", *respSize);
 
2389
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2390
                }
 
2391
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *resp, *respSize, &hte->comm)) {
 
2392
                        free(*resp);
 
2393
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2394
                }
 
2395
        }
 
2396
 
 
2397
        return result;
 
2398
}
 
2399
 
 
2400
TSS_RESULT
 
2401
TCS_GetCapability_TP(struct host_table_entry *hte,
 
2402
                                 TCPA_CAPABILITY_AREA capArea,  /* in */
 
2403
                                 UINT32 subCapSize,     /* in */
 
2404
                                 BYTE * subCap, /* in */
 
2405
                                 UINT32 * respSize,     /* out */
 
2406
                                 BYTE ** resp   /* out */
 
2407
    ) {
 
2408
        TSS_RESULT result;
 
2409
 
 
2410
        initData(&hte->comm, 4);
 
2411
 
 
2412
        hte->comm.hdr.u.ordinal = TCSD_ORD_TCSGETCAPABILITY;
 
2413
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2414
 
 
2415
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2416
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2417
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm))
 
2418
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2419
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm))
 
2420
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2421
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm))
 
2422
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2423
 
 
2424
        result = sendTCSDPacket(hte);
 
2425
 
 
2426
        if (result == TSS_SUCCESS)
 
2427
                result = hte->comm.hdr.u.result;
 
2428
 
 
2429
        if (result == TSS_SUCCESS) {
 
2430
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, respSize, 0, &hte->comm))
 
2431
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2432
 
 
2433
                *resp = (BYTE *) calloc_tspi(hte->tspContext, *respSize);
 
2434
                if (*resp == NULL) {
 
2435
                        LogError("malloc of %u bytes failed.", *respSize);
 
2436
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2437
                }
 
2438
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *resp, *respSize, &hte->comm)) {
 
2439
                        free_tspi(hte->tspContext, *resp);
 
2440
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2441
                }
 
2442
        }
 
2443
 
 
2444
        return result;
 
2445
}
 
2446
 
 
2447
TSS_RESULT
 
2448
TCSP_GetCapabilitySigned_TP(struct host_table_entry *hte,
 
2449
                                        TCS_KEY_HANDLE keyHandle,       /* in */
 
2450
                                        TCPA_NONCE antiReplay,  /* in */
 
2451
                                        TCPA_CAPABILITY_AREA capArea,   /* in */
 
2452
                                        UINT32 subCapSize,      /* in */
 
2453
                                        BYTE * subCap,  /* in */
 
2454
                                        TPM_AUTH * privAuth,    /* in, out */
 
2455
                                        TCPA_VERSION * Version, /* out */
 
2456
                                        UINT32 * respSize,      /* out */
 
2457
                                        BYTE ** resp,   /* out */
 
2458
                                        UINT32 * sigSize,       /* out */
 
2459
                                        BYTE ** sig     /* out */
 
2460
    ) {
 
2461
        return TSPERR(TSS_E_NOTIMPL);
 
2462
}
 
2463
 
 
2464
TSS_RESULT
 
2465
TCSP_GetCapabilityOwner_TP(struct host_table_entry *hte,
 
2466
                                       TPM_AUTH * pOwnerAuth,   /* out */
 
2467
                                       TCPA_VERSION * pVersion, /* out */
 
2468
                                       UINT32 * pNonVolatileFlags,      /* out */
 
2469
                                       UINT32 * pVolatileFlags  /* out */
 
2470
    ) {
 
2471
        TSS_RESULT result;
 
2472
 
 
2473
        initData(&hte->comm, 2);
 
2474
 
 
2475
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETCAPABILITYOWNER;
 
2476
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2477
 
 
2478
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2479
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2480
        if (setData(TCSD_PACKET_TYPE_AUTH, 1, pOwnerAuth, 0, &hte->comm))
 
2481
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2482
 
 
2483
        result = sendTCSDPacket(hte);
 
2484
 
 
2485
        if (result == TSS_SUCCESS)
 
2486
                result = hte->comm.hdr.u.result;
 
2487
 
 
2488
        if (result == TSS_SUCCESS) {
 
2489
                if (getData(TCSD_PACKET_TYPE_VERSION, 0, pVersion, 0, &hte->comm))
 
2490
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2491
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, pNonVolatileFlags, 0, &hte->comm))
 
2492
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2493
                if (getData(TCSD_PACKET_TYPE_UINT32, 2, pVolatileFlags, 0, &hte->comm))
 
2494
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2495
                if (getData(TCSD_PACKET_TYPE_AUTH, 3, pOwnerAuth, 0, &hte->comm))
 
2496
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2497
        }
 
2498
 
 
2499
        return result;
 
2500
}
 
2501
 
 
2502
TSS_RESULT
 
2503
TCSP_CreateEndorsementKeyPair_TP(struct host_table_entry *hte,
 
2504
                                             TCPA_NONCE antiReplay,     /* in */
 
2505
                                             UINT32 endorsementKeyInfoSize,     /* in */
 
2506
                                             BYTE * endorsementKeyInfo, /* in */
 
2507
                                             UINT32 * endorsementKeySize,       /* out */
 
2508
                                             BYTE ** endorsementKey,    /* out */
 
2509
                                             TCPA_DIGEST * checksum     /* out */
 
2510
    ) {
 
2511
 
 
2512
        TSS_RESULT result;
 
2513
 
 
2514
        initData(&hte->comm, 4);
 
2515
 
 
2516
        hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEENDORSEMENTKEYPAIR;
 
2517
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2518
 
 
2519
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2520
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2521
        if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm))
 
2522
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2523
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &endorsementKeyInfoSize, 0, &hte->comm))
 
2524
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2525
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, endorsementKeyInfo, endorsementKeyInfoSize, &hte->comm))
 
2526
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2527
 
 
2528
        result = sendTCSDPacket(hte);
 
2529
 
 
2530
        if (result == TSS_SUCCESS)
 
2531
                result = hte->comm.hdr.u.result;
 
2532
 
 
2533
        if (result == TSS_SUCCESS) {
 
2534
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, endorsementKeySize, 0, &hte->comm))
 
2535
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2536
 
 
2537
                *endorsementKey = (BYTE *) malloc(*endorsementKeySize);
 
2538
                if (*endorsementKey == NULL) {
 
2539
                        LogError("malloc of %u bytes failed.", *endorsementKeySize);
 
2540
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2541
                }
 
2542
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *endorsementKey, *endorsementKeySize, &hte->comm)) {
 
2543
                        free(*endorsementKey);
 
2544
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2545
                }
 
2546
                if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &(checksum->digest), 0, &hte->comm)) {
 
2547
                        free(*endorsementKey);
 
2548
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2549
                }
 
2550
        }
 
2551
 
 
2552
        return result;
 
2553
}
 
2554
 
 
2555
TSS_RESULT
 
2556
TCSP_ReadPubek_TP(struct host_table_entry *hte,
 
2557
                              TCPA_NONCE antiReplay,    /* in */
 
2558
                              UINT32 * pubEndorsementKeySize,   /* out */
 
2559
                              BYTE ** pubEndorsementKey,        /* out */
 
2560
                              TCPA_DIGEST * checksum    /* out */
 
2561
    ) {
 
2562
        TSS_RESULT result;
 
2563
 
 
2564
        initData(&hte->comm, 2);
 
2565
 
 
2566
        hte->comm.hdr.u.ordinal = TCSD_ORD_READPUBEK;
 
2567
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2568
 
 
2569
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2570
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2571
        if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm))
 
2572
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2573
 
 
2574
        result = sendTCSDPacket(hte);
 
2575
 
 
2576
        if (result == TSS_SUCCESS)
 
2577
                result = hte->comm.hdr.u.result;
 
2578
 
 
2579
        if (result == TSS_SUCCESS) {
 
2580
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, pubEndorsementKeySize, 0, &hte->comm))
 
2581
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2582
 
 
2583
                *pubEndorsementKey = (BYTE *) malloc(*pubEndorsementKeySize);
 
2584
                if (*pubEndorsementKey == NULL) {
 
2585
                        LogError("malloc of %u bytes failed.", *pubEndorsementKeySize);
 
2586
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2587
                }
 
2588
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *pubEndorsementKey, *pubEndorsementKeySize, &hte->comm)) {
 
2589
                        free(*pubEndorsementKey);
 
2590
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2591
                }
 
2592
                if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &(checksum->digest), 0, &hte->comm)) {
 
2593
                        free(*pubEndorsementKey);
 
2594
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2595
                }
 
2596
        }
 
2597
 
 
2598
        return result;
 
2599
}
 
2600
 
 
2601
TSS_RESULT
 
2602
TCSP_DisablePubekRead_TP(struct host_table_entry *hte,
 
2603
                                     TPM_AUTH * ownerAuth       /* in, out */
 
2604
    ) {
 
2605
        TSS_RESULT result;
 
2606
 
 
2607
        initData(&hte->comm, 2);
 
2608
 
 
2609
        hte->comm.hdr.u.ordinal = TCSD_ORD_DISABLEPUBEKREAD;
 
2610
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2611
 
 
2612
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2613
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2614
        if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm))
 
2615
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2616
 
 
2617
        result = sendTCSDPacket(hte);
 
2618
 
 
2619
        if (result == TSS_SUCCESS)
 
2620
                result = hte->comm.hdr.u.result;
 
2621
 
 
2622
        if (result == TSS_SUCCESS) {
 
2623
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
2624
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2625
        }
 
2626
 
 
2627
        return result;
 
2628
}
 
2629
 
 
2630
TSS_RESULT
 
2631
TCSP_OwnerReadPubek_TP(struct host_table_entry *hte,
 
2632
                                   TPM_AUTH * ownerAuth,        /* in, out */
 
2633
                                   UINT32 * pubEndorsementKeySize,      /* out */
 
2634
                                   BYTE ** pubEndorsementKey    /* out */
 
2635
    ) {
 
2636
 
 
2637
        TSS_RESULT result;
 
2638
 
 
2639
        initData(&hte->comm, 2);
 
2640
 
 
2641
        hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERREADPUBEK;
 
2642
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2643
 
 
2644
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2645
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2646
        if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm))
 
2647
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2648
 
 
2649
        result = sendTCSDPacket(hte);
 
2650
 
 
2651
        if (result == TSS_SUCCESS)
 
2652
                result = hte->comm.hdr.u.result;
 
2653
 
 
2654
        if (result == TSS_SUCCESS) {
 
2655
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
2656
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2657
 
 
2658
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, pubEndorsementKeySize, 0, &hte->comm))
 
2659
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2660
 
 
2661
                *pubEndorsementKey = (BYTE *) malloc(*pubEndorsementKeySize);
 
2662
                if (*pubEndorsementKey == NULL) {
 
2663
                        LogError("malloc of %u bytes failed.", *pubEndorsementKeySize);
 
2664
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2665
                }
 
2666
 
 
2667
                if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *pubEndorsementKey, *pubEndorsementKeySize, &hte->comm)) {
 
2668
                        free(*pubEndorsementKey);
 
2669
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2670
                }
 
2671
        }
 
2672
 
 
2673
        return result;
 
2674
}
 
2675
 
 
2676
TSS_RESULT
 
2677
TCSP_SelfTestFull_TP(struct host_table_entry *hte)
 
2678
{
 
2679
        TSS_RESULT result;
 
2680
 
 
2681
        initData(&hte->comm, 1);
 
2682
 
 
2683
        hte->comm.hdr.u.ordinal = TCSD_ORD_SELFTESTFULL;
 
2684
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2685
 
 
2686
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2687
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2688
 
 
2689
        result = sendTCSDPacket(hte);
 
2690
 
 
2691
        if (result == TSS_SUCCESS)
 
2692
                result = hte->comm.hdr.u.result;
 
2693
 
 
2694
        return result;
 
2695
}
 
2696
 
 
2697
TSS_RESULT
 
2698
TCSP_CertifySelfTest_TP(struct host_table_entry *hte,
 
2699
                                    TCS_KEY_HANDLE keyHandle,   /* in */
 
2700
                                    TCPA_NONCE antiReplay,      /* in */
 
2701
                                    TPM_AUTH * privAuth,        /* in, out */
 
2702
                                    UINT32 * sigSize,   /* out */
 
2703
                                    BYTE ** sig /* out */
 
2704
    ) {
 
2705
        TSS_RESULT result;
 
2706
        int i;
 
2707
 
 
2708
        initData(&hte->comm, 4);
 
2709
 
 
2710
        hte->comm.hdr.u.ordinal = TCSD_ORD_CERTIFYSELFTEST;
 
2711
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2712
 
 
2713
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2714
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2715
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
 
2716
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2717
        if (setData(TCSD_PACKET_TYPE_NONCE, 2, &antiReplay, 0, &hte->comm))
 
2718
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2719
 
 
2720
        if (privAuth) {
 
2721
                if (setData(TCSD_PACKET_TYPE_AUTH, 3, privAuth, 0, &hte->comm))
 
2722
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2723
        }
 
2724
 
 
2725
        result = sendTCSDPacket(hte);
 
2726
 
 
2727
        if (result == TSS_SUCCESS)
 
2728
                result = hte->comm.hdr.u.result;
 
2729
 
 
2730
        if (result == TSS_SUCCESS) {
 
2731
                i = 0;
 
2732
                if (privAuth) {
 
2733
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) {
 
2734
                                LogDebug("privAuth");
 
2735
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2736
                        }
 
2737
                }
 
2738
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) {
 
2739
                        LogDebug("sigSize");
 
2740
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2741
                }
 
2742
                *sig = (BYTE *) malloc(*sigSize);
 
2743
                if (*sig == NULL) {
 
2744
                        LogError("malloc of %u bytes failed.", *sigSize);
 
2745
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2746
                }
 
2747
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
 
2748
                        LogDebug("sig");
 
2749
                        free(*sig);
 
2750
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2751
                }
 
2752
        }
 
2753
 
 
2754
        return result;
 
2755
}
 
2756
 
 
2757
TSS_RESULT
 
2758
TCSP_GetTestResult_TP(struct host_table_entry *hte,
 
2759
                                  UINT32 * outDataSize, /* out */
 
2760
                                  BYTE ** outData       /* out */
 
2761
    ) {
 
2762
        TSS_RESULT result;
 
2763
 
 
2764
        initData(&hte->comm, 1);
 
2765
 
 
2766
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETTESTRESULT;
 
2767
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2768
 
 
2769
        LogDebug("TCSP_GetTestResult_TP");
 
2770
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2771
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2772
 
 
2773
        result = sendTCSDPacket(hte);
 
2774
 
 
2775
        if (result == TSS_SUCCESS)
 
2776
                result = hte->comm.hdr.u.result;
 
2777
 
 
2778
        if (result == TSS_SUCCESS) {
 
2779
                LogDebug("sendTCSDPacket succeeded");
 
2780
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, outDataSize, 0, &hte->comm))
 
2781
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2782
 
 
2783
                *outData = calloc_tspi(hte->tspContext, *outDataSize);
 
2784
                if (*outData == NULL) {
 
2785
                        LogError("malloc of %u bytes failed.", *outDataSize);
 
2786
                        return TSPERR(TSS_E_OUTOFMEMORY);
 
2787
                }
 
2788
 
 
2789
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *outData, *outDataSize, &hte->comm)) {
 
2790
                        free_tspi(hte->tspContext, *outData);
 
2791
                        *outData = NULL;
 
2792
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2793
                }
 
2794
        }
 
2795
        LogDebug("TCSP_GetTestResult_TP exit");
 
2796
 
 
2797
        return result;
 
2798
}
 
2799
 
 
2800
TSS_RESULT
 
2801
TCSP_OwnerClear_TP(struct host_table_entry *hte,
 
2802
                               TPM_AUTH * ownerAuth     /* in, out */
 
2803
    ) {
 
2804
        TSS_RESULT result;
 
2805
 
 
2806
        initData(&hte->comm, 2);
 
2807
 
 
2808
        hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERCLEAR;
 
2809
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2810
 
 
2811
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2812
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2813
        if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm))
 
2814
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2815
 
 
2816
        result = sendTCSDPacket(hte);
 
2817
 
 
2818
        if (result == TSS_SUCCESS)
 
2819
                result = hte->comm.hdr.u.result;
 
2820
 
 
2821
        if (result == TSS_SUCCESS ){
 
2822
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
2823
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2824
        }
 
2825
 
 
2826
        return result;
 
2827
}
 
2828
 
 
2829
TSS_RESULT
 
2830
TCSP_DisableOwnerClear_TP(struct host_table_entry *hte,
 
2831
                                      TPM_AUTH * ownerAuth      /* in, out */
 
2832
    ) {
 
2833
        TSS_RESULT result;
 
2834
 
 
2835
        initData(&hte->comm, 2);
 
2836
 
 
2837
        hte->comm.hdr.u.ordinal = TCSD_ORD_DISABLEOWNERCLEAR;
 
2838
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2839
 
 
2840
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2841
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2842
        if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm))
 
2843
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2844
 
 
2845
        result = sendTCSDPacket(hte);
 
2846
 
 
2847
        if (result == TSS_SUCCESS)
 
2848
                result = hte->comm.hdr.u.result;
 
2849
 
 
2850
        if (result == TSS_SUCCESS ){
 
2851
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
2852
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2853
        }
 
2854
 
 
2855
        return result;
 
2856
}
 
2857
 
 
2858
TSS_RESULT
 
2859
TCSP_ForceClear_TP(struct host_table_entry *hte)
 
2860
{
 
2861
        TSS_RESULT result;
 
2862
 
 
2863
        initData(&hte->comm, 1);
 
2864
 
 
2865
        hte->comm.hdr.u.ordinal = TCSD_ORD_FORCECLEAR;
 
2866
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2867
 
 
2868
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2869
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2870
 
 
2871
        result = sendTCSDPacket(hte);
 
2872
 
 
2873
        if (result == TSS_SUCCESS)
 
2874
                result = hte->comm.hdr.u.result;
 
2875
 
 
2876
        return result;
 
2877
}
 
2878
 
 
2879
TSS_RESULT
 
2880
TCSP_DisableForceClear_TP(struct host_table_entry *hte)
 
2881
{
 
2882
        TSS_RESULT result;
 
2883
 
 
2884
        initData(&hte->comm, 1);
 
2885
 
 
2886
        hte->comm.hdr.u.ordinal = TCSD_ORD_DISABLEFORCECLEAR;
 
2887
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2888
 
 
2889
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2890
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2891
 
 
2892
        result = sendTCSDPacket(hte);
 
2893
 
 
2894
        if (result == TSS_SUCCESS)
 
2895
                result = hte->comm.hdr.u.result;
 
2896
 
 
2897
        return result;
 
2898
}
 
2899
 
 
2900
TSS_RESULT
 
2901
TCSP_PhysicalDisable_TP(struct host_table_entry *hte)
 
2902
{
 
2903
        TSS_RESULT result;
 
2904
 
 
2905
        initData(&hte->comm, 1);
 
2906
 
 
2907
        hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALDISABLE;
 
2908
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2909
 
 
2910
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2911
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2912
 
 
2913
        result = sendTCSDPacket(hte);
 
2914
 
 
2915
        if (result == TSS_SUCCESS)
 
2916
                result = hte->comm.hdr.u.result;
 
2917
 
 
2918
        return result;
 
2919
}
 
2920
 
 
2921
TSS_RESULT
 
2922
TCSP_PhysicalEnable_TP(struct host_table_entry *hte)
 
2923
{
 
2924
        TSS_RESULT result;
 
2925
 
 
2926
        initData(&hte->comm, 1);
 
2927
 
 
2928
        hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALENABLE;
 
2929
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2930
 
 
2931
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2932
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2933
 
 
2934
        result = sendTCSDPacket(hte);
 
2935
 
 
2936
        if (result == TSS_SUCCESS)
 
2937
                result = hte->comm.hdr.u.result;
 
2938
 
 
2939
        return result;
 
2940
}
 
2941
 
 
2942
TSS_RESULT
 
2943
TCSP_OwnerSetDisable_TP(struct host_table_entry *hte,
 
2944
                        TSS_BOOL disableState,     /*  in */
 
2945
                        TPM_AUTH * ownerAuth   /*  in, out */
 
2946
) {
 
2947
        TSS_RESULT result;
 
2948
 
 
2949
        initData(&hte->comm, 3);
 
2950
 
 
2951
        hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERSETDISABLE;
 
2952
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2953
 
 
2954
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2955
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2956
        if (setData(TCSD_PACKET_TYPE_BOOL, 1, &disableState, 0, &hte->comm))
 
2957
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2958
        if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm))
 
2959
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2960
 
 
2961
        result = sendTCSDPacket(hte);
 
2962
 
 
2963
        if (result == TSS_SUCCESS)
 
2964
                result = hte->comm.hdr.u.result;
 
2965
 
 
2966
        if (result == TSS_SUCCESS) {
 
2967
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
2968
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
2969
        }
 
2970
 
 
2971
        return result;
 
2972
}
 
2973
 
 
2974
 
 
2975
TSS_RESULT
 
2976
TCSP_PhysicalSetDeactivated_TP(struct host_table_entry *hte,
 
2977
                                           TSS_BOOL state       /* in */
 
2978
    ) {
 
2979
        TSS_RESULT result;
 
2980
 
 
2981
        initData(&hte->comm, 2);
 
2982
 
 
2983
        hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALSETDEACTIVATED;
 
2984
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
2985
 
 
2986
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
2987
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2988
        if (setData(TCSD_PACKET_TYPE_BOOL, 1, &state, 0, &hte->comm))
 
2989
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
2990
 
 
2991
        result = sendTCSDPacket(hte);
 
2992
 
 
2993
        if (result == TSS_SUCCESS)
 
2994
                result = hte->comm.hdr.u.result;
 
2995
 
 
2996
        return result;
 
2997
}
 
2998
 
 
2999
TSS_RESULT
 
3000
TCSP_PhysicalPresence_TP(struct host_table_entry *hte,
 
3001
                                TCPA_PHYSICAL_PRESENCE fPhysicalPresence        /* in */
 
3002
    ) {
 
3003
        TSS_RESULT result;
 
3004
 
 
3005
        initData(&hte->comm, 2);
 
3006
 
 
3007
        hte->comm.hdr.u.ordinal = TCSD_ORD_PHYSICALPRESENCE;
 
3008
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3009
 
 
3010
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3011
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3012
        if (setData(TCSD_PACKET_TYPE_UINT16, 1, &fPhysicalPresence, 0, &hte->comm))
 
3013
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3014
 
 
3015
        result = sendTCSDPacket(hte);
 
3016
 
 
3017
        if (result == TSS_SUCCESS)
 
3018
                result = hte->comm.hdr.u.result;
 
3019
 
 
3020
        return result;
 
3021
}
 
3022
 
 
3023
TSS_RESULT
 
3024
TCSP_SetTempDeactivated_TP(struct host_table_entry *hte)
 
3025
{
 
3026
        TSS_RESULT result;
 
3027
 
 
3028
        initData(&hte->comm, 1);
 
3029
 
 
3030
        hte->comm.hdr.u.ordinal = TCSD_ORD_SETTEMPDEACTIVATED;
 
3031
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3032
 
 
3033
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3034
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3035
 
 
3036
        result = sendTCSDPacket(hte);
 
3037
 
 
3038
        if (result == TSS_SUCCESS)
 
3039
                result = hte->comm.hdr.u.result;
 
3040
 
 
3041
        return result;
 
3042
}
 
3043
 
 
3044
TSS_RESULT
 
3045
TCSP_FieldUpgrade_TP(struct host_table_entry *hte,
 
3046
                                 UINT32 dataInSize,     /* in */
 
3047
                                 BYTE * dataIn, /* in */
 
3048
                                 UINT32 * dataOutSize,  /* out */
 
3049
                                 BYTE ** dataOut,       /* out */
 
3050
                                 TPM_AUTH * ownerAuth   /* in, out */
 
3051
    ) {
 
3052
        return TSPERR(TSS_E_NOTIMPL);
 
3053
}
 
3054
 
 
3055
TSS_RESULT
 
3056
TCSP_SetRedirection_TP(struct host_table_entry *hte,
 
3057
                                   TCS_KEY_HANDLE keyHandle,    /* in */
 
3058
                                   UINT32 c1,   /* in */
 
3059
                                   UINT32 c2,   /* in */
 
3060
                                   TPM_AUTH * privAuth  /* in, out */
 
3061
    ) {
 
3062
        return TSPERR(TSS_E_NOTIMPL);
 
3063
 
 
3064
}
 
3065
 
 
3066
TSS_RESULT
 
3067
TCSP_CreateMaintenanceArchive_TP(struct host_table_entry *hte,
 
3068
                                             TSS_BOOL generateRandom,   /* in */
 
3069
                                             TPM_AUTH * ownerAuth,      /* in, out */
 
3070
                                             UINT32 * randomSize,       /* out */
 
3071
                                             BYTE ** random,    /* out */
 
3072
                                             UINT32 * archiveSize,      /* out */
 
3073
                                             BYTE ** archive    /* out */
 
3074
    ) {
 
3075
        TSS_RESULT result;
 
3076
 
 
3077
        initData(&hte->comm, 3);
 
3078
 
 
3079
        hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEMAINTENANCEARCHIVE;
 
3080
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3081
 
 
3082
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3083
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3084
        if (setData(TCSD_PACKET_TYPE_BOOL, 1, &generateRandom, 0, &hte->comm))
 
3085
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3086
        if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm))
 
3087
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3088
 
 
3089
        result = sendTCSDPacket(hte);
 
3090
 
 
3091
        if (result == TSS_SUCCESS)
 
3092
                result = hte->comm.hdr.u.result;
 
3093
 
 
3094
        if (result == TSS_SUCCESS) {
 
3095
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
3096
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3097
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, randomSize, 0, &hte->comm))
 
3098
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3099
 
 
3100
                if (*randomSize > 0) {
 
3101
                        *random = calloc_tspi(hte->tspContext, *randomSize);
 
3102
                        if (*random == NULL) {
 
3103
                                LogError("malloc of %u bytes failed.", *randomSize);
 
3104
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
3105
                        }
 
3106
 
 
3107
                        if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *random, *randomSize, &hte->comm)) {
 
3108
                                free_tspi(hte->tspContext, *random);
 
3109
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3110
                        }
 
3111
                } else {
 
3112
                        *random = NULL;
 
3113
                }
 
3114
 
 
3115
                /* Assume all elements are in the list, even when *randomSize == 0. */
 
3116
                if (getData(TCSD_PACKET_TYPE_UINT32, 3, archiveSize, 0, &hte->comm)) {
 
3117
                        free_tspi(hte->tspContext, *random);
 
3118
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3119
                }
 
3120
 
 
3121
                if (*archiveSize > 0) {
 
3122
                        *archive = calloc_tspi(hte->tspContext, *archiveSize);
 
3123
                        if (*archive == NULL) {
 
3124
                                LogError("malloc of %u bytes failed.", *archiveSize);
 
3125
                                free_tspi(hte->tspContext, *random);
 
3126
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
3127
                        }
 
3128
 
 
3129
                        if (getData(TCSD_PACKET_TYPE_PBYTE, 4, *archive, *archiveSize, &hte->comm)) {
 
3130
                                free_tspi(hte->tspContext, *random);
 
3131
                                free_tspi(hte->tspContext, *archive);
 
3132
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3133
                        }
 
3134
                } else {
 
3135
                        *archive = NULL;
 
3136
                }
 
3137
        }
 
3138
 
 
3139
        return result;
 
3140
}
 
3141
 
 
3142
TSS_RESULT
 
3143
TCSP_LoadMaintenanceArchive_TP(struct host_table_entry *hte,
 
3144
                                           UINT32 dataInSize,   /* in */
 
3145
                                           BYTE * dataIn,       /* in */
 
3146
                                           TPM_AUTH * ownerAuth,        /* in, out */
 
3147
                                           UINT32 * dataOutSize,        /* out */
 
3148
                                           BYTE ** dataOut      /* out */
 
3149
    ) {
 
3150
        TSS_RESULT result;
 
3151
 
 
3152
        initData(&hte->comm, 4);
 
3153
 
 
3154
        hte->comm.hdr.u.ordinal = TCSD_ORD_LOADMAINTENANCEARCHIVE;
 
3155
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3156
 
 
3157
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3158
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3159
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dataInSize, 0, &hte->comm))
 
3160
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3161
        if (setData(TCSD_PACKET_TYPE_PBYTE, 2, &dataIn, dataInSize, &hte->comm))
 
3162
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3163
        if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm))
 
3164
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3165
 
 
3166
        result = sendTCSDPacket(hte);
 
3167
 
 
3168
        if (result == TSS_SUCCESS)
 
3169
                result = hte->comm.hdr.u.result;
 
3170
 
 
3171
        if (result == TSS_SUCCESS) {
 
3172
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
3173
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3174
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, dataOutSize, 0, &hte->comm))
 
3175
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3176
 
 
3177
                if (*dataOutSize > 0) {
 
3178
                        *dataOut = malloc(*dataOutSize);
 
3179
                        if (*dataOut == NULL) {
 
3180
                                LogError("malloc of %u bytes failed.", *dataOutSize);
 
3181
                                return TSPERR(TSS_E_OUTOFMEMORY);
 
3182
                        }
 
3183
 
 
3184
                        if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *dataOut, *dataOutSize, &hte->comm)) {
 
3185
                                free(*dataOut);
 
3186
                                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3187
                        }
 
3188
                } else {
 
3189
                        *dataOut = NULL;
 
3190
                }
 
3191
        }
 
3192
 
 
3193
        return result;
 
3194
}
 
3195
 
 
3196
TSS_RESULT
 
3197
TCSP_KillMaintenanceFeature_TP(struct host_table_entry *hte,
 
3198
                                           TPM_AUTH * ownerAuth /* in , out */
 
3199
    ) {
 
3200
        TSS_RESULT result;
 
3201
 
 
3202
        initData(&hte->comm, 2);
 
3203
 
 
3204
        hte->comm.hdr.u.ordinal = TCSD_ORD_KILLMAINTENANCEFEATURE;
 
3205
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3206
 
 
3207
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3208
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3209
        if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm))
 
3210
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3211
 
 
3212
        result = sendTCSDPacket(hte);
 
3213
 
 
3214
        if (result == TSS_SUCCESS)
 
3215
                result = hte->comm.hdr.u.result;
 
3216
 
 
3217
        if (result == TSS_SUCCESS) {
 
3218
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
3219
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3220
        }
 
3221
 
 
3222
        return result;
 
3223
}
 
3224
 
 
3225
TSS_RESULT
 
3226
TCSP_LoadManuMaintPub_TP(struct host_table_entry *hte,
 
3227
                                     TCPA_NONCE antiReplay,     /* in */
 
3228
                                     UINT32 PubKeySize, /* in */
 
3229
                                     BYTE * PubKey,     /* in */
 
3230
                                     TCPA_DIGEST * checksum     /* out */
 
3231
    ) {
 
3232
        TSS_RESULT result;
 
3233
 
 
3234
        initData(&hte->comm, 4);
 
3235
 
 
3236
        hte->comm.hdr.u.ordinal = TCSD_ORD_LOADMANUFACTURERMAINTENANCEPUB;
 
3237
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3238
 
 
3239
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3240
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3241
        if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm))
 
3242
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3243
        if (setData(TCSD_PACKET_TYPE_UINT32, 2, &PubKeySize, 0, &hte->comm))
 
3244
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3245
        if (setData(TCSD_PACKET_TYPE_PBYTE, 3, PubKey, PubKeySize, &hte->comm))
 
3246
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3247
 
 
3248
        result = sendTCSDPacket(hte);
 
3249
 
 
3250
        if (result == TSS_SUCCESS)
 
3251
                result = hte->comm.hdr.u.result;
 
3252
 
 
3253
        if (result == TSS_SUCCESS) {
 
3254
                if (getData(TCSD_PACKET_TYPE_DIGEST, 0, checksum, 0, &hte->comm))
 
3255
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3256
        }
 
3257
 
 
3258
        return result;
 
3259
}
 
3260
 
 
3261
TSS_RESULT
 
3262
TCSP_ReadManuMaintPub_TP(struct host_table_entry *hte,
 
3263
                                     TCPA_NONCE antiReplay,     /* in */
 
3264
                                     TCPA_DIGEST * checksum     /* out */
 
3265
    ) {
 
3266
        TSS_RESULT result;
 
3267
 
 
3268
        initData(&hte->comm, 2);
 
3269
 
 
3270
        hte->comm.hdr.u.ordinal = TCSD_ORD_READMANUFACTURERMAINTENANCEPUB;
 
3271
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
3272
 
 
3273
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
3274
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3275
        if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm))
 
3276
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
3277
 
 
3278
        result = sendTCSDPacket(hte);
 
3279
 
 
3280
        if (result == TSS_SUCCESS)
 
3281
                result = hte->comm.hdr.u.result;
 
3282
 
 
3283
        if (result == TSS_SUCCESS) {
 
3284
                if (getData(TCSD_PACKET_TYPE_DIGEST, 0, checksum, 0, &hte->comm))
 
3285
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
3286
        }
 
3287
 
 
3288
        return result;
 
3289
}