diff options
Diffstat (limited to 'src/key.cpp')
-rw-r--r-- | src/key.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/key.cpp b/src/key.cpp index 57e1cac58a..2fd68fa56b 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -2,13 +2,12 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "key.h" + #include <openssl/bn.h> #include <openssl/ecdsa.h> -#include <openssl/rand.h> #include <openssl/obj_mac.h> - -#include "key.h" - +#include <openssl/rand.h> // anonymous namespace with local implementation code (OpenSSL interaction) namespace { @@ -166,9 +165,12 @@ public: assert(nSize == nSize2); } - bool SetPrivKey(const CPrivKey &privkey) { + bool SetPrivKey(const CPrivKey &privkey, bool fSkipCheck=false) { const unsigned char* pbegin = &privkey[0]; if (d2i_ECPrivateKey(&pkey, &pbegin, privkey.size())) { + if(fSkipCheck) + return true; + // d2i_ECPrivateKey returns true if parsing succeeds. // This doesn't necessarily mean the key is valid. if (EC_KEY_check_key(pkey)) @@ -411,6 +413,24 @@ bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) return true; } +bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) { + CECKey key; + if (!key.SetPrivKey(privkey, fSkipCheck)) + return false; + + key.GetSecretBytes(vch); + fCompressed = vchPubKey.IsCompressed(); + fValid = true; + + if (fSkipCheck) + return true; + + if (GetPubKey() != vchPubKey) + return false; + + return true; +} + bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const { if (!IsValid()) return false; |