Skip to content

Commit fa18c32

Browse files
authored
Merge pull request #191 from tomato42/unlikely-keys
handle private keys equal to n-1
2 parents d3b7289 + 087513b commit fa18c32

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ecdsa/ellipticcurve.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,12 @@ def mul_add(self, self_mul, other, other_mul):
619619
X1, Y1 = self.__x, self.__y
620620
other = other.scale()
621621
X2, Y2 = other.__x, other.__y
622-
both = (self + other).scale()
623-
X4, Y4 = both.__x, both.__y
622+
both = self + other
623+
if both is INFINITY:
624+
X4, Y4 = 0, 0
625+
else:
626+
both.scale()
627+
X4, Y4 = both.__x, both.__y
624628
_double = self._double
625629
_add = self._add
626630
while i > 1:

src/ecdsa/test_keys.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
sigdecode_der,
2525
sigdecode_strings,
2626
)
27+
from .curves import NIST256p
2728

2829

2930
class TestVerifyingKeyFromString(unittest.TestCase):
@@ -408,3 +409,10 @@ def test_SigningKey_sign_digest(convert):
408409
sig = sk.sign_digest(convert(data_hash))
409410

410411
vk.verify(sig, data)
412+
413+
414+
def test_SigningKey_with_unlikely_value():
415+
sk = SigningKey.from_secret_exponent(NIST256p.order - 1, curve=NIST256p)
416+
vk = sk.verifying_key
417+
sig = sk.sign(b"hello")
418+
assert vk.verify(sig, b"hello")

0 commit comments

Comments
 (0)