Skip to content

Commit d2664cb

Browse files
authored
Fix publicKeyVerify length check (#167)
1 parent d9f7bf0 commit d2664cb

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/elliptic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ function loadPublicKey (pubkey) {
4747
switch (first) {
4848
case 0x02:
4949
case 0x03:
50-
// if (pubkey.length !== 33) return null
50+
if (pubkey.length !== 33) return null
5151
return loadCompressedPublicKey(first, pubkey.subarray(1, 33))
5252
case 0x04:
5353
case 0x06:
5454
case 0x07:
55-
// if (pubkey.length !== 65) return null
55+
if (pubkey.length !== 65) return null
5656
return loadUncompressedPublicKey(first, pubkey.subarray(1, 33), pubkey.subarray(33, 65))
5757
default:
5858
return null

test/publickey.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = (t, secp256k1) => {
2828
invalidY[64] ^= 0x01
2929
t.false(secp256k1.publicKeyVerify(invalidY), 'invalid Y')
3030

31+
const invalidLength = Buffer.from(publicKey.uncompressed)
32+
invalidLength[0] = publicKey.compressed[0]
33+
t.false(secp256k1.publicKeyVerify(invalidLength), 'invalid length')
34+
3135
t.end()
3236
})
3337

0 commit comments

Comments
 (0)