diff --git a/src/key.cpp b/src/key.cpp index 0a89ce36e0..be1249cfc2 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -12,6 +12,7 @@ #include #include +#include static secp256k1_context* secp256k1_context_sign = nullptr; @@ -202,6 +203,15 @@ bool SigHasLowR(const secp256k1_ecdsa_signature* sig) return compact_sig[0] < 0x80; } +uint256 CKey::ECDH(const CPubKey& pubkey) const { + assert(fValid); + uint256 result; + secp256k1_pubkey pkey; + assert(secp256k1_ec_pubkey_parse(secp256k1_context_sign, &pkey, pubkey.begin(), pubkey.size())); + assert(secp256k1_ecdh(secp256k1_context_sign, result.begin(), &pkey, begin(), NULL, NULL)); + return result; +} + bool CKey::Sign(const uint256 &hash, std::vector& vchSig, bool grind, uint32_t test_case) const { if (!fValid) return false; diff --git a/src/key.h b/src/key.h index e054d4f4c7..3bc8e01737 100644 --- a/src/key.h +++ b/src/key.h @@ -110,6 +110,11 @@ public: */ CPubKey GetPubKey() const; + /** + * Compute the ECDH exchange result using this private key and another public key. + */ + uint256 ECDH(const CPubKey& pubkey) const; + /** * Create a DER-serialized signature. * The test_case parameter tweaks the deterministic nonce.