[rom_ext] Incorrect unit test silicon_creator for manifest
- Dominant language
- SystemVerilog
- Stars
- 3.6k
- Forks
- 1.1k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 141
Description
### Description
I was searching the codebase to see which portion of the image is used for the digest that is signed, and I ran across [code][0] that seems incorrect. It seems like the code must not be used. It should be removed or refactored as to not cause confusion in the future, or worse start being used when it is incorrect.
```c
/**
* Gets the region of the image that should be included in the digest
* computation.
*
* Digest region of an image starts immediately after the `usage_constraints`
* field of its manifest and ends at the end of the image.
*
* @param manifest A manifest.
* return digest_region Region of the image that should be included in the
* digest computation.
*/
OT_WARN_UNUSED_RESULT
inline manifest_digest_region_t manifest_digest_region_get(
const manifest_t *manifest) {
enum {
kDigestRegionOffset = offsetof(manifest_t, usage_constraints) +
sizeof(manifest->usage_constraints),
};
return (manifest_digest_region_t){
.start = (const char *)manifest + kDigestRegionOffset,
.length = manifest->signed_region_end - kDigestRegionOffset,
};
}
```
Specifically the digest start should start at the **beginning** of the usage_constraint field not right after it as the usage_constraint should be part of the digest. Opentitantool correctly implements the digest range to [include][1] the usage_constraint field.
```rust
/// Operates on the signed region of the image.
pub fn map_signed_region(&self, f: F) -> Result
where
F: FnOnce(&[u8]) -> R,
{
Ok(f(&self.data.bytes[offset_of!(Manifest, usage_constraints)
..self.borrow_manifest()?.signed_region_end as usize]))
}
```
[0]:https://github.com/lowRISC/opentitan/blob/master/sw/device/silicon_creator/lib/manifest_unittest.cc#L33
[1]:https://github.com/lowRISC/opentitan/blob/master/sw/host/opentitanlib/src/image/image.rs#L579-L580
Contributor guide
Assessment
This issue has not been assessed yet.