Skip to content

Commit d136170

Browse files
Add signature.r and signature.s range check
1 parent 998c92b commit d136170

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1313

1414

1515
## [Unreleased]
16+
### Fixed
17+
- Signature r and s range check
1618

1719
## [2.0.0] - 2021-10-08
1820
### Added

ellipticcurve/__init__.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from ellipticcurve.utils.compatibility import *
2-
from ellipticcurve.privateKey import PrivateKey
3-
from ellipticcurve.publicKey import PublicKey
4-
from ellipticcurve.signature import Signature
5-
from ellipticcurve.utils.file import File
6-
from ellipticcurve.ecdsa import Ecdsa
1+
from .utils.compatibility import *
2+
from .privateKey import PrivateKey
3+
from .publicKey import PublicKey
4+
from .signature import Signature
5+
from .utils.file import File
6+
from .ecdsa import Ecdsa

ellipticcurve/ecdsa.py

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def verify(cls, message, signature, publicKey, hashfunc=sha256):
3333
curve = publicKey.curve
3434
r = signature.r
3535
s = signature.s
36+
if not 1 <= r <= curve.N - 1:
37+
return False
38+
if not 1 <= s <= curve.N - 1:
39+
return False
3640
inv = Math.inv(s, curve.N)
3741
u1 = Math.multiply(curve.G, n=(numberMessage * inv) % curve.N, N=curve.N, A=curve.A, P=curve.P)
3842
u2 = Math.multiply(publicKey.point, n=(r * inv) % curve.N, N=curve.N, A=curve.A, P=curve.P)

0 commit comments

Comments
 (0)