Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fwidgen: allow caller to select the FWID digest, add support for sha256, add IANA string id to output #46

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fwidgen: Add sha256 support, allow the caller to select the FWID digest.
flihp committed Mar 20, 2025
commit 863c6d9be3dc7ff0631fbe326d45fbe63349430b
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion fwidgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,5 +8,6 @@ anyhow.version = "1"
clap = { version = "4.5.32", features = ["derive", "env", "wrap_help"] }
hex = "0.4.3"
hubtools.workspace = true
sha3 = { version = "0.10.8", default-features = false }
sha2 = "0.10.8"
sha3 = "0.10.8"
toml = { version = "0.7.8", default-features = false, features = ["parse"] }
33 changes: 29 additions & 4 deletions fwidgen/src/main.rs
Original file line number Diff line number Diff line change
@@ -3,9 +3,10 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use anyhow::{anyhow, Context, Result};
use clap::Parser;
use clap::{Parser, ValueEnum};
use hubtools::RawHubrisArchive;
use sha3::{Digest, Sha3_256};
use sha2::{digest::DynDigest, Digest as _, Sha256};
use sha3::Sha3_256;
use std::{ops::Range, str};

pub const LPC55_FLASH_PAGE_SIZE: usize = 512;
@@ -22,11 +23,35 @@ pub const LPC55_FLASH_PAGE_SIZE: usize = 512;
/// of hubris archives
#[derive(Parser, Debug)]
struct Args {
/// Hash algorithm used to generate FWID
#[clap(default_value_t, env = "HUBEDIT_DIGEST", long, value_enum)]
digest: Digest,

/// Hubris archive
#[clap(env = "HUBEDIT_ARCHIVE")]
archive: String,
}

// We provide names explicitly for each variant to map each to the IANA named
// information hash algorithm registry hash name strings.
#[derive(Clone, Debug, Default, ValueEnum)]
enum Digest {
#[clap(name = "sha-256")]
Sha256,
#[clap(name = "sha3-256")]
#[default]
Sha3_256,
}

impl Digest {
fn to_dyn_digest(&self) -> Box<dyn DynDigest> {
match self {
Digest::Sha256 => Box::new(Sha256::new()),
Digest::Sha3_256 => Box::new(Sha3_256::new()),
}
}
}

#[derive(Debug)]
enum Chip {
Lpc55,
@@ -172,9 +197,9 @@ fn main() -> Result<()> {
}
};

let mut digest = Sha3_256::new();
let mut digest = args.digest.to_dyn_digest();
digest.update(&image);
digest.update(vec![0xff; pad]);
digest.update(vec![0xff; pad].as_ref());

let digest = digest.finalize();