Update CMakeLists.txt - play with openssl
[novacoin.git] / src / key.cpp
index b7a205a..82c8b34 100644 (file)
@@ -2,38 +2,41 @@
 // 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;
 
@@ -41,7 +44,7 @@ err:
 
     if (pub_key)
         EC_POINT_free(pub_key);
-    if (ctx != NULL)
+    if (ctx != nullptr)
         BN_CTX_free(ctx);
 
     return(ok);
@@ -513,6 +516,16 @@ bool CPubKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>
     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())
@@ -1172,6 +1185,8 @@ bool CMalleableKeyView::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubK
     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);
@@ -1211,3 +1226,11 @@ bool CMalleableKeyView::IsValid() const
 {
     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) { }