Skip to content

Commit ed22e48

Browse files
Merge pull request #16 from starkbank/fix/signature-range
Fixed signature range
2 parents 339c00b + b788e6f commit ed22e48

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to the following versioning pattern:
7+
8+
Given a version number MAJOR.MINOR.PATCH, increment:
9+
10+
- MAJOR version when **breaking changes** are introduced;
11+
- MINOR version when **backwards compatible changes** are introduced;
12+
- PATCH version when backwards compatible bug **fixes** are implemented.
13+
14+
15+
## [Unreleased]
16+
### Fixed
17+
- Signature r and s range check
18+
19+
## [1.0.0] - 2020-04-22
20+
### Added
21+
- first official version

src/main/java/com/starkbank/ellipticcurve/Ecdsa.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public static boolean verify(String message, Signature signature, PublicKey publ
5555
Curve curve = publicKey.curve;
5656
BigInteger r = signature.r;
5757
BigInteger s = signature.s;
58+
59+
if (r.compareTo(new BigInteger(String.valueOf(1))) < 0) {
60+
return false;
61+
}
62+
if (r.compareTo(curve.N) >= 0) {
63+
return false;
64+
}
65+
if (s.compareTo(new BigInteger(String.valueOf(1))) < 0) {
66+
return false;
67+
}
68+
if (s.compareTo(curve.N) >= 0) {
69+
return false;
70+
}
71+
5872
BigInteger w = Math.inv(s, curve.N);
5973
Point u1 =Math.multiply(curve.G, numberMessage.multiply(w).mod(curve.N), curve.N, curve.A, curve.P);
6074
Point u2 = Math.multiply(publicKey.point, r.multiply(w).mod(curve.N), curve.N, curve.A, curve.P);

0 commit comments

Comments
 (0)