Skip to content

Commit

Permalink
avb: Bump hashtree and FEC size limits to accommodate 8 GiB images
Browse files Browse the repository at this point in the history
Fixes: #291

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed May 24, 2024
1 parent d47c14a commit ae1050b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
29 changes: 23 additions & 6 deletions avbroot/src/format/avb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,29 @@ pub const FOOTER_MAGIC: [u8; 4] = *b"AVBf";
pub const HEADER_MAX_SIZE: u64 = 64 * 1024;

/// Maximum hash tree size. The current limit equals the hash tree size for a
/// 4GiB image using SHA512 digests and a block size of 4096.
pub const HASH_TREE_MAX_SIZE: u64 = 68_177_920;

/// Maximum FEC data size. The current limit equals the FEC data size for a 4GiB
/// image using 2 parity bytes per codeword.
pub const FEC_DATA_MAX_SIZE: u64 = 33_959_936;
/// 8GiB image using SHA256 digests and a block size of 4096. This is equal to:
///
/// ```rust
/// use avbroot::format::hashtree::HashTree;
/// let size = HashTree::new(4096, &ring::digest::SHA256, b"")
/// .compute_level_offsets(8 * 1024 * 1024 * 1024)
/// .unwrap()
/// .first()
/// .map(|r| r.end)
/// .unwrap_or(0);
/// ```
pub const HASH_TREE_MAX_SIZE: u64 = 67_637_248;

/// Maximum FEC data size. The current limit equals the FEC data size for a 8GiB
/// image using 2 parity bytes per codeword. This is equal to:
///
/// ```rust
/// use avbroot::format::fec::Fec;
/// let size = Fec::new(8 * 1024 * 1024 * 1024, 4096, 2)
/// .unwrap()
/// .fec_size();
/// ```
pub const FEC_DATA_MAX_SIZE: u64 = 67_911_680;

#[derive(Debug, Error)]
pub enum Error {
Expand Down
2 changes: 1 addition & 1 deletion avbroot/src/format/fec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Fec {

/// Get the size of the FEC data needed to cover the entire file.
#[inline]
fn fec_size(&self) -> usize {
pub fn fec_size(&self) -> usize {
usize::from(self.parity()) * self.rounds as usize * self.block_size as usize
}

Expand Down
2 changes: 1 addition & 1 deletion avbroot/src/format/hashtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl HashTree {
/// tree data. The items are returned with the bottom level's offsets first
/// in the list. Note that the bottom level is stored at the end of the hash
/// tree data.
fn compute_level_offsets(&self, image_size: u64) -> Result<Vec<Range<usize>>> {
pub fn compute_level_offsets(&self, image_size: u64) -> Result<Vec<Range<usize>>> {
let algorithm = self.salted_context.algorithm();
let digest_size = algorithm.output_len().next_power_of_two();
let mut ranges = vec![];
Expand Down

0 comments on commit ae1050b

Please sign in to comment.