refactor(python): add `signature_unsafe_expanded` into `_ed25519`
What changed, and why it matters
This commit adds a new helper function for creating Ed25519 digital signatures when the secret key has already been expanded into its internal components. It is explicitly marked as unsafe and for testing only, and it does not change any existing security behavior. The change appears to be a code refactor to support a specific key-storage format used by another project (Tropic).
No immediate action required. Treat as a low-risk refactor. If this function is later used in production code paths, it should be reviewed for constant-time behavior, input validation, and whether skipping seed expansion is appropriate for the threat model.
Security signals we found
New unsafe/test-only cryptographic helper added
Function name and docstring explicitly warn against use with secret keys or secret data
No input validation or side-channel protections present (consistent with existing unsafe functions in the same module)
No changelog entry, consistent with internal refactor
Evidence from the diff
The patch introduces signature_unsafe_expanded() in python/src/trezorlib/_ed25519.py. It mirrors the existing signature_unsafe() function but skips the SHA-512 seed expansion step, accepting the pre-expanded scalar and prefix directly. The implementation follows the standard Ed25519 signing equation: R = rB, S = (r + H(R||pk||m)a) mod l. The function is documented as unsafe, not for use with secret material, and for testing only. No existing callers are modified, and no changelog entry is recorded.
Changed components
python/src/trezorlib/_ed25519.pyInspect captured patch +18 / −0
### python/src/trezorlib/_ed25519.py
@@ -256,6 +256,24 @@ def signature_unsafe(m: bytes, sk: bytes, pk: bytes) -> bytes:
return encodepoint(R) + encodeint(S)
+def signature_unsafe_expanded(m: bytes, scalar: bytes, prefix: bytes) -> bytes:
+ """
+ Signature with an expanded secret key (scalar + prefix), which is how
+ e.g. Tropic stores Ed25519 keys. Skips the seed expansion step of
+ `signature_unsafe`, the rest of the algorithm is identical.
+
+ Not safe to use with secret keys or secret data.
+
+ See module docstring. This function should be used for testing only.
+ """
+ a = decodeint(scalar)
+ pk = encodepoint(scalarmult_B(a))
+ r = Hint(prefix + m)
+ R = scalarmult_B(r)
+ S = (r + Hint(encodepoint(R) + pk + m) * a) % l
+ return encodepoint(R) + encodeint(S)
+
+
def isoncurve(P: Point) -> bool:
x, y, z, t = P
return (Why this scored 18/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.