Skip to content

Commit 9a15fff

Browse files
ChALkeRfanatid
authored andcommitted
elliptic: fix key verification in loadCompressedPublicKey
1 parent dc37f41 commit 9a15fff

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

lib/elliptic.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function loadCompressedPublicKey (first, xbuf) {
1818
let y = x.redSqr().redIMul(x).redIAdd(ecparams.b).redSqrt()
1919
if ((first === 0x03) !== y.isOdd()) y = y.redNeg()
2020

21+
// x*x*x + b = y*y
22+
const x3 = x.redSqr().redIMul(x)
23+
if (!y.redSqr().redISub(x3.redIAdd(ecparams.b)).isZero()) return null
24+
2125
return ec.keyPair({ pub: { x: x, y: y } })
2226
}
2327

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"node-gyp": "=10.1.0",
4141
"nyc": "^15.0.0",
4242
"prebuildify": "^6.0.1",
43-
"prebuildify-cross": "github:fanatid/prebuildify-cross#9f7af67698f06e07d42304d9813a6f19aee5812c",
43+
"prebuildify-cross": "^5.1.1",
4444
"standard": "^14.3.1",
4545
"tap-dot": "^2.0.0",
4646
"tape": "^4.10.1",

test/publickey.js

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ module.exports = (t, secp256k1) => {
3232
invalidLength[0] = publicKey.compressed[0]
3333
t.false(secp256k1.publicKeyVerify(invalidLength), 'invalid length')
3434

35+
const zeroUncompressed = Buffer.concat([Buffer.from([0x04]), Buffer.alloc(64)])
36+
t.false(secp256k1.publicKeyVerify(zeroUncompressed), 'zero uncompressed')
37+
38+
const zeroCompressed = Buffer.concat([Buffer.from([0x02]), Buffer.alloc(32)])
39+
t.false(secp256k1.publicKeyVerify(zeroCompressed), 'zero compressed')
40+
3541
t.end()
3642
})
3743

0 commit comments

Comments
 (0)