Skip to content

Commit a7743db

Browse files
authored
Merge commit from fork
1 parent dc37f41 commit a7743db

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
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

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)