mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Add CKey::ECDH
This commit is contained in:
parent
aa375e66c1
commit
045e615692
2 changed files with 15 additions and 0 deletions
10
src/key.cpp
10
src/key.cpp
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue