diff --git a/src/Makefile.am b/src/Makefile.am index 7ca5f7ce75..8dea607d97 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -624,7 +624,6 @@ crypto_libbitcoin_crypto_base_a_SOURCES = \ crypto/pkcs5_pbkdf2_hmac_sha512.cpp \ crypto/pkcs5_pbkdf2_hmac_sha512.h \ crypto/ripemd160.cpp \ - crypto/aes_helper.c \ crypto/ripemd160.h \ crypto/sha1.cpp \ crypto/sha1.h \ @@ -655,29 +654,30 @@ crypto_libbitcoin_crypto_avx2_a_SOURCES = crypto/sha256_avx2.cpp # x11 crypto_libbitcoin_crypto_base_a_SOURCES += \ - crypto/blake.c \ - crypto/bmw.c \ - crypto/cubehash.c \ - crypto/echo.c \ - crypto/groestl.c \ - crypto/jh.c \ - crypto/keccak.c \ - crypto/luffa.c \ - crypto/shavite.c \ - crypto/simd.c \ - crypto/skein.c \ - crypto/sph_blake.h \ - crypto/sph_bmw.h \ - crypto/sph_cubehash.h \ - crypto/sph_echo.h \ - crypto/sph_groestl.h \ - crypto/sph_jh.h \ - crypto/sph_keccak.h \ - crypto/sph_luffa.h \ - crypto/sph_shavite.h \ - crypto/sph_simd.h \ - crypto/sph_skein.h \ - crypto/sph_types.h + crypto/x11/aes_helper.c \ + crypto/x11/blake.c \ + crypto/x11/bmw.c \ + crypto/x11/cubehash.c \ + crypto/x11/echo.c \ + crypto/x11/groestl.c \ + crypto/x11/jh.c \ + crypto/x11/keccak.c \ + crypto/x11/luffa.c \ + crypto/x11/shavite.c \ + crypto/x11/simd.c \ + crypto/x11/skein.c \ + crypto/x11/sph_blake.h \ + crypto/x11/sph_bmw.h \ + crypto/x11/sph_cubehash.h \ + crypto/x11/sph_echo.h \ + crypto/x11/sph_groestl.h \ + crypto/x11/sph_jh.h \ + crypto/x11/sph_keccak.h \ + crypto/x11/sph_luffa.h \ + crypto/x11/sph_shavite.h \ + crypto/x11/sph_simd.h \ + crypto/x11/sph_skein.h \ + crypto/x11/sph_types.h crypto_libbitcoin_crypto_x86_shani_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) crypto_libbitcoin_crypto_x86_shani_a_CPPFLAGS = $(AM_CPPFLAGS) @@ -707,6 +707,7 @@ libbitcoin_consensus_a_SOURCES = \ consensus/validation.h \ hash.cpp \ hash.h \ + hash_x11.h \ prevector.h \ primitives/block.cpp \ primitives/block.h \ diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index 056ccf0e19..21794bcb27 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/src/crypto/aes_helper.c b/src/crypto/x11/aes_helper.c similarity index 100% rename from src/crypto/aes_helper.c rename to src/crypto/x11/aes_helper.c diff --git a/src/crypto/blake.c b/src/crypto/x11/blake.c similarity index 100% rename from src/crypto/blake.c rename to src/crypto/x11/blake.c diff --git a/src/crypto/bmw.c b/src/crypto/x11/bmw.c similarity index 100% rename from src/crypto/bmw.c rename to src/crypto/x11/bmw.c diff --git a/src/crypto/cubehash.c b/src/crypto/x11/cubehash.c similarity index 100% rename from src/crypto/cubehash.c rename to src/crypto/x11/cubehash.c diff --git a/src/crypto/echo.c b/src/crypto/x11/echo.c similarity index 100% rename from src/crypto/echo.c rename to src/crypto/x11/echo.c diff --git a/src/crypto/groestl.c b/src/crypto/x11/groestl.c similarity index 100% rename from src/crypto/groestl.c rename to src/crypto/x11/groestl.c diff --git a/src/crypto/jh.c b/src/crypto/x11/jh.c similarity index 100% rename from src/crypto/jh.c rename to src/crypto/x11/jh.c diff --git a/src/crypto/keccak.c b/src/crypto/x11/keccak.c similarity index 100% rename from src/crypto/keccak.c rename to src/crypto/x11/keccak.c diff --git a/src/crypto/luffa.c b/src/crypto/x11/luffa.c similarity index 100% rename from src/crypto/luffa.c rename to src/crypto/x11/luffa.c diff --git a/src/crypto/shavite.c b/src/crypto/x11/shavite.c similarity index 100% rename from src/crypto/shavite.c rename to src/crypto/x11/shavite.c diff --git a/src/crypto/simd.c b/src/crypto/x11/simd.c similarity index 100% rename from src/crypto/simd.c rename to src/crypto/x11/simd.c diff --git a/src/crypto/skein.c b/src/crypto/x11/skein.c similarity index 100% rename from src/crypto/skein.c rename to src/crypto/x11/skein.c diff --git a/src/crypto/sph_blake.h b/src/crypto/x11/sph_blake.h similarity index 99% rename from src/crypto/sph_blake.h rename to src/crypto/x11/sph_blake.h index 0957417cf4..4d6dc2a110 100644 --- a/src/crypto/sph_blake.h +++ b/src/crypto/x11/sph_blake.h @@ -42,7 +42,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for BLAKE-224. diff --git a/src/crypto/sph_bmw.h b/src/crypto/x11/sph_bmw.h similarity index 99% rename from src/crypto/sph_bmw.h rename to src/crypto/x11/sph_bmw.h index f958f77199..2d1698603e 100644 --- a/src/crypto/sph_bmw.h +++ b/src/crypto/x11/sph_bmw.h @@ -41,7 +41,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for BMW-224. diff --git a/src/crypto/sph_cubehash.h b/src/crypto/x11/sph_cubehash.h similarity index 99% rename from src/crypto/sph_cubehash.h rename to src/crypto/x11/sph_cubehash.h index 5480052d6c..8bdf8b8be3 100644 --- a/src/crypto/sph_cubehash.h +++ b/src/crypto/x11/sph_cubehash.h @@ -42,7 +42,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for CubeHash-224. diff --git a/src/crypto/sph_echo.h b/src/crypto/x11/sph_echo.h similarity index 99% rename from src/crypto/sph_echo.h rename to src/crypto/x11/sph_echo.h index f298c495f4..80bfd2ca6c 100644 --- a/src/crypto/sph_echo.h +++ b/src/crypto/x11/sph_echo.h @@ -41,7 +41,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for ECHO-224. diff --git a/src/crypto/sph_groestl.h b/src/crypto/x11/sph_groestl.h similarity index 99% rename from src/crypto/sph_groestl.h rename to src/crypto/x11/sph_groestl.h index 21948cee92..b1063dc3b2 100644 --- a/src/crypto/sph_groestl.h +++ b/src/crypto/x11/sph_groestl.h @@ -40,7 +40,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for Groestl-224. diff --git a/src/crypto/sph_jh.h b/src/crypto/x11/sph_jh.h similarity index 99% rename from src/crypto/sph_jh.h rename to src/crypto/x11/sph_jh.h index f8812b448f..63e01f1b13 100644 --- a/src/crypto/sph_jh.h +++ b/src/crypto/x11/sph_jh.h @@ -41,7 +41,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for JH-224. diff --git a/src/crypto/sph_keccak.h b/src/crypto/x11/sph_keccak.h similarity index 99% rename from src/crypto/sph_keccak.h rename to src/crypto/x11/sph_keccak.h index 1f37a79c21..3712afc013 100644 --- a/src/crypto/sph_keccak.h +++ b/src/crypto/x11/sph_keccak.h @@ -41,7 +41,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for Keccak-224. diff --git a/src/crypto/sph_luffa.h b/src/crypto/x11/sph_luffa.h similarity index 99% rename from src/crypto/sph_luffa.h rename to src/crypto/x11/sph_luffa.h index 5132477482..090ba7aa09 100644 --- a/src/crypto/sph_luffa.h +++ b/src/crypto/x11/sph_luffa.h @@ -41,7 +41,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for Luffa-224. diff --git a/src/crypto/sph_shavite.h b/src/crypto/x11/sph_shavite.h similarity index 99% rename from src/crypto/sph_shavite.h rename to src/crypto/x11/sph_shavite.h index 9a76f971cc..8e92283878 100644 --- a/src/crypto/sph_shavite.h +++ b/src/crypto/x11/sph_shavite.h @@ -39,7 +39,7 @@ #define SPH_SHAVITE_H__ #include -#include +#include "sph_types.h" #ifdef __cplusplus extern "C"{ diff --git a/src/crypto/sph_simd.h b/src/crypto/x11/sph_simd.h similarity index 99% rename from src/crypto/sph_simd.h rename to src/crypto/x11/sph_simd.h index 27e106b03c..9a3afb9580 100644 --- a/src/crypto/sph_simd.h +++ b/src/crypto/x11/sph_simd.h @@ -41,7 +41,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" /** * Output size (in bits) for SIMD-224. diff --git a/src/crypto/sph_skein.h b/src/crypto/x11/sph_skein.h similarity index 99% rename from src/crypto/sph_skein.h rename to src/crypto/x11/sph_skein.h index d159a9d5c0..c7debeec44 100644 --- a/src/crypto/sph_skein.h +++ b/src/crypto/x11/sph_skein.h @@ -46,7 +46,7 @@ extern "C"{ #endif #include -#include +#include "sph_types.h" #if SPH_64 diff --git a/src/crypto/sph_types.h b/src/crypto/x11/sph_types.h similarity index 100% rename from src/crypto/sph_types.h rename to src/crypto/x11/sph_types.h diff --git a/src/hash.h b/src/hash.h index f207744f0d..2d15a6ab22 100644 --- a/src/hash.h +++ b/src/hash.h @@ -16,18 +16,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include typedef uint256 ChainCode; @@ -253,71 +241,4 @@ unsigned int MurmurHash3(unsigned int nHashSeed, Span vData void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]); -/* ----------- Dash Hash ------------------------------------------------ */ -template -inline uint256 HashX11(const T1 pbegin, const T1 pend) - -{ - sph_blake512_context ctx_blake; - sph_bmw512_context ctx_bmw; - sph_groestl512_context ctx_groestl; - sph_jh512_context ctx_jh; - sph_keccak512_context ctx_keccak; - sph_skein512_context ctx_skein; - sph_luffa512_context ctx_luffa; - sph_cubehash512_context ctx_cubehash; - sph_shavite512_context ctx_shavite; - sph_simd512_context ctx_simd; - sph_echo512_context ctx_echo; - static unsigned char pblank[1]; - - uint512 hash[11]; - - sph_blake512_init(&ctx_blake); - sph_blake512 (&ctx_blake, (pbegin == pend ? pblank : static_cast(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0])); - sph_blake512_close(&ctx_blake, static_cast(&hash[0])); - - sph_bmw512_init(&ctx_bmw); - sph_bmw512 (&ctx_bmw, static_cast(&hash[0]), 64); - sph_bmw512_close(&ctx_bmw, static_cast(&hash[1])); - - sph_groestl512_init(&ctx_groestl); - sph_groestl512 (&ctx_groestl, static_cast(&hash[1]), 64); - sph_groestl512_close(&ctx_groestl, static_cast(&hash[2])); - - sph_skein512_init(&ctx_skein); - sph_skein512 (&ctx_skein, static_cast(&hash[2]), 64); - sph_skein512_close(&ctx_skein, static_cast(&hash[3])); - - sph_jh512_init(&ctx_jh); - sph_jh512 (&ctx_jh, static_cast(&hash[3]), 64); - sph_jh512_close(&ctx_jh, static_cast(&hash[4])); - - sph_keccak512_init(&ctx_keccak); - sph_keccak512 (&ctx_keccak, static_cast(&hash[4]), 64); - sph_keccak512_close(&ctx_keccak, static_cast(&hash[5])); - - sph_luffa512_init(&ctx_luffa); - sph_luffa512 (&ctx_luffa, static_cast(&hash[5]), 64); - sph_luffa512_close(&ctx_luffa, static_cast(&hash[6])); - - sph_cubehash512_init(&ctx_cubehash); - sph_cubehash512 (&ctx_cubehash, static_cast(&hash[6]), 64); - sph_cubehash512_close(&ctx_cubehash, static_cast(&hash[7])); - - sph_shavite512_init(&ctx_shavite); - sph_shavite512(&ctx_shavite, static_cast(&hash[7]), 64); - sph_shavite512_close(&ctx_shavite, static_cast(&hash[8])); - - sph_simd512_init(&ctx_simd); - sph_simd512 (&ctx_simd, static_cast(&hash[8]), 64); - sph_simd512_close(&ctx_simd, static_cast(&hash[9])); - - sph_echo512_init(&ctx_echo); - sph_echo512 (&ctx_echo, static_cast(&hash[9]), 64); - sph_echo512_close(&ctx_echo, static_cast(&hash[10])); - - return hash[10].trim256(); -} - #endif // BITCOIN_HASH_H diff --git a/src/hash_x11.h b/src/hash_x11.h new file mode 100644 index 0000000000..78c2c31e05 --- /dev/null +++ b/src/hash_x11.h @@ -0,0 +1,91 @@ +// Copyright (c) 2014-2023 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_HASH_X11_H +#define BITCOIN_HASH_X11_H + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +/* ----------- Dash Hash ------------------------------------------------ */ +template +inline uint256 HashX11(const T1 pbegin, const T1 pend) + +{ + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_skein512_context ctx_skein; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + static unsigned char pblank[1]; + + uint512 hash[11]; + + sph_blake512_init(&ctx_blake); + sph_blake512 (&ctx_blake, (pbegin == pend ? pblank : static_cast(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0])); + sph_blake512_close(&ctx_blake, static_cast(&hash[0])); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512 (&ctx_bmw, static_cast(&hash[0]), 64); + sph_bmw512_close(&ctx_bmw, static_cast(&hash[1])); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512 (&ctx_groestl, static_cast(&hash[1]), 64); + sph_groestl512_close(&ctx_groestl, static_cast(&hash[2])); + + sph_skein512_init(&ctx_skein); + sph_skein512 (&ctx_skein, static_cast(&hash[2]), 64); + sph_skein512_close(&ctx_skein, static_cast(&hash[3])); + + sph_jh512_init(&ctx_jh); + sph_jh512 (&ctx_jh, static_cast(&hash[3]), 64); + sph_jh512_close(&ctx_jh, static_cast(&hash[4])); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512 (&ctx_keccak, static_cast(&hash[4]), 64); + sph_keccak512_close(&ctx_keccak, static_cast(&hash[5])); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512 (&ctx_luffa, static_cast(&hash[5]), 64); + sph_luffa512_close(&ctx_luffa, static_cast(&hash[6])); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512 (&ctx_cubehash, static_cast(&hash[6]), 64); + sph_cubehash512_close(&ctx_cubehash, static_cast(&hash[7])); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, static_cast(&hash[7]), 64); + sph_shavite512_close(&ctx_shavite, static_cast(&hash[8])); + + sph_simd512_init(&ctx_simd); + sph_simd512 (&ctx_simd, static_cast(&hash[8]), 64); + sph_simd512_close(&ctx_simd, static_cast(&hash[9])); + + sph_echo512_init(&ctx_echo); + sph_echo512 (&ctx_echo, static_cast(&hash[9]), 64); + sph_echo512_close(&ctx_echo, static_cast(&hash[10])); + + return hash[10].trim256(); +} + +#endif // BITCOIN_HASH_X11_H diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index fb8fec057c..a7ec5a0823 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/test/util/data/non-backported.txt b/test/util/data/non-backported.txt index 150bbb70c1..35a639dc57 100644 --- a/test/util/data/non-backported.txt +++ b/test/util/data/non-backported.txt @@ -45,3 +45,4 @@ src/util/ranges_set.* src/util/wpipe.* src/wallet/bip39* src/wallet/hdchain.* +src/hash_x11.h