aboutsummaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2021-04-18 18:58:43 -0400
committerRussell Yanofsky <russ@yanofsky.org>2021-04-19 06:11:38 -0400
commit387c4cf5887bfdaf1606e1b287d901e4c449514f (patch)
tree1d3c9deafd400edec87f8db0bed3a8bf5dacfd1e /src/init
parenta67b54855b294802d52f09fa60d3f63550cbada7 (diff)
Move common sanity check code to init/common
Diffstat (limited to 'src/init')
-rw-r--r--src/init/common.cpp24
-rw-r--r--src/init/common.h5
2 files changed, 29 insertions, 0 deletions
diff --git a/src/init/common.cpp b/src/init/common.cpp
index cb24708031..54c3fe3a2e 100644
--- a/src/init/common.cpp
+++ b/src/init/common.cpp
@@ -2,11 +2,15 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <compat/sanity.h>
#include <crypto/sha256.h>
#include <key.h>
#include <logging.h>
+#include <node/ui_interface.h>
#include <pubkey.h>
#include <random.h>
+#include <util/time.h>
+#include <util/translation.h>
#include <memory>
@@ -27,4 +31,24 @@ void UnsetGlobals()
globalVerifyHandle.reset();
ECC_Stop();
}
+
+bool SanityChecks()
+{
+ if (!ECC_InitSanityCheck()) {
+ return InitError(Untranslated("Elliptic curve cryptography sanity check failure. Aborting."));
+ }
+
+ if (!glibcxx_sanity_test())
+ return false;
+
+ if (!Random_SanityCheck()) {
+ return InitError(Untranslated("OS cryptographic RNG sanity check failure. Aborting."));
+ }
+
+ if (!ChronoSanityCheck()) {
+ return InitError(Untranslated("Clock epoch mismatch. Aborting."));
+ }
+
+ return true;
+}
} // namespace init
diff --git a/src/init/common.h b/src/init/common.h
index b201232bfc..64a3637370 100644
--- a/src/init/common.h
+++ b/src/init/common.h
@@ -11,6 +11,11 @@
namespace init {
void SetGlobals();
void UnsetGlobals();
+/**
+ * Ensure a usable environment with all
+ * necessary library support.
+ */
+bool SanityChecks();
} // namespace init
#endif // BITCOIN_INIT_COMMON_H