@@ -43,13 +43,12 @@ static char in_filename[PATH_MAX] = "", out_filename[PATH_MAX] = "";
43
43
static TSS_HPCRS hPcrs = NULL_HPCRS ;
44
44
static TSS_HCONTEXT hContext ;
45
45
static TSS_HTPM hTpm ;
46
+ static UINT32 selectedPcrs [24 ];
47
+ static UINT32 selectedPcrsLen = 0 ;
46
48
47
49
static int parse (const int aOpt , const char * aArg )
48
50
{
49
51
int rc = -1 ;
50
- UINT32 pcr_idx ;
51
- BYTE * pcr_idx_val ;
52
- UINT32 pcr_siz ;
53
52
54
53
switch (aOpt ) {
55
54
case 'i' :
@@ -66,25 +65,7 @@ static int parse(const int aOpt, const char *aArg)
66
65
break ;
67
66
case 'p' :
68
67
if (aArg ) {
69
- if (hPcrs == NULL_HPCRS ) {
70
- if (Tspi_Context_CreateObject (hContext ,
71
- TSS_OBJECT_TYPE_PCRS ,
72
- 0 ,
73
- & hPcrs ) !=
74
- TSS_SUCCESS )
75
- break ;
76
- }
77
- pcr_idx = atoi (aArg );
78
- if (Tspi_TPM_PcrRead (hTpm , pcr_idx , & pcr_siz ,
79
- & pcr_idx_val ) != TSS_SUCCESS )
80
- break ;
81
-
82
- if (Tspi_PcrComposite_SetPcrValue (hPcrs , pcr_idx ,
83
- pcr_siz ,
84
- pcr_idx_val )
85
- != TSS_SUCCESS )
86
- break ;
87
-
68
+ selectedPcrs [selectedPcrsLen ++ ] = atoi (aArg );
88
69
rc = 0 ;
89
70
}
90
71
break ;
@@ -109,7 +90,7 @@ int main(int argc, char **argv)
109
90
int lineLen ;
110
91
unsigned char encData [sizeof (line ) + EVP_CIPHER_block_size (EVP_aes_256_cbc ())];
111
92
int encDataLen ;
112
- UINT32 encLen ;
93
+ UINT32 encLen , i ;
113
94
BYTE * encKey ;
114
95
BYTE * randKey = NULL ;
115
96
UINT32 sealKeyLen ;
@@ -152,6 +133,50 @@ int main(int argc, char **argv)
152
133
goto out_close ;
153
134
}
154
135
136
+ /* Create the PCRs object. If any PCRs above 15 are selected, this will need to be
137
+ * a 1.2 TSS/TPM */
138
+ if (selectedPcrsLen ) {
139
+ TSS_FLAG initFlag = 0 ;
140
+ UINT32 pcrSize ;
141
+ BYTE * pcrValue ;
142
+
143
+ for (i = 0 ; i < selectedPcrsLen ; i ++ ) {
144
+ if (selectedPcrs [i ] > 15 ) {
145
+ #ifdef TSS_LIB_IS_12
146
+ initFlag |= TSS_PCRS_STRUCT_INFO_LONG ;
147
+ #else
148
+ logError (_ ("This version of %s was compiled for a v1.1 TSS, which "
149
+ "can only seal\n data to PCRs 0-15. PCR %u is out of range"
150
+ "\n" ), argv [0 ], selectedPcrs [i ]);
151
+ goto out_close ;
152
+ #endif
153
+ }
154
+ }
155
+
156
+ if (contextCreateObject (hContext , TSS_OBJECT_TYPE_PCRS , initFlag ,
157
+ & hPcrs ) != TSS_SUCCESS )
158
+ goto out_close ;
159
+
160
+ for (i = 0 ; i < selectedPcrsLen ; i ++ ) {
161
+ if (tpmPcrRead (hTpm , selectedPcrs [i ], & pcrSize , & pcrValue ) != TSS_SUCCESS )
162
+ goto out_close ;
163
+
164
+ if (pcrcompositeSetPcrValue (hPcrs , selectedPcrs [i ], pcrSize , pcrValue )
165
+ != TSS_SUCCESS )
166
+ goto out_close ;
167
+ }
168
+ #ifdef TSS_LIB_IS_12
169
+ if (initFlag ) {
170
+ UINT32 localityValue =
171
+ TPM_LOC_ZERO | TPM_LOC_ONE | TPM_LOC_TWO | TPM_LOC_THREE |
172
+ TPM_LOC_FOUR ;
173
+
174
+ if (pcrcompositeSetPcrLocality (hPcrs , localityValue ) != TSS_SUCCESS )
175
+ goto out_close ;
176
+ }
177
+ #endif
178
+ }
179
+
155
180
/* Retrieve random data to be used as the symmetric key
156
181
(this key will encrypt the input file contents) */
157
182
if (tpmGetRandom (hTpm , EVP_CIPHER_key_length (EVP_aes_256_cbc ()),
0 commit comments