2021-04-18 18:56:12 -04:00
|
|
|
// Copyright (c) 2021 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2021-04-18 18:58:43 -04:00
|
|
|
#include <compat/sanity.h>
|
2021-04-18 18:56:12 -04:00
|
|
|
#include <crypto/sha256.h>
|
|
|
|
#include <key.h>
|
|
|
|
#include <logging.h>
|
2021-04-18 18:58:43 -04:00
|
|
|
#include <node/ui_interface.h>
|
2021-04-18 18:56:12 -04:00
|
|
|
#include <pubkey.h>
|
|
|
|
#include <random.h>
|
2021-04-18 18:58:43 -04:00
|
|
|
#include <util/time.h>
|
|
|
|
#include <util/translation.h>
|
2021-04-18 18:56:12 -04:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
|
|
|
|
|
|
|
namespace init {
|
|
|
|
void SetGlobals()
|
|
|
|
{
|
|
|
|
std::string sha256_algo = SHA256AutoDetect();
|
|
|
|
LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
|
|
|
|
RandomInit();
|
|
|
|
ECC_Start();
|
|
|
|
globalVerifyHandle.reset(new ECCVerifyHandle());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnsetGlobals()
|
|
|
|
{
|
|
|
|
globalVerifyHandle.reset();
|
|
|
|
ECC_Stop();
|
|
|
|
}
|
2021-04-18 18:58:43 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-04-18 18:56:12 -04:00
|
|
|
} // namespace init
|