From 330cea911f1020972113c8c3ad6a138282cd6b17 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Sat, 15 Oct 2022 10:56:55 +0200 Subject: [PATCH] enforce explicit experimental configuration through annotation Introduces a new support header that exposes the macro EXPERIMENTAL_FEATURE that (a) allows us to clearly mark blocks of code as experimental (or entire files) and (b) enforces that none of the annotated code gets compiled if --enable-experimental was not configured through a static assertion. Existing experimental features are annotated: - AVX2 using the intel-ipsec-mb dependency for SHA1/256/512 - ARMv8 intrinsics for SHA1/256 - ARMv82 intrinsics for SHA512 - SSE2 for scrypt --- src/Makefile.am | 1 + src/crypto/scrypt-sse2.cpp | 4 ++++ src/crypto/sha1.cpp | 5 +++++ src/crypto/sha256.cpp | 5 +++++ src/crypto/sha512.cpp | 4 ++++ src/support/experimental.h | 22 ++++++++++++++++++++++ 6 files changed, 41 insertions(+) create mode 100644 src/support/experimental.h diff --git a/src/Makefile.am b/src/Makefile.am index 1574df227..1809a8626 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -143,6 +143,7 @@ BITCOIN_CORE_H = \ support/allocators/zeroafterfree.h \ support/cleanse.h \ support/events.h \ + support/experimental.h \ support/lockedpool.h \ sync.h \ threadsafety.h \ diff --git a/src/crypto/scrypt-sse2.cpp b/src/crypto/scrypt-sse2.cpp index 3a951ba85..7241abe9e 100644 --- a/src/crypto/scrypt-sse2.cpp +++ b/src/crypto/scrypt-sse2.cpp @@ -28,12 +28,16 @@ */ #include "crypto/scrypt.h" +#include "support/experimental.h" #include #include #include #include +// this entire functionality is experimental +EXPERIMENTAL_FEATURE + static inline void xor_salsa8_sse2(__m128i B[4], const __m128i Bx[4]) { __m128i X0, X1, X2, X3; diff --git a/src/crypto/sha1.cpp b/src/crypto/sha1.cpp index fcd510e40..d928d5814 100644 --- a/src/crypto/sha1.cpp +++ b/src/crypto/sha1.cpp @@ -6,6 +6,7 @@ #include "crypto/sha1.h" #include "crypto/common.h" +#include "support/experimental.h" #include @@ -71,6 +72,9 @@ const uint32_t k4 = 0xCA62C1D6ul; void Transform(uint32_t* s, const unsigned char* chunk) { #if defined(USE_ARMV8) || defined(USE_ARMV82) + // this entire block is experimental + EXPERIMENTAL_FEATURE + uint32x4_t ABCD, ABCD_SAVED; uint32x4_t TMP0, TMP1; uint32x4_t MSG0, MSG1, MSG2, MSG3; @@ -241,6 +245,7 @@ void Transform(uint32_t* s, const unsigned char* chunk) #elif USE_AVX2 // Perform SHA1 one block (Intel AVX2) + EXPERIMENTAL_FEATURE sha1_one_block_avx2(chunk, s); #else // Perform SHA one block (legacy) diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index bd61c3858..f943da940 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -6,6 +6,7 @@ #include "crypto/sha256.h" #include "crypto/common.h" +#include "support/experimental.h" #include @@ -91,6 +92,9 @@ void inline Initialize(uint32_t* s) void Transform(uint32_t* s, const unsigned char* chunk) { #if defined(USE_ARMV8) || defined(USE_ARMV82) + // entire block is experimental + EXPERIMENTAL_FEATURE + uint32x4_t STATE0, STATE1, ABEF_SAVE, CDGH_SAVE; uint32x4_t MSG0, MSG1, MSG2, MSG3; uint32x4_t TMP0, TMP1, TMP2; @@ -247,6 +251,7 @@ void Transform(uint32_t* s, const unsigned char* chunk) #elif USE_AVX2 // Perform SHA256 one block (Intel AVX2) + EXPERIMENTAL_FEATURE sha256_one_block_avx2(chunk, s); #else // Perform SHA256 one block (legacy) diff --git a/src/crypto/sha512.cpp b/src/crypto/sha512.cpp index c911ed312..91842e0e6 100644 --- a/src/crypto/sha512.cpp +++ b/src/crypto/sha512.cpp @@ -6,6 +6,7 @@ #include "crypto/sha512.h" #include "crypto/common.h" +#include "support/experimental.h" #include @@ -100,6 +101,8 @@ void inline Round(uint64_t a, uint64_t b, uint64_t c, uint64_t& d, uint64_t e, u #ifdef USE_ARMV82 +EXPERIMENTAL_FEATURE + /* ---------------------------------------------------------------------- * Hardware-accelerated implementation of SHA-512 using Arm NEON. */ @@ -311,6 +314,7 @@ void Transform(uint64_t* s, const unsigned char* chunk) { #ifdef USE_AVX2 // Perform SHA512 one block (Intel AVX2) + EXPERIMENTAL_FEATURE sha512_one_block_avx2(chunk, s); #elif USE_ARMV82 sha512_neon_core core; diff --git a/src/support/experimental.h b/src/support/experimental.h new file mode 100644 index 000000000..b7201691a --- /dev/null +++ b/src/support/experimental.h @@ -0,0 +1,22 @@ +// Copyright (c) 2022 The Dogecoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef DOGECOIN_SUPPORT_EXPERIMENTAL_H +#define DOGECOIN_SUPPORT_EXPERIMENTAL_H + +// include config for experimental flag +#if defined(HAVE_CONFIG_H) +#include "config/bitcoin-config.h" +#endif //HAVE_CONFIG_H + +#if defined(ALLOW_DOGECOIN_EXPERIMENTAL) +#define EXPERIMENTAL_FEATURES_ALLOWED 1 +#else +#define EXPERIMENTAL_FEATURES_ALLOWED 0 +#endif // ALLOW_DOGECOIN_EXPERIMENTAL + +#define EXPERIMENTAL_FEATURE static_assert(EXPERIMENTAL_FEATURES_ALLOWED == 1, \ + "Experimental features need to be explicitly enabled during configuration."); + +#endif //BITCOIN_SUPPORT_EXPERIMENTAL_H