1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*
* Licensed Materials - Property of IBM
*
* trousers - An open source TCG Software Stack
*
* (C) Copyright International Business Machines Corp. 2007
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "trousers/tss.h"
#include "trousers_types.h"
#include "tcs_tsp.h"
#include "tcs_utils.h"
#include "tcs_int_literals.h"
#include "capabilities.h"
#include "tcslog.h"
#include "tcsps.h"
#include "req_mgr.h"
TSS_RESULT
TCSP_ReadCounter_Internal(TCS_CONTEXT_HANDLE hContext,
TSS_COUNTER_ID idCounter,
TPM_COUNTER_VALUE* counterValue)
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = tpm_rqu_build(TPM_ORD_ReadCounter, &offset, txBlob, idCounter, NULL)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto out;
if ((result = UnloadBlob_Header(txBlob, ¶mSize))) {
LogDebugFn("TPM_ReadCounter failed: rc=0x%x", result);
goto out;
}
if (!result) {
result = tpm_rsp_parse(TPM_ORD_ReadCounter, txBlob, paramSize, NULL, counterValue,
NULL);
}
out:
return result;
}
TSS_RESULT
TCSP_CreateCounter_Internal(TCS_CONTEXT_HANDLE hContext,
UINT32 LabelSize,
BYTE* pLabel,
TPM_ENCAUTH CounterAuth,
TPM_AUTH* pOwnerAuth,
TSS_COUNTER_ID* idCounter,
TPM_COUNTER_VALUE* counterValue)
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
if (LabelSize != 4) {
LogDebugFn("BAD_PARAMETER: LabelSize != 4");
return TCSERR(TSS_E_BAD_PARAMETER);
}
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = auth_mgr_check(hContext, &pOwnerAuth->AuthHandle)))
return result;
if ((result = tpm_rqu_build(TPM_ORD_CreateCounter, &offset, txBlob, CounterAuth.authdata,
LabelSize, pLabel, pOwnerAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto out;
if ((result = UnloadBlob_Header(txBlob, ¶mSize))) {
LogDebugFn("TPM_CreateCounter failed: rc=0x%x", result);
goto out;
}
if (!result) {
result = tpm_rsp_parse(TPM_ORD_CreateCounter, txBlob, paramSize, idCounter,
counterValue, pOwnerAuth);
}
out:
return result;
}
TSS_RESULT
TCSP_IncrementCounter_Internal(TCS_CONTEXT_HANDLE hContext,
TSS_COUNTER_ID idCounter,
TPM_AUTH* pCounterAuth,
TPM_COUNTER_VALUE* counterValue)
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = auth_mgr_check(hContext, &pCounterAuth->AuthHandle)))
return result;
if ((result = tpm_rqu_build(TPM_ORD_IncrementCounter, &offset, txBlob, idCounter,
pCounterAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto out;
if ((result = UnloadBlob_Header(txBlob, ¶mSize))) {
LogDebugFn("UnloadBlob_Header failed: rc=0x%x", result);
goto out;
}
if (!result) {
result = tpm_rsp_parse(TPM_ORD_IncrementCounter, txBlob, paramSize, NULL,
counterValue, pCounterAuth);
}
out:
return result;
}
TSS_RESULT
TCSP_ReleaseCounter_Internal(TCS_CONTEXT_HANDLE hContext,
TSS_COUNTER_ID idCounter,
TPM_AUTH* pCounterAuth)
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = auth_mgr_check(hContext, &pCounterAuth->AuthHandle)))
return result;
if ((result = tpm_rqu_build(TPM_ORD_ReleaseCounter, &offset, txBlob, idCounter,
pCounterAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto out;
if ((result = UnloadBlob_Header(txBlob, ¶mSize))) {
LogDebugFn("UnloadBlob_Header failed: rc=0x%x", result);
goto out;
}
if (!result) {
result = tpm_rsp_parse(TPM_ORD_ReleaseCounter, txBlob, paramSize, pCounterAuth);
}
out:
return result;
}
TSS_RESULT
TCSP_ReleaseCounterOwner_Internal(TCS_CONTEXT_HANDLE hContext,
TSS_COUNTER_ID idCounter,
TPM_AUTH* pOwnerAuth)
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = auth_mgr_check(hContext, &pOwnerAuth->AuthHandle)))
return result;
if ((result = tpm_rqu_build(TPM_ORD_ReleaseCounterOwner, &offset, txBlob, idCounter,
pOwnerAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto out;
if ((result = UnloadBlob_Header(txBlob, ¶mSize))) {
LogDebugFn("UnloadBlob_Header failed: rc=0x%x", result);
goto out;
}
if (!result) {
result = tpm_rsp_parse(TPM_ORD_ReleaseCounterOwner, txBlob, paramSize, pOwnerAuth);
}
out:
return result;
}
|