Skip to content

Commit 8801e31

Browse files
committed
refactor: remove unused CKey::Negate method
This method was introduced as a pre-requirement for the v2 transport protocol back then (see PR #14047, commit 463921b), when it was still BIP151. With the replacement BIP324, this is not needed anymore, and it's also unlikely that any other proposal would need to negate private keys at this abstraction level. (If there is really demand, it's trivial to reintroduce the method.)
1 parent f7a6d34 commit 8801e31

File tree

4 files changed

+0
-50
lines changed

4 files changed

+0
-50
lines changed

src/key.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ void CKey::MakeNewKey(bool fCompressedIn) {
166166
fCompressed = fCompressedIn;
167167
}
168168

169-
bool CKey::Negate()
170-
{
171-
assert(keydata);
172-
return secp256k1_ec_seckey_negate(secp256k1_context_sign, keydata->data());
173-
}
174-
175169
CPrivKey CKey::GetPrivKey() const {
176170
assert(keydata);
177171
CPrivKey seckey;

src/key.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ class CKey
124124
//! Generate a new private key using a cryptographic PRNG.
125125
void MakeNewKey(bool fCompressed);
126126

127-
//! Negate private key
128-
bool Negate();
129-
130127
/**
131128
* Convert the private key to a CPrivKey (serialized OpenSSL private key data).
132129
* This is expensive.

src/test/fuzz/key.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ FUZZ_TARGET(key, .init = initialize_key)
7878
assert(copied_key == key);
7979
}
8080

81-
{
82-
CKey negated_key = key;
83-
negated_key.Negate();
84-
assert(negated_key.IsValid());
85-
assert(!(negated_key == key));
86-
87-
negated_key.Negate();
88-
assert(negated_key == key);
89-
}
90-
9181
const uint256 random_uint256 = Hash(buffer);
9282

9383
{

src/test/key_tests.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -201,37 +201,6 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
201201
BOOST_CHECK(found_small);
202202
}
203203

204-
BOOST_AUTO_TEST_CASE(key_key_negation)
205-
{
206-
// create a dummy hash for signature comparison
207-
unsigned char rnd[8];
208-
std::string str = "Bitcoin key verification\n";
209-
GetRandBytes(rnd);
210-
uint256 hash{Hash(str, rnd)};
211-
212-
// import the static test key
213-
CKey key = DecodeSecret(strSecret1C);
214-
215-
// create a signature
216-
std::vector<unsigned char> vch_sig;
217-
std::vector<unsigned char> vch_sig_cmp;
218-
key.Sign(hash, vch_sig);
219-
220-
// negate the key twice
221-
BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
222-
key.Negate();
223-
// after the first negation, the signature must be different
224-
key.Sign(hash, vch_sig_cmp);
225-
BOOST_CHECK(vch_sig_cmp != vch_sig);
226-
BOOST_CHECK(key.GetPubKey().data()[0] == 0x02);
227-
key.Negate();
228-
// after the second negation, we should have the original key and thus the
229-
// same signature
230-
key.Sign(hash, vch_sig_cmp);
231-
BOOST_CHECK(vch_sig_cmp == vch_sig);
232-
BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
233-
}
234-
235204
static CPubKey UnserializePubkey(const std::vector<uint8_t>& data)
236205
{
237206
DataStream stream{};

0 commit comments

Comments
 (0)