Skip to content

Commit

Permalink
Fix publicKeyVerify length check (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Apr 27, 2020
1 parent d9f7bf0 commit d2664cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/elliptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ function loadPublicKey (pubkey) {
switch (first) {
case 0x02:
case 0x03:
// if (pubkey.length !== 33) return null
if (pubkey.length !== 33) return null
return loadCompressedPublicKey(first, pubkey.subarray(1, 33))
case 0x04:
case 0x06:
case 0x07:
// if (pubkey.length !== 65) return null
if (pubkey.length !== 65) return null
return loadUncompressedPublicKey(first, pubkey.subarray(1, 33), pubkey.subarray(33, 65))
default:
return null
Expand Down
4 changes: 4 additions & 0 deletions test/publickey.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = (t, secp256k1) => {
invalidY[64] ^= 0x01
t.false(secp256k1.publicKeyVerify(invalidY), 'invalid Y')

const invalidLength = Buffer.from(publicKey.uncompressed)
invalidLength[0] = publicKey.compressed[0]
t.false(secp256k1.publicKeyVerify(invalidLength), 'invalid length')

t.end()
})

Expand Down

0 comments on commit d2664cb

Please sign in to comment.