From b70cdd7fa4b24c838e0688386c1337bdc7790c4a Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Jun 2012 16:13:24 -0700 Subject: [PATCH] Make Get/Set PrivateKeyU work. --- src/key.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/key.h b/src/key.h index 2d1eeb253a..10ab23a237 100644 --- a/src/key.h +++ b/src/key.h @@ -207,21 +207,30 @@ public: return vchRet; } - uint256 GetPrivateKeyU(void) + BIGNUM* GetSecretBN() const + { // DEPRECATED + return BN_dup(EC_KEY_get0_private_key(pkey)); + } + + void GetPrivateKeyU(uint256& privKey) { - // WRITEME - throw 0; + const BIGNUM* bn = EC_KEY_get0_private_key(pkey); + if (bn == NULL) + throw key_error("CKey::GetPrivateKeyU: EC_KEY_get0_private_key failed"); + privKey.zero(); + BN_bn2bin(bn, privKey.begin() + (privKey.size() - BN_num_bytes(bn))); } void SetPrivateKeyU(const uint256& key) { - // WRITEME - throw 0; - } - - BIGNUM* GetSecretBN() const - { - return BN_dup(EC_KEY_get0_private_key(pkey)); + BIGNUM* bn = BN_bin2bn(key.begin(), key.size(), NULL); + if (!EC_KEY_set_private_key(pkey, bn)) + { + BN_free(bn); + throw key_error("CKey::SetPrivateKeyU: EC_KEY_set_private_key failed"); + } + fSet = true; + BN_free(bn); } CPrivKey GetPrivKey()