summaryrefslogtreecommitdiffstats
path: root/src/tpm12/tpm_pcr.h
blob: 6036c9d956a1c768bddaf52a44f553148446243a (plain)
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/********************************************************************************/
/*                                                                              */
/*                              PCR Handler                                     */
/*                           Written by Ken Goldman                             */
/*                     IBM Thomas J. Watson Research Center                     */
/*            $Id: tpm_pcr.h 4620 2011-09-07 21:43:19Z kgoldman $               */
/*                                                                              */
/* (c) Copyright IBM Corporation 2006, 2010.					*/
/*										*/
/* All rights reserved.								*/
/* 										*/
/* Redistribution and use in source and binary forms, with or without		*/
/* modification, are permitted provided that the following conditions are	*/
/* met:										*/
/* 										*/
/* Redistributions of source code must retain the above copyright notice,	*/
/* this list of conditions and the following disclaimer.			*/
/* 										*/
/* Redistributions in binary form must reproduce the above copyright		*/
/* notice, this list of conditions and the following disclaimer in the		*/
/* documentation and/or other materials provided with the distribution.		*/
/* 										*/
/* Neither the names of the IBM Corporation nor the names of its		*/
/* contributors may be used to endorse or promote products derived from		*/
/* this software without specific prior written permission.			*/
/* 										*/
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS		*/
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT		*/
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR	*/
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT		*/
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,	*/
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT		*/
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,	*/
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY	*/
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT		*/
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE	*/
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.		*/
/********************************************************************************/

#ifndef TPM_PCR_H
#define TPM_PCR_H

#include "tpm_global.h"
#include "tpm_sizedbuffer.h"
#include "tpm_store.h"

/*
  Locality Utilities
*/

TPM_RESULT TPM_Locality_Set(TPM_LOCALITY_SELECTION *tpm_locality_selection,
                               TPM_MODIFIER_INDICATOR tpm_modifier_indicator);
TPM_RESULT TPM_Locality_Check(TPM_LOCALITY_SELECTION tpm_locality_selection,
                              TPM_MODIFIER_INDICATOR localityModifier);

TPM_RESULT TPM_LocalitySelection_CheckLegal(TPM_LOCALITY_SELECTION tpm_locality_selection);
TPM_RESULT TPM_LocalityModifier_CheckLegal(TPM_MODIFIER_INDICATOR localityModifier);

void       TPM_PCRLocality_Compare(TPM_BOOL *match,
                                   TPM_LOCALITY_SELECTION tpm_locality_selection1,
                                   TPM_LOCALITY_SELECTION tpm_locality_selection2);

/*
  state PCR's
*/

TPM_RESULT TPM_PCR_CheckRange(TPM_PCRINDEX index);
void       TPM_PCR_Init(TPM_PCRVALUE *tpm_pcrs,
                        const TPM_PCR_ATTRIBUTES *tpm_pcr_attributes,
                        size_t pcrIndex);
void       TPM_PCR_Reset(TPM_PCRVALUE *tpm_pcrs,
                         TPM_BOOL TOSPresent,
                         TPM_PCRINDEX pcrIndex); 
TPM_RESULT TPM_PCR_Load(TPM_PCRVALUE dest_pcr,
                        TPM_PCRVALUE *tpm_pcrs,
                        TPM_PCRINDEX index);
TPM_RESULT TPM_PCR_Store(TPM_PCRVALUE *tpm_pcrs,
                         TPM_PCRINDEX index,
                         TPM_PCRVALUE src_pcr);

/*
  TPM_SELECT_SIZE
*/

void       TPM_SelectSize_Init(TPM_SELECT_SIZE *tpm_select_size);
TPM_RESULT TPM_SelectSize_Load(TPM_SELECT_SIZE *tpm_select_size,
                               unsigned char **stream,
                               uint32_t *stream_size);


/*
  TPM_PCR_SELECTION
*/

void       TPM_PCRSelection_Init(TPM_PCR_SELECTION *tpm_pcr_selection);
TPM_RESULT TPM_PCRSelection_Load(TPM_PCR_SELECTION *tpm_pcr_selection,
                                 unsigned char **stream,
                                 uint32_t *stream_size);
TPM_RESULT TPM_PCRSelection_Store(TPM_STORE_BUFFER *sbuffer,
                                  const TPM_PCR_SELECTION *tpm_pcr_selection);
void       TPM_PCRSelection_Delete(TPM_PCR_SELECTION *tpm_pcr_selection);
/* copy */
TPM_RESULT TPM_PCRSelection_Copy(TPM_PCR_SELECTION *destination,
                                 TPM_PCR_SELECTION *source);
/* setters */
TPM_RESULT TPM_PCRSelection_GenerateDigest(TPM_DIGEST tpm_digest,
                                           TPM_PCR_SELECTION *tpm_pcr_selection,
                                           TPM_PCRVALUE *tpm_pcrs);
TPM_RESULT TPM_PCRSelection_GenerateDigest2(TPM_DIGEST tpm_digest,
                                           TPM_PCR_COMPOSITE *tpm_pcr_composite,
                                           TPM_PCR_SELECTION *tpm_pcr_selection,
                                           TPM_PCRVALUE *tpm_pcrs);
/* getters */
TPM_RESULT TPM_PCRSelection_GetPCRUsage(TPM_BOOL *pcrUsage,
                                        const TPM_PCR_SELECTION *tpm_pcr_selection,
                                        size_t start_index);
/* checkers */
TPM_RESULT TPM_PCRSelection_CheckRange(const TPM_PCR_SELECTION *tpm_pcr_selection);
void       TPM_PCRSelection_Compare(TPM_BOOL *match,
                                    TPM_PCR_SELECTION *tpm_pcr_selection1,
                                    TPM_PCR_SELECTION *tpm_pcr_selection2);
#if 0
void TPM_PCRSelection_LessThan(TPM_BOOL *lessThan,
                               TPM_PCR_SELECTION *tpm_pcr_selection_new,
                               TPM_PCR_SELECTION *tpm_pcr_selection_old);
#endif

/* TPM_PCR_ATTRIBUTES */

void       TPM_PCRAttributes_Init(TPM_PCR_ATTRIBUTES *tpm_pcr_attributes);

void       TPM_PCRInfo_Trace(const char *message,
			     TPM_PCR_SELECTION pcrSelection,
			     TPM_COMPOSITE_HASH digestAtRelease);
/*
  PCRs - Functions that act on the entire set of PCRs
*/

void       TPM_PCRs_Init(TPM_PCRVALUE *tpm_pcrs,
			 const TPM_PCR_ATTRIBUTES *tpm_pcr_attributes);
TPM_RESULT TPM_PCRs_Load(TPM_PCRVALUE *tpm_pcrs,
                         const TPM_PCR_ATTRIBUTES *tpm_pcr_attributes,
                         unsigned char **stream,
                         uint32_t *stream_size);
TPM_RESULT TPM_PCRs_Store(TPM_STORE_BUFFER *sbuffer,
                          TPM_PCRVALUE *tpm_pcrs,
                          const TPM_PCR_ATTRIBUTES *tpm_pcr_attributes);

/*
  TPM_PCR_INFO
*/

void       TPM_PCRInfo_Init(TPM_PCR_INFO *tpm_pcr_info);
TPM_RESULT TPM_PCRInfo_Load(TPM_PCR_INFO *tpm_pcr_info,
                            unsigned char **stream,
                            uint32_t *stream_size);
TPM_RESULT TPM_PCRInfo_Store(TPM_STORE_BUFFER *sbuffer,
                             const TPM_PCR_INFO *tpm_pcr_info);
void       TPM_PCRInfo_Delete(TPM_PCR_INFO *tpm_pcr_info);
/* create */
TPM_RESULT TPM_PCRInfo_Create(TPM_PCR_INFO **tpm_pcr_info);
/* load */
TPM_RESULT TPM_PCRInfo_LoadFromBuffer(TPM_PCR_INFO *tpm_pcr_info,
                                     const TPM_SIZED_BUFFER *tpm_sized_buffer);
TPM_RESULT TPM_PCRInfo_CreateFromBuffer(TPM_PCR_INFO **tpm_pcr_info,
                                        const TPM_SIZED_BUFFER *tpm_sized_buffer);
/* copy */
TPM_RESULT TPM_PCRInfo_Copy(TPM_PCR_INFO *dest_tpm_pcr_info,
                            TPM_PCR_INFO *src_tpm_pcr_info);
TPM_RESULT TPM_PCRInfo_CopyInfoLong(TPM_PCR_INFO *dest_tpm_pcr_info,
                                    TPM_PCR_INFO_LONG *src_tpm_pcr_info_long);
TPM_RESULT TPM_PCRInfo_CreateFromInfo(TPM_PCR_INFO **dest_tpm_pcr_info,
                                      TPM_PCR_INFO *src_tpm_pcr_info);
TPM_RESULT TPM_PCRInfo_CreateFromInfoLong(TPM_PCR_INFO **dest_tpm_pcr_info,
                                          TPM_PCR_INFO_LONG *src_tpm_pcr_info_long);
TPM_RESULT TPM_PCRInfo_CreateFromKey(TPM_PCR_INFO **dest_tpm_pcr_info,
                                     TPM_KEY *tpm_key);

/* setters */
TPM_RESULT TPM_PCRInfo_GenerateDigest(TPM_DIGEST tpm_digest,
                                      TPM_PCR_INFO *tpm_pcr_info,
                                      TPM_PCRVALUE *tpm_pcrs);
TPM_RESULT TPM_PCRInfo_CheckDigest(TPM_PCR_INFO *tpm_pcr_info,
                                   TPM_PCRVALUE *tpm_pcrs);
TPM_RESULT TPM_PCRInfo_SetDigestAtCreation(TPM_PCR_INFO *tpm_pcr_info,
                                           TPM_PCRVALUE *tpm_pcrs);
/* getters */
TPM_RESULT TPM_PCRInfo_GetPCRUsage(TPM_BOOL *pcrUsage,
                                   TPM_PCR_INFO *tpm_pcr_info,
                                   size_t start_index);

/*
  TPM_PCR_INFO_LONG
*/

void       TPM_PCRInfoLong_Init(TPM_PCR_INFO_LONG *tpm_pcr_info_long);
TPM_RESULT TPM_PCRInfoLong_Load(TPM_PCR_INFO_LONG *tpm_pcr_info_long,
                                unsigned char **stream,
                                uint32_t *stream_size);
TPM_RESULT TPM_PCRInfoLong_Store(TPM_STORE_BUFFER *sbuffer,
                                 const TPM_PCR_INFO_LONG *tpm_pcr_info_long);
void       TPM_PCRInfoLong_Delete(TPM_PCR_INFO_LONG *tpm_pcr_info_long);
/* create */
TPM_RESULT TPM_PCRInfoLong_Create(TPM_PCR_INFO_LONG **tpm_pcr_info_long);
/* load */
TPM_RESULT TPM_PCRInfoLong_LoadFromBuffer(TPM_PCR_INFO_LONG *tpm_pcr_info_long,
                                          const TPM_SIZED_BUFFER *tpm_sized_buffer);
TPM_RESULT TPM_PCRInfoLong_CreateFromBuffer(TPM_PCR_INFO_LONG **tpm_pcr_info_long,
                                            const TPM_SIZED_BUFFER *tpm_sized_buffer);
/* copy */
TPM_RESULT TPM_PCRInfoLong_Copy(TPM_PCR_INFO_LONG *dest_tpm_pcr_info_long,
                                TPM_PCR_INFO_LONG *src_tpm_pcr_info_long);
TPM_RESULT TPM_PCRInfoLong_CreateFromInfoLong(TPM_PCR_INFO_LONG **dest_tpm_pcr_info_long,
                                              TPM_PCR_INFO_LONG *src_tpm_pcr_info_long);
/* setters */
TPM_RESULT TPM_PCRInfoLong_GenerateDigest(TPM_DIGEST tpm_digest,
                                          TPM_PCR_INFO_LONG *tpm_pcr_info_long,
                                          TPM_PCRVALUE *tpm_pcrs);
TPM_RESULT TPM_PCRInfoLong_CheckDigest(TPM_PCR_INFO_LONG *tpm_pcr_info_long,
                                       TPM_PCRVALUE *tpm_pcrs,
                                       TPM_MODIFIER_INDICATOR localityModifier);
TPM_RESULT TPM_PCRInfoLong_SetDigestAtCreation(TPM_PCR_INFO_LONG *tpm_pcr_info_long,
                                               TPM_PCRVALUE *tpm_pcrs);
/* getters */
TPM_RESULT TPM_PCRInfoLong_GetPCRUsage(TPM_BOOL *pcrUsage,
                                       TPM_PCR_INFO_LONG *tpm_pcr_info_long,
                                       size_t start_index);

/*
  TPM_PCR_INFO_SHORT
*/

void       TPM_PCRInfoShort_Init(TPM_PCR_INFO_SHORT *tpm_pcr_info_short);
TPM_RESULT TPM_PCRInfoShort_Load(TPM_PCR_INFO_SHORT *tpm_pcr_info_short,
                                 unsigned char **stream,
                                 uint32_t *stream_size,
				 TPM_BOOL optimize);
TPM_RESULT TPM_PCRInfoShort_Store(TPM_STORE_BUFFER *sbuffer,
                                  const TPM_PCR_INFO_SHORT *tpm_pcr_info_short,
				  TPM_BOOL optimize);
void       TPM_PCRInfoShort_Delete(TPM_PCR_INFO_SHORT *tpm_pcr_info_short);
/* create */
TPM_RESULT TPM_PCRInfoShort_Create(TPM_PCR_INFO_SHORT **tpm_pcr_info_short);
/* load */
TPM_RESULT TPM_PCRInfoShort_LoadFromBuffer(TPM_PCR_INFO_SHORT *tpm_pcr_info_short,
                                           const TPM_SIZED_BUFFER *tpm_sized_buffer);
TPM_RESULT TPM_PCRInfoShort_CreateFromBuffer(TPM_PCR_INFO_SHORT **tpm_pcr_info_short,
                                             const TPM_SIZED_BUFFER *tpm_sized_buffer);
/* copy */
TPM_RESULT TPM_PCRInfoShort_Copy(TPM_PCR_INFO_SHORT *dest_tpm_pcr_info_short,
                                 TPM_PCR_INFO_SHORT *src_tpm_pcr_info_short);
TPM_RESULT TPM_PCRInfoShort_CopyInfo(TPM_PCR_INFO_SHORT *dest_tpm_pcr_info_short,
                                     TPM_PCR_INFO *src_tpm_pcr_info);
TPM_RESULT TPM_PCRInfoShort_CopyInfoLong(TPM_PCR_INFO_SHORT *dest_tpm_pcr_info_short,
                                         TPM_PCR_INFO_LONG *src_tpm_pcr_info_long);
TPM_RESULT TPM_PCRInfoShort_CreateFromInfo(TPM_PCR_INFO_SHORT **dest_tpm_pcr_info_short,
                                           TPM_PCR_INFO *src_tpm_pcr_info);
TPM_RESULT TPM_PCRInfoShort_CreateFromInfoLong(TPM_PCR_INFO_SHORT **dest_tpm_pcr_info_short,
                                               TPM_PCR_INFO_LONG *src_tpm_pcr_info_long);
TPM_RESULT TPM_PCRInfoShort_CreateFromKey(TPM_PCR_INFO_SHORT **dest_tpm_pcr_info_short,
                                          TPM_KEY *tpm_key);

/* setters */
TPM_RESULT TPM_PCRInfoShort_GenerateDigest(TPM_DIGEST tpm_digest,
                                           TPM_PCR_INFO_SHORT *tpm_pcr_info_short,
                                           TPM_PCRVALUE *tpm_pcrs);
TPM_RESULT TPM_PCRInfoShort_CheckDigest(TPM_PCR_INFO_SHORT *tpm_pcr_info_short,
                                        TPM_PCRVALUE *tpm_pcrs,
                                        TPM_MODIFIER_INDICATOR localityModifier);

/* getters */
TPM_RESULT TPM_PCRInfoShort_GetPCRUsage(TPM_BOOL *pcrUsage,
                                        TPM_PCR_INFO_SHORT *tpm_pcr_info_short);

/*
  TPM_PCR_COMPOSITE
*/

void       TPM_PCRComposite_Init(TPM_PCR_COMPOSITE *tpm_pcr_composite);
TPM_RESULT TPM_PCRComposite_Store(TPM_STORE_BUFFER *sbuffer,
                                  const TPM_PCR_COMPOSITE *tpm_pcr_composite);
void       TPM_PCRComposite_Delete(TPM_PCR_COMPOSITE *tpm_pcr_composite);

TPM_RESULT TPM_PCRComposite_Set(TPM_PCR_COMPOSITE *tpm_pcr_composite,
                                TPM_PCR_SELECTION *tpm_pcr_selection,
                                TPM_PCRVALUE *tpm_pcrs);

/*
  TPM_QUOTE_INFO
*/

void       TPM_QuoteInfo_Init(TPM_QUOTE_INFO *tpm_quote_info);
#if 0
TPM_RESULT TPM_QuoteInfo_Load(TPM_QUOTE_INFO *tpm_quote_info,
                              unsigned char **stream,
                              uint32_t *stream_size);
#endif
TPM_RESULT TPM_QuoteInfo_Store(TPM_STORE_BUFFER *sbuffer,
                               const TPM_QUOTE_INFO *tpm_quote_info);
void       TPM_QuoteInfo_Delete(TPM_QUOTE_INFO *tpm_quote_info);

/*
  TPM_QUOTE_INFO2
*/

void       TPM_QuoteInfo2_Init(TPM_QUOTE_INFO2 *tpm_quote_info2);
#if 0
TPM_RESULT TPM_QuoteInfo2_Load(TPM_QUOTE_INFO2 *tpm_quote_info2,
                               unsigned char **stream,
                               uint32_t *stream_size);
#endif
TPM_RESULT TPM_QuoteInfo2_Store(TPM_STORE_BUFFER *sbuffer,
                                const TPM_QUOTE_INFO2 *tpm_quote_info2);
void       TPM_QuoteInfo2_Delete(TPM_QUOTE_INFO2 *tpm_quote_info2);


/*
  Common command processing
*/

TPM_RESULT TPM_ExtendCommon(TPM_PCRVALUE outDigest,
                            tpm_state_t *tpm_state,
                            TPM_COMMAND_CODE ordinal,
                            TPM_PCRINDEX pcrNum,
                            TPM_DIGEST inDigest);
/*
  Command Processing
*/

TPM_RESULT TPM_Process_PcrRead(tpm_state_t *tpm_state,
                               TPM_STORE_BUFFER *response,
                               TPM_TAG tag,
                               uint32_t paramSize,
                               TPM_COMMAND_CODE ordinal,
                               unsigned char *command,
                               TPM_TRANSPORT_INTERNAL *transportInternal);
TPM_RESULT TPM_Process_Quote(tpm_state_t *tpm_state,
                             TPM_STORE_BUFFER *response,
                             TPM_TAG tag,
                             uint32_t paramSize,
                             TPM_COMMAND_CODE ordinal,
                             unsigned char *command,
                             TPM_TRANSPORT_INTERNAL *transportInternal);
TPM_RESULT TPM_Process_Quote2(tpm_state_t *tpm_state,
                              TPM_STORE_BUFFER *response,
                              TPM_TAG tag,
                              uint32_t paramSize,
                              TPM_COMMAND_CODE ordinal,
                              unsigned char *command,
                              TPM_TRANSPORT_INTERNAL *transportInternal);

TPM_RESULT TPM_Process_Extend(tpm_state_t *tpm_state,
                              TPM_STORE_BUFFER *response,
                              TPM_TAG tag,
                              uint32_t paramSize,
                              TPM_COMMAND_CODE ordinal,
                              unsigned char *command,
                              TPM_TRANSPORT_INTERNAL *transportInternal);

TPM_RESULT TPM_Process_PcrReset(tpm_state_t *tpm_state,
                                TPM_STORE_BUFFER *response,
                                TPM_TAG tag,
                                uint32_t paramSize,
                                TPM_COMMAND_CODE ordinal,
                                unsigned char *command,
                                TPM_TRANSPORT_INTERNAL *transportInternal);
#endif