// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <map>
+#include "key.h"
+#include "base58.h"
+#include "streams.h"
+#include "hash.h"
#include <openssl/ecdsa.h>
#include <openssl/evp.h>
-#include "key.h"
-#include "base58.h"
// Generate a private key from just the secret parameter
int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
{
- int ok = 0;
- BN_CTX *ctx = NULL;
- EC_POINT *pub_key = NULL;
-
if (!eckey) return 0;
+ int ok = 0;
+ BN_CTX *ctx = nullptr;
+ EC_POINT *pub_key = nullptr;
+
const EC_GROUP *group = EC_KEY_get0_group(eckey);
- if ((ctx = BN_CTX_new()) == NULL)
+ if ((ctx = BN_CTX_new()) == nullptr)
goto err;
pub_key = EC_POINT_new(group);
- if (pub_key == NULL)
+ if (pub_key == nullptr)
goto err;
- if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
+ if (!EC_POINT_mul(group, pub_key, priv_key, nullptr, nullptr, ctx))
goto err;
- EC_KEY_set_private_key(eckey,priv_key);
- EC_KEY_set_public_key(eckey,pub_key);
+ if (!EC_KEY_set_private_key(eckey,priv_key))
+ goto err;
+ if (!EC_KEY_set_public_key(eckey,pub_key))
+ goto err;
ok = 1;
if (pub_key)
EC_POINT_free(pub_key);
- if (ctx != NULL)
+ if (ctx != nullptr)
BN_CTX_free(ctx);
return(ok);
return fSuccessful;
}
+CKeyID CPubKey::GetID() const
+{
+ return CKeyID(Hash160(vbytes, vbytes + size()));
+}
+
+uint256 CPubKey::GetHash() const
+{
+ return Hash(vbytes, vbytes + size());
+}
+
bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const
{
if (vchSig.empty() || !IsValid())
return true;
}
+bool CMalleableKeyView::operator <(const CMalleableKeyView &kv) const { return vchPubKeyH.GetID() < kv.vchPubKeyH.GetID(); }
+
std::string CMalleableKeyView::ToString() const
{
CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
{
return vchSecretL.size() == 32 && GetMalleablePubKey().IsValid();
}
+
+CScriptID::CScriptID() : uint160(0) { }
+
+CScriptID::CScriptID(const uint160 &in) : uint160(in) { }
+
+CKeyID::CKeyID() : uint160(0) { }
+
+CKeyID::CKeyID(const uint160 &in) : uint160(in) { }