@@ -157,6 +157,63 @@ fn test_tcg_v1(bt: &BootServices) {
157
157
assert_eq ! ( event_last, event) ;
158
158
}
159
159
160
+ /// Get the SHA-1 digest stored in the given PCR index.
161
+ fn tcg_v2_read_pcr_8 ( tcg : & mut v2:: Tcg ) -> v1:: Sha1Digest {
162
+ // Input command block.
163
+ #[ rustfmt:: skip]
164
+ let input = [
165
+ // tag: TPM_ST_NO_SESSIONS
166
+ 0x80 , 0x01 ,
167
+ // commandSize
168
+ 0x00 , 0x00 , 0x00 , 0x14 ,
169
+ // commandCode: TPM_CC_PCR_Read
170
+ 0x00 , 0x00 , 0x01 , 0x7e ,
171
+
172
+ // pcrSelectionIn.count: 1
173
+ 0x00 , 0x00 , 0x00 , 0x01 ,
174
+ // pcrSelectionIn.pcrSelections[0].hash: SHA-1
175
+ 0x00 , 0x04 ,
176
+ // pcrSelectionIn.pcrSelections[0].sizeofSelect: 3 bytes
177
+ 0x03 ,
178
+ // pcrSelectionIn.pcrSelections[0].pcrSelect: bitmask array
179
+ // PCR 0-7: don't select
180
+ 0x00 ,
181
+ // PCR 8-15: select only PCR 8
182
+ 0x01 ,
183
+ // PCR 16-23: don't select
184
+ 0x00 ,
185
+ ] ;
186
+
187
+ let mut output = [ 0 ; 50 ] ;
188
+ tcg. submit_command ( & input, & mut output)
189
+ . expect ( "failed to get PCR value" ) ;
190
+
191
+ // tag: TPM_ST_NO_SESSIONS
192
+ assert_eq ! ( output[ 0 ..2 ] , [ 0x80 , 0x01 ] ) ;
193
+ // responseSize
194
+ assert_eq ! ( output[ 2 ..6 ] , [ 0x00 , 0x00 , 0x00 , 0x32 ] ) ;
195
+ // responseCode: TPM_RC_SUCCESS
196
+ assert_eq ! ( output[ 6 ..10 ] , [ 0x00 , 0x00 , 0x00 , 0x00 ] ) ;
197
+ // Bytes 10..14 are the TPM update counter, ignore.
198
+
199
+ // pcrSelectionIn.count: 1
200
+ assert_eq ! ( output[ 14 ..18 ] , [ 0x00 , 0x00 , 0x00 , 0x01 ] ) ;
201
+ // pcrSelectionIn.pcrSelections[0].hash: SHA-1
202
+ assert_eq ! ( output[ 18 ..20 ] , [ 0x00 , 0x04 ] ) ;
203
+ // pcrSelectionIn.pcrSelections[0].sizeofSelect: 3 bytes
204
+ assert_eq ! ( output[ 20 ] , 0x03 ) ;
205
+ // pcrSelectionIn.pcrSelections[0].pcrSelect: bitmap selecting PCR 8
206
+ assert_eq ! ( output[ 21 ..24 ] , [ 0x00 , 0x01 , 0x00 ] ) ;
207
+
208
+ // pcrValues.count: 1
209
+ assert_eq ! ( output[ 24 ..28 ] , [ 0x00 , 0x00 , 0x00 , 0x01 ] ) ;
210
+ // pcrValues.digests[0].size: 20 bytes
211
+ assert_eq ! ( output[ 28 ..30 ] , [ 0x00 , 0x14 ] ) ;
212
+
213
+ // The rest of the output is the SHA-1 digest.
214
+ output[ 30 ..] . try_into ( ) . unwrap ( )
215
+ }
216
+
160
217
pub fn test_tcg_v2 ( bt : & BootServices ) {
161
218
info ! ( "Running TCG v2 test" ) ;
162
219
@@ -216,6 +273,9 @@ pub fn test_tcg_v2(bt: &BootServices) {
216
273
. get_result_of_set_active_pcr_banks( )
217
274
. expect( "get_result_of_set_active_pcr_banks failed" )
218
275
. is_none( ) ) ;
276
+
277
+ // PCR 8 is initially zero.
278
+ assert_eq ! ( tcg_v2_read_pcr_8( & mut tcg) , [ 0 ; 20 ] ) ;
219
279
}
220
280
221
281
pub fn test ( bt : & BootServices ) {
0 commit comments