electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 9c4807644bf8bb0d2b777e9d02573e9b94db7c0f
parent 2bffc9d3eb3866e6e3fce59be0986e3024f6566d
Author: Gordan Nekić <48327736+gnekich@users.noreply.github.com>
Date:   Sat,  6 Feb 2021 06:16:52 +0100

Fix ledger sign message (#7004)

there was an around ~1/128 chance of creating an invalid signature when signing a message with a ledger
Diffstat:
Melectrum/plugins/ledger/ledger.py | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py @@ -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