Skip to content

Commit c4ee069

Browse files
Merge pull request #14 from starkbank/fix/signature-range
Fixed signature range
2 parents 49c6003 + bd98780 commit c4ee069

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#Private and public keys
22
*.key
33
.idea
4+
node_modules

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.1.2] - 2020-09-27
20+
### Added
21+
- package-lock.json
22+
23+
## [1.1.1] - 2020-09-02
24+
### Changed
25+
- mocha to dev dependencies in package.json
26+
27+
## [1.1.0] - 2020-08-26
28+
### Added
29+
- external randNum override to Ecdsa.sign
30+
31+
## [1.0.0] - 2020-04-15
32+
### Added
33+
- first official version

ellipticcurve/ecdsa.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ exports.verify = function (message, signature, publicKey, hashfunc=sha256) {
3232
let curve = publicKey.curve;
3333
let sigR = signature.r;
3434
let sigS = signature.s;
35+
36+
if (sigR < 1 || sigR >= curve.N) {
37+
return false;
38+
}
39+
if (sigS < 1 || sigS >= curve.N) {
40+
return false;
41+
}
42+
3543
let inv = EcdsaMath.inv(sigS, curve.N);
3644
let u1 = EcdsaMath.multiply(curve.G, modulo((numberMessage.multiply(inv)), curve.N), curve.N, curve.A, curve.P);
3745
let u2 = EcdsaMath.multiply(publicKey.point, modulo((sigR.multiply(inv)), curve.N), curve.N, curve.A, curve.P);

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
"devDependencies": {
3737
"mocha": "^6.2.2"
3838
}
39-
}
39+
}

0 commit comments

Comments
 (0)