Skip to content

Commit a5168f6

Browse files
Merge pull request #3 from starkbank/fix/signature-range
Add signature.r and signature.s range check
2 parents aa4e9e0 + 4b960e2 commit a5168f6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

CHANGELOG.md

+21
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-14
20+
### Added
21+
- first official version

lib/ecdsa.ex

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ defmodule EllipticCurve.Ecdsa do
8585

8686
inv = Math.inv(signature.s, curveData."N")
8787

88-
signature.r ==
88+
result = signature.r ==
8989
Math.add(
9090
Math.multiply(
9191
curveData."G",
@@ -104,5 +104,11 @@ defmodule EllipticCurve.Ecdsa do
104104
curveData."A",
105105
curveData."P"
106106
).x
107+
108+
cond do
109+
signature.r < 1 || signature.r >= curveData."N" -> false
110+
signature.s < 1 || signature.s >= curveData."N" -> false
111+
true -> result
112+
end
107113
end
108114
end

0 commit comments

Comments
 (0)