Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR authored Oct 18, 2024
1 parent dc37f41 commit a7743db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/elliptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function loadCompressedPublicKey (first, xbuf) {
let y = x.redSqr().redIMul(x).redIAdd(ecparams.b).redSqrt()
if ((first === 0x03) !== y.isOdd()) y = y.redNeg()

// x*x*x + b = y*y
const x3 = x.redSqr().redIMul(x)
if (!y.redSqr().redISub(x3.redIAdd(ecparams.b)).isZero()) return null

return ec.keyPair({ pub: { x: x, y: y } })
}

Expand Down
6 changes: 6 additions & 0 deletions test/publickey.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module.exports = (t, secp256k1) => {
invalidLength[0] = publicKey.compressed[0]
t.false(secp256k1.publicKeyVerify(invalidLength), 'invalid length')

const zeroUncompressed = Buffer.concat([Buffer.from([0x04]), Buffer.alloc(64)])
t.false(secp256k1.publicKeyVerify(zeroUncompressed), 'zero uncompressed')

const zeroCompressed = Buffer.concat([Buffer.from([0x02]), Buffer.alloc(32)])
t.false(secp256k1.publicKeyVerify(zeroCompressed), 'zero compressed')

t.end()
})

Expand Down

0 comments on commit a7743db

Please sign in to comment.