Skip to content

Commit 804c542

Browse files
committed
ecdsa: add SEC annotations for verify
1 parent 52689fc commit 804c542

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ecdsa.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,26 @@ function verifyRaw(curve, e, signature, Q) {
8686
var r = signature.r
8787
var s = signature.s
8888

89+
// 1.4.1 Enforce r and s are both integers in the interval [1, n − 1]
8990
if (r.signum() <= 0 || r.compareTo(n) >= 0) return false
9091
if (s.signum() <= 0 || s.compareTo(n) >= 0) return false
9192

93+
// c = s^-1 mod n
9294
var c = s.modInverse(n)
9395

96+
// 1.4.4 Compute u1 = es^−1 mod n
97+
// u2 = rs^−1 mod n
9498
var u1 = e.multiply(c).mod(n)
9599
var u2 = r.multiply(c).mod(n)
96100

97-
var point = G.multiplyTwo(u1, Q, u2)
98-
var v = point.affineX.mod(n)
101+
// 1.4.5 Compute R = (xR, yR) = u1G + u2Q
102+
var R = G.multiplyTwo(u1, Q, u2)
103+
var v = R.affineX.mod(n)
99104

105+
// 1.4.5 (cont.) Enforce R is not at infinity
106+
if (curve.isInfinity(R)) return false
107+
108+
// 1.4.8 If v = r, output "valid", and if v != r, output "invalid"
100109
return v.equals(r)
101110
}
102111

0 commit comments

Comments
 (0)