aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/init.cpp21
-rw-r--r--src/key.cpp12
-rw-r--r--src/key.h3
3 files changed, 36 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index bc4924b48d..b66231ff2c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -11,6 +11,7 @@
#include "addrman.h"
#include "checkpoints.h"
+#include "key.h"
#include "main.h"
#include "miner.h"
#include "net.h"
@@ -385,6 +386,23 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
}
}
+/** Sanity checks
+ * Ensure that Bitcoin is running in a usable environment with all
+ * necessary library support.
+ */
+bool InitSanityCheck(void)
+{
+ if(!ECC_InitSanityCheck()) {
+ InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more "
+ "information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries");
+ return false;
+ }
+
+ // TODO: remaining sanity checks, see #4081
+
+ return true;
+}
+
/** Initialize bitcoin.
* @pre Parameters should be parsed and config file should be read.
*/
@@ -586,6 +604,9 @@ bool AppInit2(boost::thread_group& threadGroup)
strWalletFile = GetArg("-wallet", "wallet.dat");
#endif
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
+ // Sanity check
+ if (!InitSanityCheck())
+ return InitError(_("Initialization sanity check failed. Bitcoin Core is shutting down."));
std::string strDataDir = GetDataDir().string();
#ifdef ENABLE_WALLET
diff --git a/src/key.cpp b/src/key.cpp
index aa24f0a622..4747beffb4 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -631,3 +631,15 @@ bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const {
out.nChild = nChild;
return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode);
}
+
+bool ECC_InitSanityCheck() {
+ EC_KEY *pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
+ if(pkey == NULL)
+ return false;
+ EC_KEY_free(pkey);
+
+ // TODO Is there more EC functionality that could be missing?
+ return true;
+}
+
+
diff --git a/src/key.h b/src/key.h
index 983775fd23..11dc65de8c 100644
--- a/src/key.h
+++ b/src/key.h
@@ -306,4 +306,7 @@ struct CExtKey {
void SetMaster(const unsigned char *seed, unsigned int nSeedLen);
};
+/** Check that required EC support is available at runtime */
+bool ECC_InitSanityCheck(void);
+
#endif