1
0

Fix ledger sign message (#7004)

there was an around ~1/128 chance of creating an invalid signature when signing a message with a ledger
This commit is contained in:
Gordan Nekić
2021-02-06 06:16:52 +01:00
committed by GitHub
parent 2bffc9d3eb
commit 9c4807644b

View File

@@ -334,7 +334,12 @@ class Ledger_KeyStore(Hardware_KeyStore):
if sLength == 33:
s = s[1:]
# And convert it
return bytes([27 + 4 + (signature[0] & 0x01)]) + r + s
# Pad r and s points with 0x00 bytes when the point is small to get valid signature.
r_padded = bytes([0x00]) * (32 - len(r)) + r
s_padded = bytes([0x00]) * (32 - len(s)) + s
return bytes([27 + 4 + (signature[0] & 0x01)]) + r_padded + s_padded
@runs_in_hwd_thread
@test_pin_unlocked