changes to the apis to accommodate the public key record format

This commit is contained in:
bunnie 2025-10-06 15:20:34 +08:00
parent fae47d2dac
commit 03ea3c9d0c
3 changed files with 13 additions and 17 deletions

View file

@ -16,6 +16,7 @@ pub mod offsets;
pub mod sce;
pub mod signatures;
pub use offsets::*;
pub mod pubkeys;
/// UF2 Family ID. Randomly generated, no collisions with the known list, still to be merged
/// into the "official" list

View file

@ -9,19 +9,6 @@ pub const UNSIGNED_LEN: usize = size_of::<u32>() + SIGNATURE_LENGTH;
pub const SIGNATURE_LENGTH: usize = 64; // length of an ed25519 signature.
pub const PUBLIC_KEY_LENGTH: usize = 32; // length of an ed25519 public key.
/// Nominal purposes of pub key slots:
/// - slot 0 is Baochip secured signing key 1
/// - slot 1 is Baochip secured signing key 2
/// - slot 2 is a Beta signing key. It's kept in a secured token but also available in a development
/// environment.
/// - slot 3 is the Developer signing key. It's a well-known key that anyone can use to sign an image. If
/// revoked, it is not a valid signing key. When not revoked, upon being presented with an image signed by
/// this, the bootloader will automatically erase all device-local secrets.
///
/// The dual signing keys for Baochip allows for a laddered upgrade path in case a signing key
/// needs to be replaced, upgraded, or cycled out for any reason.
pub const KEYSLOT_INITIAL_TAGS: [&'static [u8; 4]; 4] = [b"bao1", b"bao2", b"beta", b"dev "];
/// These are notional and subject to change
#[repr(u32)]
#[derive(PartialEq, Eq, Clone, Copy)]
@ -94,7 +81,7 @@ impl Default for SignatureInFlash {
#[derive(Copy, Clone)]
pub struct Pubkey {
pub pk: [u8; PUBLIC_KEY_LENGTH],
pub tag: u32,
pub tag: [u8; 4],
/// `aad_len` also specifies the signing protocol. If it is `0`, then a pure `ed25519ph`
/// signature is assumed. If it is greater than `0`, then it's assumed to be a
/// FIDO2/WebAuthn signature format using ed25519, where the signature is computed as:
@ -108,7 +95,15 @@ pub struct Pubkey {
unsafe impl Zeroable for Pubkey {}
unsafe impl Pod for Pubkey {}
impl Default for Pubkey {
fn default() -> Self { Self { pk: [0u8; PUBLIC_KEY_LENGTH], tag: 0, aad_len: 0, aad: [0u8; 59] } }
fn default() -> Self { Self { pk: [0u8; PUBLIC_KEY_LENGTH], tag: [0u8; 4], aad_len: 0, aad: [0u8; 59] } }
}
impl Pubkey {
pub fn populate_from(&mut self, record: &Pubkey) {
self.pk.copy_from_slice(&record.pk);
self.tag.copy_from_slice(&record.tag);
self.aad_len = record.aad_len;
self.aad.copy_from_slice(&record.aad);
}
}
#[repr(C)]

View file

@ -43,7 +43,7 @@ pub fn validate_image(
function_codes: &[u32],
auto_jump: bool,
mut spim: Option<&mut Spim>,
) -> Result<(usize, u32), String> {
) -> Result<(usize, [u8; 4]), String> {
// Copy the signature into a structure so we can unpack it.
let mut sig = SignatureInFlash::default();
if let Some(ref mut spim) = spim {
@ -82,7 +82,7 @@ pub fn validate_image(
let mut secure = false;
let mut passing_key: Option<usize> = None;
for (i, key) in pk_src.sealed_data.pubkeys.iter().enumerate() {
if key.tag == 0 {
if key.tag == [0u8; 4] {
continue;
}
let revocation_value = one_way_counters.get(revocation_offset + i).expect("internal error");