chore(python): minor adjustments to trezorlib/firmware
What changed, and why it matters
This is a routine Python code change in Trezor's firmware handling library. It adds support for a new Nordic (NRF) firmware header type and helper methods to insert cryptographic signatures into firmware image structures, plus a minor formatting tweak. There is no indication of a security vulnerability or fix.
No security action required. Treat as normal development/maintenance code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds a new HeaderType.NRF_FIRMWARE value (magic bytes 0x3DB8F396) to the firmware header enum and two new methods on BootableImage: insert_sigmask and insert_signatures. These methods allow setting the signature bitmask and inserting SLH-DSA (7856-byte) and ECDSA (64-byte) signatures into a specified key slot, with basic length and bounds validation. A blank line is also added to a Protocol class in util.py. The change is additive and does not modify existing security-critical parsing or validation logic.
Changed components
python/src/trezorlib/firmware/core.pypython/src/trezorlib/firmware/util.pyInspect captured patch +22 / −0
diff --git a/python/src/trezorlib/firmware/core.py b/python/src/trezorlib/firmware/core.py
index 732bb27d..81125f8c 100644
--- a/python/src/trezorlib/firmware/core.py
+++ b/python/src/trezorlib/firmware/core.py
@@ -44,6 +44,7 @@ class HeaderType(Enum):
FIRMWARE = b"TRZF"
BOOTLOADER = b"TRZB"
BOOTLOADER_V2 = b"TRZQ"
+ NRF_FIRMWARE = bytes.fromhex("3DB8F396")
class FirmwareHeader(Struct):
@@ -349,6 +350,26 @@ class BootableImage(Struct):
return self.header.hw_model
return None
+ def insert_sigmask(self, sigmask: int) -> None:
+ self.header.sigmask = sigmask
+
+ def insert_signatures(
+ self, slh_signature: bytes, ec_signature: bytes, slot_idx: int
+ ) -> None:
+ if not (
+ 0 <= slot_idx < len(self.unauth.slh_signatures)
+ and 0 <= slot_idx < len(self.unauth.ec_signatures)
+ ):
+ raise ValueError("Invalid pubkey-pair slot_idx")
+ if len(slh_signature) != 7856:
+ raise ValueError(
+ f"slh_signature must be 7856 bytes, got {len(slh_signature)}"
+ )
+ if len(ec_signature) != 64:
+ raise ValueError(f"ec_signature must be 64 bytes, got {len(ec_signature)}")
+ self.unauth.slh_signatures[slot_idx] = slh_signature
+ self.unauth.ec_signatures[slot_idx] = ec_signature
+
def public_pq_keys(self, dev_keys: bool = False) -> t.Sequence[bytes]:
if dev_keys:
return models.ROOT_SLH_DSA_KEYS_DEV_PUBLIC
diff --git a/python/src/trezorlib/firmware/util.py b/python/src/trezorlib/firmware/util.py
index 0aedeefc..24ba6bdf 100644
--- a/python/src/trezorlib/firmware/util.py
+++ b/python/src/trezorlib/firmware/util.py
@@ -35,6 +35,7 @@ class Unsigned(FirmwareIntegrityError):
class DigestCalculator(Protocol):
+
def update(self, __data: bytes) -> None: ...
def digest(self) -> bytes: ...
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.