refactor(core/python): factor out `get_challenge_message()`
What changed, and why it matters
This commit is a simple code cleanup: it moves a small block of code that builds an authentication challenge message into its own reusable function. There is no change to behavior, no bug fix, and no security-related change.
No security action needed. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff extracts the construction of the signed challenge message (compact_size(CHALLENGE_HEADER) + CHALLENGE_HEADER + compact_size(challenge) + challenge) into a new helper function get_challenge_message() in python/src/trezorlib/authentication.py. The existing verify_authentication_response() function now calls this helper instead of inlining the same logic. The generated bytes are identical; no logic, constants, or cryptographic operations changed.
Changed components
python/src/trezorlib/authentication.pyInspect captured patch +12 / −6
diff --git a/python/src/trezorlib/authentication.py b/python/src/trezorlib/authentication.py
index 3ea8aae8..d5c230d9 100644
--- a/python/src/trezorlib/authentication.py
+++ b/python/src/trezorlib/authentication.py
@@ -47,6 +47,17 @@ def _pk_mldsa44(pubkey_hex: str) -> PublicKey:
CHALLENGE_HEADER = b"AuthenticateDevice:"
+
+def get_challenge_message(challenge: bytes) -> bytes:
+ """Build the message that Trezor signs in response to an AuthenticateDevice call."""
+ return (
+ compact_size(len(CHALLENGE_HEADER))
+ + CHALLENGE_HEADER
+ + compact_size(len(challenge))
+ + challenge
+ )
+
+
OID_TO_NAME = {
NameOID.COMMON_NAME: "CN",
NameOID.LOCALITY_NAME: "L",
@@ -497,12 +508,7 @@ def verify_authentication_response(
The optional argument `root_pubkey` allows you to specify a root public key either
as a `PublicKey` object or as a byte-string.
"""
- challenge_bytes = (
- compact_size(len(CHALLENGE_HEADER))
- + CHALLENGE_HEADER
- + compact_size(len(challenge))
- + challenge
- )
+ challenge_bytes = get_challenge_message(challenge)
cert_chain_iter = iter(cert_chain)
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.