| 227 | } |
| 228 | |
| 229 | fn compute_mrtd(&self, variant: PageAddOrder) -> Result<Vec<u8>> { |
| 230 | let mut h = Sha384::new(); |
| 231 | |
| 232 | let mem_page_add = |h: &mut Sha384, s: &TdvfSection, page: u64| { |
| 233 | if s.attributes & ATTRIBUTE_PAGE_AUG == 0 { |
| 234 | let mut buf = [0u8; 128]; |
| 235 | buf[..12].copy_from_slice(b"MEM.PAGE.ADD"); |
| 236 | let gpa = s.memory_address + page * PAGE_SIZE; |
| 237 | buf[16..24].copy_from_slice(&gpa.to_le_bytes()); |
| 238 | h.update(buf); |
| 239 | } |
| 240 | }; |
| 241 | |
| 242 | let mr_extend = |h: &mut Sha384, s: &TdvfSection, page: u64| { |
| 243 | if s.attributes & ATTRIBUTE_MR_EXTEND != 0 { |
| 244 | for i in 0..(PAGE_SIZE as usize / MR_EXTEND_GRANULARITY) { |
| 245 | let mut buf = [0u8; 128]; |
| 246 | buf[..9].copy_from_slice(b"MR.EXTEND"); |
| 247 | let gpa = |
| 248 | s.memory_address + page * PAGE_SIZE + (i * MR_EXTEND_GRANULARITY) as u64; |
| 249 | buf[16..24].copy_from_slice(&gpa.to_le_bytes()); |
| 250 | h.update(buf); |
| 251 | |
| 252 | let chunk_offset = s.data_offset as usize |
| 253 | + (page * PAGE_SIZE) as usize |
| 254 | + i * MR_EXTEND_GRANULARITY; |
| 255 | h.update(&self.fw[chunk_offset..chunk_offset + MR_EXTEND_GRANULARITY]); |
| 256 | } |
| 257 | } |
| 258 | }; |
| 259 | |
| 260 | for s in &self.sections { |
| 261 | let num_pages = s.memory_data_size / PAGE_SIZE; |
| 262 | match variant { |
| 263 | PageAddOrder::TwoPass => { |
| 264 | for page in 0..num_pages { |
| 265 | mem_page_add(&mut h, s, page); |
| 266 | } |
| 267 | for page in 0..num_pages { |
| 268 | mr_extend(&mut h, s, page); |
| 269 | } |
| 270 | } |
| 271 | PageAddOrder::SinglePass => { |
| 272 | for page in 0..num_pages { |
| 273 | mem_page_add(&mut h, s, page); |
| 274 | mr_extend(&mut h, s, page); |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | Ok(h.finalize().to_vec()) |
| 280 | } |
| 281 | |
| 282 | pub fn mrtd(&self, machine: &Machine) -> Result<Vec<u8>> { |
| 283 | let opts = machine |