3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004-2006
16
#include <sys/types.h>
22
#include "trousers/tss.h"
23
#include "trousers_types.h"
24
#include "trousers_types.h"
26
#include "tcs_utils.h"
27
#include "tcs_int_literals.h"
30
#include "tcsd_wrap.h"
35
LoadBlob_SYMMETRIC_KEY(UINT64 *offset, BYTE *blob, TCPA_SYMMETRIC_KEY *key)
37
LoadBlob_UINT32(offset, key->algId, blob);
38
LoadBlob_UINT16(offset, key->encScheme, blob);
39
LoadBlob_UINT16(offset, key->size, blob);
42
LoadBlob(offset, key->size, blob, key->data);
49
UnloadBlob_SYMMETRIC_KEY(UINT64 *offset, BYTE *blob, TCPA_SYMMETRIC_KEY *key)
54
UnloadBlob_UINT32(offset, NULL, blob);
55
UnloadBlob_UINT16(offset, NULL, blob);
56
UnloadBlob_UINT16(offset, &size, blob);
59
UnloadBlob(offset, size, blob, NULL);
64
UnloadBlob_UINT32(offset, &key->algId, blob);
65
UnloadBlob_UINT16(offset, &key->encScheme, blob);
66
UnloadBlob_UINT16(offset, &key->size, blob);
69
key->data = (BYTE *)malloc(key->size);
70
if (key->data == NULL) {
71
LogError("malloc of %hu bytes failed.", key->size);
73
return TCSERR(TSS_E_OUTOFMEMORY);
75
UnloadBlob(offset, key->size, blob, key->data);
84
get_credential(UINT32 type, UINT32 *size, BYTE **cred)
93
case TSS_TCS_CREDENTIAL_PLATFORMCERT:
94
path = tcsd_options.platform_cred;
96
case TSS_TCS_CREDENTIAL_TPM_CC:
97
path = tcsd_options.conformance_cred;
99
case TSS_TCS_CREDENTIAL_EKCERT:
100
path = tcsd_options.endorsement_cred;
103
LogDebugFn("Bad credential type");
110
if ((fd = open(path, O_RDONLY)) < 0) {
111
LogError("open(%s): %s", path, strerror(errno));
115
if ((rc = fstat(fd, &stat_buf)) == -1) {
116
LogError("Error stating credential: %s: %s", path, strerror(errno));
120
file_size = (size_t)stat_buf.st_size;
122
LogDebugFn("%s, (%zd bytes)", path, file_size);
124
file = mmap(0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
125
if (file == MAP_FAILED) {
126
LogError("Error reading credential: %s: %s", path, strerror(errno));
132
if ((*cred = malloc(file_size)) == NULL) {
133
LogError("malloc of %zd bytes failed.", file_size);
134
munmap(file, file_size);
138
memcpy(*cred, file, file_size);
140
munmap(file, file_size);