From cbf7b8954098252a38b559e5ca3a88ed83c2c0c3 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 7 Dec 2018 16:23:22 +0100 Subject: [PATCH] Reintroduce BLSInit to correctly set secure alloctor callbacks https://github.com/dashpay/dash/pull/2409 removed the need to call the Init method of the Chia BLS library, but we also accidently removed the initialization of the secure allocator. --- src/bench/bench_dash.cpp | 1 + src/bls/bls.cpp | 8 ++++++++ src/bls/bls.h | 2 ++ src/init.cpp | 4 ++++ src/test/test_dash.cpp | 1 + 5 files changed, 16 insertions(+) diff --git a/src/bench/bench_dash.cpp b/src/bench/bench_dash.cpp index 82b1cf3b3ebd..a1d208502470 100644 --- a/src/bench/bench_dash.cpp +++ b/src/bench/bench_dash.cpp @@ -19,6 +19,7 @@ main(int argc, char** argv) ECC_Start(); ECCVerifyHandle verifyHandle; + BLSInit(); SetupEnvironment(); fPrintToDebugLog = false; // don't want to write to debug.log file diff --git a/src/bls/bls.cpp b/src/bls/bls.cpp index 02a793551866..bb44f50296ac 100644 --- a/src/bls/bls.cpp +++ b/src/bls/bls.cpp @@ -462,3 +462,11 @@ static void secure_free(void* p) return get_secure_allocator().deallocate(ptr, n); } #endif + +bool BLSInit() +{ +#ifndef BUILD_BITCOIN_INTERNAL + bls::BLS::SetSecureAllocator(secure_allocate, secure_free); +#endif + return true; +} diff --git a/src/bls/bls.h b/src/bls/bls.h index f62ab67566a4..c50a96ee11ec 100644 --- a/src/bls/bls.h +++ b/src/bls/bls.h @@ -300,4 +300,6 @@ typedef std::shared_ptr BLSPublicKeyVectorPtr; typedef std::shared_ptr BLSSecretKeyVectorPtr; typedef std::shared_ptr BLSSignatureVectorPtr; +bool BLSInit(); + #endif // DASH_CRYPTO_BLS_H diff --git a/src/init.cpp b/src/init.cpp index a66c23991157..5bf399197a24 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -855,6 +855,10 @@ bool InitSanityCheck(void) if (!glibc_sanity_test() || !glibcxx_sanity_test()) return false; + if (!BLSInit()) { + return false; + } + return true; } diff --git a/src/test/test_dash.cpp b/src/test/test_dash.cpp index 7bc3f7e9f734..5300171d1247 100644 --- a/src/test/test_dash.cpp +++ b/src/test/test_dash.cpp @@ -44,6 +44,7 @@ extern void noui_connect(); BasicTestingSetup::BasicTestingSetup(const std::string& chainName) { ECC_Start(); + BLSInit(); SetupEnvironment(); SetupNetworking(); InitSignatureCache();