refactor(core): improve checksum handling in THP [no changelog]
What changed, and why it matters
This commit is a straightforward code cleanup in the Trezor firmware's THP (Trezor Host Protocol) layer. It renames a function and changes how CRC checksums are computed, but does not appear to fix or introduce a security vulnerability. The behavior remains functionally equivalent: invalid checksums are still rejected, and valid payloads are still accepted.
No security action required. Treat as normal code-quality refactor during review.
Security signals we found
No security-relevant keywords in commit title or message
No change to validation outcome: invalid checksums still return False/None equivalent
No change to checksum algorithm or length
No added bounds checks, error handling, or cryptographic changes
Commit explicitly marked as refactor and '[no changelog]'
Evidence from the diff
The patch refactors checksum handling in core/src/trezor/wire/thp/channel.py and core/src/trezor/wire/thp/interface_context.py. In channel.py, verify_checksum() is renamed to is_checksum_valid() and its return type changes from memoryview | None to bool, making the caller’s intent clearer without altering logic. In interface_context.py, the direct use of crc.crc32() from trezorcrypto is replaced with a call to a higher-level checksum.compute() helper. The commit message labels this as a refactor with no changelog, and there is no evidence of a security fix or behavior change that would affect integrity, confidentiality, or availability.
Changed components
core/src/trezor/wire/thp/channel.pycore/src/trezor/wire/thp/interface_context.pyInspect captured patch +8 / −8
diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py
index 1f95065ba..d524a9830 100644
--- a/core/src/trezor/wire/thp/channel.py
+++ b/core/src/trezor/wire/thp/channel.py
@@ -115,7 +115,7 @@ class Reassembler:
if self.bytes_read > self.buffer_len:
raise ThpError("read more bytes than expected")
- if not verify_checksum(buffer):
+ if not is_checksum_valid(buffer):
return False
assert self.message is None
@@ -128,16 +128,16 @@ class Reassembler:
self.bytes_read += utils.memcpy(payload_buffer, self.bytes_read, packet, offset)
-def verify_checksum(buffer: memoryview) -> memoryview | None:
+def is_checksum_valid(buffer: memoryview) -> bool:
"""
- Return the buffer if the checksum is valid, otherwise return `None`.
+ Returns `True` if the checksum is valid, otherwise returns `False`.
"""
if is_valid(buffer[-CHECKSUM_LENGTH:], buffer[:-CHECKSUM_LENGTH]):
- return buffer
+ return True
# ignore invalid payloads
if __debug__:
log.warning("Invalid payload checksum: %s", utils.hexlify_if_bytes(buffer))
- return None
+ return False
class ChannelPreemptedException(UnexpectedMessageException):
diff --git a/core/src/trezor/wire/thp/interface_context.py b/core/src/trezor/wire/thp/interface_context.py
index a8cdf682c..b9d9816f5 100644
--- a/core/src/trezor/wire/thp/interface_context.py
+++ b/core/src/trezor/wire/thp/interface_context.py
@@ -1,6 +1,5 @@
import ustruct
from micropython import const
-from trezorcrypto import crc
from typing import TYPE_CHECKING
from storage.cache_thp import (
@@ -132,8 +131,9 @@ class InterfaceContext:
return channel
def write_payload(self, header: PacketHeader, payload: bytes) -> Awaitable[None]:
- checksum = crc.crc32(payload, crc.crc32(header.to_bytes()))
- checksum_bytes = checksum.to_bytes(CHECKSUM_LENGTH, "big")
+ checksum_bytes = checksum.compute(
+ payload, checksum.compute_int(header.to_bytes())
+ )
return self._write_payload_chunks(header, payload, checksum_bytes)
def _write_payload_chunks(
Why this scored 12/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.