(mut reader: R)
| 75 | } |
| 76 | |
| 77 | fn sha256_reader<R: Read>(mut reader: R) -> Result<[u8; 32]> { |
| 78 | let mut hasher = Sha256::new(); |
| 79 | let mut chunk = [0u8; 8192]; |
| 80 | loop { |
| 81 | let bytes_read = reader |
| 82 | .read(&mut chunk) |
| 83 | .map_err(|e| Self::measured_boot_io(&e))?; |
| 84 | if bytes_read == 0 { |
| 85 | break; |
| 86 | } |
| 87 | hasher.update(&chunk[..bytes_read]); |
| 88 | } |
| 89 | |
| 90 | Ok(hasher.finalize().into()) |
| 91 | } |
| 92 | |
| 93 | pub fn build_hash_block(&self) -> Result<[u8; SEV_HASH_BLOCK_SIZE]> { |
| 94 | // Current tooling appends a NUL byte at the end of cmdlines: |