Skip to content

Commit dfa17d9

Browse files
Thomas Kerinafk11
Thomas Kerin
authored andcommitted
secp256k1_ec_pubkey_serialize - deal with bc break
1 parent 0a07964 commit dfa17d9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Crypto/EcAdapter/Impl/Secp256k1/Key/PublicKey.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ private function doEquals(PublicKey $other): bool
7272
$context = $this->ecAdapter->getContext();
7373
$pubA = '';
7474
$pubB = '';
75-
if (!(secp256k1_ec_pubkey_serialize($context, $pubA, $this->pubkey_t, (int) $this->compressed) && secp256k1_ec_pubkey_serialize($context, $pubB, $other->pubkey_t, (int) $this->compressed))) {
75+
$flags = $this->compressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED;
76+
77+
if (!(secp256k1_ec_pubkey_serialize($context, $pubA, $this->pubkey_t, $flags) && secp256k1_ec_pubkey_serialize($context, $pubB, $other->pubkey_t, $flags))) {
7678
throw new \RuntimeException('Unable to serialize public key during equals');
7779
}
7880

@@ -113,7 +115,8 @@ private function clonePubkey()
113115
{
114116
$context = $this->ecAdapter->getContext();
115117
$serialized = '';
116-
if (1 !== secp256k1_ec_pubkey_serialize($context, $serialized, $this->pubkey_t, (int) $this->compressed)) {
118+
$flags = $this->compressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED;
119+
if (1 !== secp256k1_ec_pubkey_serialize($context, $serialized, $this->pubkey_t, $flags)) {
117120
throw new \Exception('Secp256k1: pubkey serialize');
118121
}
119122

src/Crypto/EcAdapter/Impl/Secp256k1/Serializer/Key/PublicKeySerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private function doSerialize(PublicKey $publicKey)
3939
$this->ecAdapter->getContext(),
4040
$serialized,
4141
$publicKey->getResource(),
42-
(int) $isCompressed
42+
$isCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED
4343
)) {
4444
throw new \RuntimeException('Secp256k1: Failed to serialize public key');
4545
}

0 commit comments

Comments
 (0)