Add CKey::ECDH

This commit is contained in:
Steven Roose 2019-03-19 20:28:28 +00:00
parent aa375e66c1
commit 045e615692
No known key found for this signature in database
GPG key ID: 7FC91380BB4CE800
2 changed files with 15 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <secp256k1.h>
#include <secp256k1_recovery.h>
#include <secp256k1_ecdh.h>
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<unsigned char>& vchSig, bool grind, uint32_t test_case) const {
if (!fValid)
return false;