-
Notifications
You must be signed in to change notification settings - Fork 45
/
pcr_log.rs
98 lines (81 loc) · 2.73 KB
/
pcr_log.rs
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
/*++
Licensed under the Apache-2.0 license.
File Name:
pcr.rs
Abstract:
PCR-related types.
--*/
use crate::PcrId;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use zeroize::Zeroize;
pub const PCR_ID_FMC_CURRENT: PcrId = PcrId::PcrId0;
pub const PCR_ID_FMC_JOURNEY: PcrId = PcrId::PcrId1;
pub const PCR_ID_STASH_MEASUREMENT: PcrId = PcrId::PcrId31;
// PcrLogEntryId is used to identify the PCR entry and
// the size of the data in PcrLogEntry::pcr_data.
#[repr(u16)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PcrLogEntryId {
Invalid = 0,
DeviceStatus = 1, // data size = 9 bytes
VendorPubKeyHash = 2, // data size = 48 bytes
OwnerPubKeyHash = 3, // data size = 48 bytes
FmcTci = 4, // data size = 48 bytes
StashMeasurement = 5, // data size = 48 bytes
RtTci = 6, // data size = 48 bytes
FwImageManifest = 7, // data size = 48 bytes
}
impl From<u16> for PcrLogEntryId {
/// Converts to this type from the input type.
fn from(id: u16) -> PcrLogEntryId {
match id {
1 => PcrLogEntryId::DeviceStatus,
2 => PcrLogEntryId::VendorPubKeyHash,
3 => PcrLogEntryId::OwnerPubKeyHash,
4 => PcrLogEntryId::FmcTci,
5 => PcrLogEntryId::StashMeasurement,
6 => PcrLogEntryId::RtTci,
7 => PcrLogEntryId::FwImageManifest,
_ => PcrLogEntryId::Invalid,
}
}
}
/// PCR log entry
#[repr(C)]
#[derive(IntoBytes, Clone, Copy, Debug, Default, FromBytes, Immutable, KnownLayout, Zeroize)]
pub struct PcrLogEntry {
/// Entry identifier
pub id: u16,
pub reserved0: [u8; 2],
/// Bitmask indicating the PCRs to which the data is being extended to.
pub pcr_ids: u32,
// PCR data
pub pcr_data: [u32; 12],
}
impl PcrLogEntry {
pub fn measured_data(&self) -> &[u8] {
let data_len = match PcrLogEntryId::from(self.id) {
PcrLogEntryId::Invalid => 0,
PcrLogEntryId::DeviceStatus => 9,
PcrLogEntryId::VendorPubKeyHash => 48,
PcrLogEntryId::OwnerPubKeyHash => 48,
PcrLogEntryId::FmcTci => 48,
PcrLogEntryId::StashMeasurement => 48,
PcrLogEntryId::RtTci => 48,
PcrLogEntryId::FwImageManifest => 48,
};
&self.pcr_data.as_bytes()[..data_len]
}
}
/// Measurement log entry
#[repr(C)]
#[derive(IntoBytes, Clone, Copy, Debug, Default, FromBytes, Immutable, KnownLayout, Zeroize)]
pub struct MeasurementLogEntry {
pub pcr_entry: PcrLogEntry,
pub metadata: [u8; 4],
pub context: [u32; 12],
pub svn: u32,
pub reserved0: [u8; 4],
}
pub const RT_FW_CURRENT_PCR: PcrId = PcrId::PcrId2;
pub const RT_FW_JOURNEY_PCR: PcrId = PcrId::PcrId3;