Skip to content

Fixed signature range #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to the following versioning pattern:

Given a version number MAJOR.MINOR.PATCH, increment:

- MAJOR version when **breaking changes** are introduced;
- MINOR version when **backwards compatible changes** are introduced;
- PATCH version when backwards compatible bug **fixes** are implemented.


## [Unreleased]
### Fixed
- Signature r and s range check

## [1.0.0] - 2020-04-22
### Added
- first official version
14 changes: 14 additions & 0 deletions src/main/java/com/starkbank/ellipticcurve/Ecdsa.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public static boolean verify(String message, Signature signature, PublicKey publ
Curve curve = publicKey.curve;
BigInteger r = signature.r;
BigInteger s = signature.s;

if (r.compareTo(new BigInteger(String.valueOf(1))) < 0) {
return false;
}
if (r.compareTo(curve.N) >= 0) {
return false;
}
if (s.compareTo(new BigInteger(String.valueOf(1))) < 0) {
return false;
}
if (s.compareTo(curve.N) >= 0) {
return false;
}

BigInteger w = Math.inv(s, curve.N);
Point u1 =Math.multiply(curve.G, numberMessage.multiply(w).mod(curve.N), curve.N, curve.A, curve.P);
Point u2 = Math.multiply(publicKey.point, r.multiply(w).mod(curve.N), curve.N, curve.A, curve.P);
Expand Down