Merge #6303: refactor: segregate x11 hashing

e1749b50a3 exclude x11 dir from linting (pasta)
dc1f566fce fmt: run clang-format on hash_x11.h (pasta)
bd8aa04d44 refactor: segregate x11 hashing (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  Refactor x11 hashing out into it's own header

  ## What was done?
  move x11 hashing out of hash.h, into hash_x11.h and also move those headers crypto/x11 folder

  ## How Has This Been Tested?
  Building

  ## Breaking Changes
  None

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    utACK e1749b50a3

Tree-SHA512: c5e9ac9995608b1963494a4e6d870bb452972d6c09387c06546623e25c8be26fd2918918fb00fbef0c0356c61f1bed127a469c5adae252792f25bc419c73100b
This commit is contained in:
pasta 2024-10-07 14:43:20 -05:00
commit 4bd7f5db48
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38
32 changed files with 133 additions and 116 deletions

View File

@ -626,7 +626,6 @@ crypto_libbitcoin_crypto_base_a_SOURCES = \
crypto/pkcs5_pbkdf2_hmac_sha512.cpp \ crypto/pkcs5_pbkdf2_hmac_sha512.cpp \
crypto/pkcs5_pbkdf2_hmac_sha512.h \ crypto/pkcs5_pbkdf2_hmac_sha512.h \
crypto/ripemd160.cpp \ crypto/ripemd160.cpp \
crypto/aes_helper.c \
crypto/ripemd160.h \ crypto/ripemd160.h \
crypto/sha1.cpp \ crypto/sha1.cpp \
crypto/sha1.h \ crypto/sha1.h \
@ -657,29 +656,30 @@ crypto_libbitcoin_crypto_avx2_a_SOURCES = crypto/sha256_avx2.cpp
# x11 # x11
crypto_libbitcoin_crypto_base_a_SOURCES += \ crypto_libbitcoin_crypto_base_a_SOURCES += \
crypto/blake.c \ crypto/x11/aes_helper.c \
crypto/bmw.c \ crypto/x11/blake.c \
crypto/cubehash.c \ crypto/x11/bmw.c \
crypto/echo.c \ crypto/x11/cubehash.c \
crypto/groestl.c \ crypto/x11/echo.c \
crypto/jh.c \ crypto/x11/groestl.c \
crypto/keccak.c \ crypto/x11/jh.c \
crypto/luffa.c \ crypto/x11/keccak.c \
crypto/shavite.c \ crypto/x11/luffa.c \
crypto/simd.c \ crypto/x11/shavite.c \
crypto/skein.c \ crypto/x11/simd.c \
crypto/sph_blake.h \ crypto/x11/skein.c \
crypto/sph_bmw.h \ crypto/x11/sph_blake.h \
crypto/sph_cubehash.h \ crypto/x11/sph_bmw.h \
crypto/sph_echo.h \ crypto/x11/sph_cubehash.h \
crypto/sph_groestl.h \ crypto/x11/sph_echo.h \
crypto/sph_jh.h \ crypto/x11/sph_groestl.h \
crypto/sph_keccak.h \ crypto/x11/sph_jh.h \
crypto/sph_luffa.h \ crypto/x11/sph_keccak.h \
crypto/sph_shavite.h \ crypto/x11/sph_luffa.h \
crypto/sph_simd.h \ crypto/x11/sph_shavite.h \
crypto/sph_skein.h \ crypto/x11/sph_simd.h \
crypto/sph_types.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_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
crypto_libbitcoin_crypto_x86_shani_a_CPPFLAGS = $(AM_CPPFLAGS) crypto_libbitcoin_crypto_x86_shani_a_CPPFLAGS = $(AM_CPPFLAGS)
@ -709,6 +709,7 @@ libbitcoin_consensus_a_SOURCES = \
consensus/validation.h \ consensus/validation.h \
hash.cpp \ hash.cpp \
hash.h \ hash.h \
hash_x11.h \
prevector.h \ prevector.h \
primitives/block.cpp \ primitives/block.cpp \
primitives/block.h \ primitives/block.h \

View File

@ -13,6 +13,7 @@
#include <crypto/sha512.h> #include <crypto/sha512.h>
#include <crypto/siphash.h> #include <crypto/siphash.h>
#include <hash.h> #include <hash.h>
#include <hash_x11.h>
#include <random.h> #include <random.h>
#include <uint256.h> #include <uint256.h>

View File

@ -42,7 +42,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for BLAKE-224. * Output size (in bits) for BLAKE-224.

View File

@ -41,7 +41,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for BMW-224. * Output size (in bits) for BMW-224.

View File

@ -42,7 +42,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for CubeHash-224. * Output size (in bits) for CubeHash-224.

View File

@ -41,7 +41,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for ECHO-224. * Output size (in bits) for ECHO-224.

View File

@ -40,7 +40,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for Groestl-224. * Output size (in bits) for Groestl-224.

View File

@ -41,7 +41,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for JH-224. * Output size (in bits) for JH-224.

View File

@ -41,7 +41,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for Keccak-224. * Output size (in bits) for Keccak-224.

View File

@ -41,7 +41,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for Luffa-224. * Output size (in bits) for Luffa-224.

View File

@ -39,7 +39,7 @@
#define SPH_SHAVITE_H__ #define SPH_SHAVITE_H__
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C"{ extern "C"{

View File

@ -41,7 +41,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
/** /**
* Output size (in bits) for SIMD-224. * Output size (in bits) for SIMD-224.

View File

@ -46,7 +46,7 @@ extern "C"{
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <crypto/sph_types.h> #include "sph_types.h"
#if SPH_64 #if SPH_64

View File

@ -16,18 +16,6 @@
#include <uint256.h> #include <uint256.h>
#include <version.h> #include <version.h>
#include <crypto/sph_blake.h>
#include <crypto/sph_bmw.h>
#include <crypto/sph_groestl.h>
#include <crypto/sph_jh.h>
#include <crypto/sph_keccak.h>
#include <crypto/sph_skein.h>
#include <crypto/sph_luffa.h>
#include <crypto/sph_cubehash.h>
#include <crypto/sph_shavite.h>
#include <crypto/sph_simd.h>
#include <crypto/sph_echo.h>
#include <vector> #include <vector>
typedef uint256 ChainCode; typedef uint256 ChainCode;
@ -253,71 +241,4 @@ unsigned int MurmurHash3(unsigned int nHashSeed, Span<const unsigned char> vData
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]); void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]);
/* ----------- Dash Hash ------------------------------------------------ */
template<typename T1>
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<const void*>(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0]));
sph_blake512_close(&ctx_blake, static_cast<void*>(&hash[0]));
sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, static_cast<const void*>(&hash[0]), 64);
sph_bmw512_close(&ctx_bmw, static_cast<void*>(&hash[1]));
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, static_cast<const void*>(&hash[1]), 64);
sph_groestl512_close(&ctx_groestl, static_cast<void*>(&hash[2]));
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, static_cast<const void*>(&hash[2]), 64);
sph_skein512_close(&ctx_skein, static_cast<void*>(&hash[3]));
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, static_cast<const void*>(&hash[3]), 64);
sph_jh512_close(&ctx_jh, static_cast<void*>(&hash[4]));
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, static_cast<const void*>(&hash[4]), 64);
sph_keccak512_close(&ctx_keccak, static_cast<void*>(&hash[5]));
sph_luffa512_init(&ctx_luffa);
sph_luffa512 (&ctx_luffa, static_cast<void*>(&hash[5]), 64);
sph_luffa512_close(&ctx_luffa, static_cast<void*>(&hash[6]));
sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512 (&ctx_cubehash, static_cast<const void*>(&hash[6]), 64);
sph_cubehash512_close(&ctx_cubehash, static_cast<void*>(&hash[7]));
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, static_cast<const void*>(&hash[7]), 64);
sph_shavite512_close(&ctx_shavite, static_cast<void*>(&hash[8]));
sph_simd512_init(&ctx_simd);
sph_simd512 (&ctx_simd, static_cast<const void*>(&hash[8]), 64);
sph_simd512_close(&ctx_simd, static_cast<void*>(&hash[9]));
sph_echo512_init(&ctx_echo);
sph_echo512 (&ctx_echo, static_cast<const void*>(&hash[9]), 64);
sph_echo512_close(&ctx_echo, static_cast<void*>(&hash[10]));
return hash[10].trim256();
}
#endif // BITCOIN_HASH_H #endif // BITCOIN_HASH_H

92
src/hash_x11.h Normal file
View File

@ -0,0 +1,92 @@
// 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 <crypto/x11/sph_blake.h>
#include <crypto/x11/sph_bmw.h>
#include <crypto/x11/sph_cubehash.h>
#include <crypto/x11/sph_echo.h>
#include <crypto/x11/sph_groestl.h>
#include <crypto/x11/sph_jh.h>
#include <crypto/x11/sph_keccak.h>
#include <crypto/x11/sph_luffa.h>
#include <crypto/x11/sph_shavite.h>
#include <crypto/x11/sph_simd.h>
#include <crypto/x11/sph_skein.h>
#include <uint256.h>
/* ----------- Dash Hash ------------------------------------------------ */
template <typename T1>
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<const void*>(&pbegin[0])),
(pend - pbegin) * sizeof(pbegin[0]));
sph_blake512_close(&ctx_blake, static_cast<void*>(&hash[0]));
sph_bmw512_init(&ctx_bmw);
sph_bmw512(&ctx_bmw, static_cast<const void*>(&hash[0]), 64);
sph_bmw512_close(&ctx_bmw, static_cast<void*>(&hash[1]));
sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, static_cast<const void*>(&hash[1]), 64);
sph_groestl512_close(&ctx_groestl, static_cast<void*>(&hash[2]));
sph_skein512_init(&ctx_skein);
sph_skein512(&ctx_skein, static_cast<const void*>(&hash[2]), 64);
sph_skein512_close(&ctx_skein, static_cast<void*>(&hash[3]));
sph_jh512_init(&ctx_jh);
sph_jh512(&ctx_jh, static_cast<const void*>(&hash[3]), 64);
sph_jh512_close(&ctx_jh, static_cast<void*>(&hash[4]));
sph_keccak512_init(&ctx_keccak);
sph_keccak512(&ctx_keccak, static_cast<const void*>(&hash[4]), 64);
sph_keccak512_close(&ctx_keccak, static_cast<void*>(&hash[5]));
sph_luffa512_init(&ctx_luffa);
sph_luffa512(&ctx_luffa, static_cast<void*>(&hash[5]), 64);
sph_luffa512_close(&ctx_luffa, static_cast<void*>(&hash[6]));
sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512(&ctx_cubehash, static_cast<const void*>(&hash[6]), 64);
sph_cubehash512_close(&ctx_cubehash, static_cast<void*>(&hash[7]));
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, static_cast<const void*>(&hash[7]), 64);
sph_shavite512_close(&ctx_shavite, static_cast<void*>(&hash[8]));
sph_simd512_init(&ctx_simd);
sph_simd512(&ctx_simd, static_cast<const void*>(&hash[8]), 64);
sph_simd512_close(&ctx_simd, static_cast<void*>(&hash[9]));
sph_echo512_init(&ctx_echo);
sph_echo512(&ctx_echo, static_cast<const void*>(&hash[9]), 64);
sph_echo512_close(&ctx_echo, static_cast<void*>(&hash[10]));
return hash[10].trim256();
}
#endif // BITCOIN_HASH_X11_H

View File

@ -6,6 +6,7 @@
#include <primitives/block.h> #include <primitives/block.h>
#include <hash.h> #include <hash.h>
#include <hash_x11.h>
#include <streams.h> #include <streams.h>
#include <tinyformat.h> #include <tinyformat.h>

View File

@ -10,7 +10,7 @@ export LC_ALL=C
HEADER_ID_PREFIX="BITCOIN_" HEADER_ID_PREFIX="BITCOIN_"
HEADER_ID_SUFFIX="_H" HEADER_ID_SUFFIX="_H"
REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|dashbls/|immer/|leveldb/|crc32c/|secp256k1/|test/fuzz/FuzzedDataProvider.h|tinyformat.h|bench/nanobench.h|univalue/|ctpl_stl.h|bls/|crypto/sph|gsl|util/expected.h)" REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|dashbls/|immer/|leveldb/|crc32c/|secp256k1/|test/fuzz/FuzzedDataProvider.h|tinyformat.h|bench/nanobench.h|univalue/|ctpl_stl.h|bls/|crypto/x11/sph|gsl|util/expected.h)"
EXIT_CODE=0 EXIT_CODE=0
for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}") for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}")

View File

@ -9,7 +9,7 @@
# Check includes: Check for duplicate includes. Enforce bracket syntax includes. # Check includes: Check for duplicate includes. Enforce bracket syntax includes.
export LC_ALL=C export LC_ALL=C
IGNORE_REGEXP="/(dashbls|immer|leveldb|secp256k1|univalue|crc32c)/" IGNORE_REGEXP="/(dashbls|immer|leveldb|secp256k1|univalue|crc32c|crypto/x11)/"
# cd to root folder of git repo for git ls-files to work properly # cd to root folder of git repo for git ls-files to work properly
cd "$(dirname $0)/../.." || exit 1 cd "$(dirname $0)/../.." || exit 1

View File

@ -46,3 +46,4 @@ src/util/ranges_set.*
src/util/wpipe.* src/util/wpipe.*
src/wallet/bip39* src/wallet/bip39*
src/wallet/hdchain.* src/wallet/hdchain.*
src/hash_x11.h