sha256csm init

This commit is contained in:
Pavel Rosický 2022-07-26 23:54:26 +02:00
parent 4c57b60e59
commit 90a826cbe4
17 changed files with 166 additions and 18 deletions

View file

@ -10,6 +10,7 @@ option(WITH_RANDOMX "Enable RandomX algorithms family" ON)
option(WITH_ARGON2 "Enable Argon2 algorithms family" ON)
option(WITH_KAWPOW "Enable KawPow algorithms family" ON)
option(WITH_GHOSTRIDER "Enable GhostRider algorithm" ON)
option(WITH_SHA256CSM "Enable Sha256CSM algorithm" ON)
option(WITH_HTTP "Enable HTTP protocol support (client/server)" ON)
option(WITH_DEBUG_LOG "Enable debug log output" OFF)
option(WITH_TLS "Enable OpenSSL support" ON)
@ -200,6 +201,7 @@ include(cmake/randomx.cmake)
include(cmake/argon2.cmake)
include(cmake/kawpow.cmake)
include(cmake/ghostrider.cmake)
include(cmake/sha256.cmake)
include(cmake/OpenSSL.cmake)
include(cmake/asm.cmake)
@ -235,7 +237,7 @@ if (WITH_DEBUG_LOG)
endif()
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB} ${ARGON2_LIBRARY} ${ETHASH_LIBRARY} ${GHOSTRIDER_LIBRARY})
target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB} ${ARGON2_LIBRARY} ${ETHASH_LIBRARY} ${GHOSTRIDER_LIBRARY} ${SHA256_LIBRARY})
if (WIN32)
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/bin/WinRing0/WinRing0x64.sys" $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>)

View file

@ -1,4 +1,4 @@
if (WITH_GHOSTRIDER)
if (WITH_GHOSTRIDER OR WITH_SHA256CSM) # WITH_SHA256CSM for sph_sha2
add_definitions(/DXMRIG_ALGO_GHOSTRIDER)
add_subdirectory(src/crypto/ghostrider)
set(GHOSTRIDER_LIBRARY ghostrider)

8
cmake/sha256.cmake Normal file
View file

@ -0,0 +1,8 @@
if (WITH_SHA256CSM)
add_definitions(/DXMRIG_ALGO_SHA256CSM)
# add_subdirectory(src/crypto/sha256)
# set(SHA256_LIBRARY sha256)
else()
remove_definitions(/DXMRIG_ALGO_SHA256CSM)
# set(SHA256_LIBRARY "")
endif()

View file

@ -179,6 +179,7 @@ void xmrig::CpuConfig::generate()
count += xmrig::generate<Algorithm::RANDOM_X>(m_threads, m_limit);
count += xmrig::generate<Algorithm::ARGON2>(m_threads, m_limit);
count += xmrig::generate<Algorithm::GHOSTRIDER>(m_threads, m_limit);
count += xmrig::generate<Algorithm::SHA256>(m_threads, m_limit);
m_shouldSave |= count > 0;
}

View file

@ -161,6 +161,13 @@ size_t inline generate<Algorithm::GHOSTRIDER>(Threads<CpuThreads>& threads, uint
}
#endif
#ifdef XMRIG_ALGO_SHA256CSM
template<>
size_t inline generate<Algorithm::SHA256>(Threads<CpuThreads>& threads, uint32_t limit)
{
return generate(Algorithm::kSHA256CSM, threads, Algorithm::SHA256CSM, limit);
}
#endif
} /* namespace xmrig */

View file

@ -20,6 +20,16 @@
#include <thread>
#include <mutex>
#include <iostream>
#include <cinttypes>
#include <iomanip>
#include <sstream>
#include <stdexcept>
extern "C" {
#include "crypto/ghostrider/sph_sha2.h"
}
#include "backend/cpu/Cpu.h"
#include "backend/cpu/CpuWorker.h"
@ -216,6 +226,10 @@ bool xmrig::CpuWorker<N>::selfTest()
}
# endif
# ifdef XMRIG_ALGO_SHA256CSM
if (m_algorithm.id() == Algorithm::SHA256CSM) return verify(Algorithm::SHA256CSM, test_output_sha256csm);
# endif
return false;
}
@ -316,6 +330,12 @@ void xmrig::CpuWorker<N>::start()
break;
# endif
# ifdef XMRIG_ALGO_SHA256CSM
case Algorithm::SHA256:
sha256csm(m_hash, m_job.blob(), 0);
break;
# endif
default:
fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
break;
@ -408,6 +428,35 @@ bool xmrig::CpuWorker<N>::verify(const Algorithm &algorithm, const uint8_t *refe
}
# endif
# ifdef XMRIG_ALGO_SHA256CSM
if (algorithm == Algorithm::SHA256CSM) {
uint8_t blob[80] = {
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
};
// 62ddda4d -> e7412af4
uint8_t hash1[32] = {};
sha256csm(hash1, blob, 0);
// for(int i = 0; i < 32; i++) {
// printf("%02x", hash1[i]);
// }
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (int i = 0; i < 32; i++) {
ss << std::hex << std::setw(2) << static_cast<int>(hash1[i]);
}
return ss.str() == "e537f42caaeadfc2f022eff26f6e4b16c78ce86f5eda63b347d4466806e07821";
}
# endif
cn_hash_fun func = fn(algorithm);
if (!func) {
return false;

View file

@ -101,6 +101,9 @@ const char* Algorithm::kGHOSTRIDER = "ghostrider";
const char* Algorithm::kGHOSTRIDER_RTM = "ghostrider";
#endif
#ifdef XMRIG_ALGO_SHA256CSM
const char* Algorithm::kSHA256CSM = "sha256csm";
#endif
#define ALGO_NAME(ALGO) { Algorithm::ALGO, Algorithm::k##ALGO }
#define ALGO_ALIAS(ALGO, NAME) { NAME, Algorithm::ALGO }
@ -163,6 +166,10 @@ static const std::map<uint32_t, const char *> kAlgorithmNames = {
# ifdef XMRIG_ALGO_GHOSTRIDER
ALGO_NAME(GHOSTRIDER_RTM),
# endif
# ifdef XMRIG_ALGO_SHA256CSM
ALGO_NAME(SHA256CSM),
# endif
};
@ -275,6 +282,10 @@ static const std::map<const char *, Algorithm::Id, aliasCompare> kAlgorithmAlias
ALGO_ALIAS_AUTO(KAWPOW_RVN), ALGO_ALIAS(KAWPOW_RVN, "kawpow/rvn"),
# endif
# ifdef XMRIG_ALGO_SHA256CSM
ALGO_ALIAS_AUTO(SHA256CSM), ALGO_ALIAS(SHA256CSM, "sha256csm/gale"),
# endif
# ifdef XMRIG_ALGO_GHOSTRIDER
ALGO_ALIAS_AUTO(GHOSTRIDER_RTM), ALGO_ALIAS(GHOSTRIDER_RTM, "ghostrider/rtm"),
ALGO_ALIAS(GHOSTRIDER_RTM, "gr"),
@ -353,7 +364,8 @@ std::vector<xmrig::Algorithm> xmrig::Algorithm::all(const std::function<bool(con
RX_0, RX_WOW, RX_ARQ, RX_GRAFT, RX_SFX, RX_KEVA,
AR2_CHUKWA, AR2_CHUKWA_V2, AR2_WRKZ,
KAWPOW_RVN,
GHOSTRIDER_RTM
GHOSTRIDER_RTM,
SHA256CSM
};
Algorithms out;

View file

@ -82,6 +82,7 @@ public:
AR2_CHUKWA_V2 = 0x61140000, // "argon2/chukwav2" Argon2id (Chukwa v2).
AR2_WRKZ = 0x61120000, // "argon2/wrkz" Argon2id (WRKZ)
KAWPOW_RVN = 0x6b0f0000, // "kawpow/rvn" KawPow (RVN)
SHA256CSM = 0x6d0f0000, // "sha256csm" SHA256CSM (GalleonCoin)
};
enum Family : uint32_t {
@ -95,7 +96,8 @@ public:
RANDOM_X = 0x72000000,
ARGON2 = 0x61000000,
KAWPOW = 0x6b000000,
GHOSTRIDER = 0x6c000000
GHOSTRIDER = 0x6c000000,
SHA256 = 0x6d000000
};
static const char *kINVALID;
@ -163,6 +165,10 @@ public:
static const char* kGHOSTRIDER_RTM;
# endif
# ifdef XMRIG_ALGO_SHA256CSM
static const char* kSHA256CSM;
# endif
inline Algorithm() = default;
inline Algorithm(const char *algo) : m_id(parse(algo)) {}
inline Algorithm(Id id) : m_id(id) {}

View file

@ -76,9 +76,13 @@ int64_t xmrig::EthStratumClient::submit(const JobResult& result)
params.PushBack(m_user.toJSON(), allocator);
params.PushBack(result.jobId.toJSON(), allocator);
# ifdef XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
if (m_pool.algorithm().id() == Algorithm::GHOSTRIDER_RTM) {
params.PushBack(Value("00000000000000000000000000000000", static_cast<uint32_t>(m_extraNonce2Size * 2)), allocator);
} else if (m_pool.algorithm().id() == Algorithm::SHA256CSM) {
params.PushBack(Value("00000000", static_cast<uint32_t>(m_extraNonce2Size * 2)), allocator);
}
if ((m_pool.algorithm().id() == Algorithm::GHOSTRIDER_RTM || m_pool.algorithm().id() == Algorithm::SHA256CSM)) {
params.PushBack(Value(m_ntime.data(), allocator), allocator);
std::stringstream s;
@ -113,8 +117,8 @@ int64_t xmrig::EthStratumClient::submit(const JobResult& result)
uint64_t actual_diff;
# ifdef XMRIG_ALGO_GHOSTRIDER
if (result.algorithm == Algorithm::GHOSTRIDER_RTM) {
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
if ((result.algorithm == Algorithm::GHOSTRIDER_RTM) || (result.algorithm == Algorithm::SHA256CSM)) {
actual_diff = reinterpret_cast<const uint64_t*>(result.result())[3];
}
else
@ -195,14 +199,14 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
setExtraNonce(arr[0]);
}
# ifdef XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
if (strcmp(method, "mining.set_difficulty") == 0) {
if (!params.IsArray()) {
LOG_ERR("%s " RED("invalid mining.set_difficulty notification: params is not an array"), tag());
return;
}
if (m_pool.algorithm().id() != Algorithm::GHOSTRIDER_RTM) {
if ((m_pool.algorithm().id() != Algorithm::GHOSTRIDER_RTM) && (m_pool.algorithm().id() != Algorithm::SHA256CSM)) {
return;
}
@ -236,7 +240,7 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
algo = m_pool.coin().algorithm();
}
const size_t min_arr_size = (algo.id() == Algorithm::GHOSTRIDER_RTM) ? 8 : 6;
const size_t min_arr_size = ((algo.id() == Algorithm::GHOSTRIDER_RTM) || (algo.id() == Algorithm::SHA256CSM)) ? 8 : 6;
if (arr.Size() < min_arr_size) {
LOG_ERR("%s " RED("invalid mining.notify notification: params array has wrong size"), tag());
@ -256,8 +260,8 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
std::stringstream s;
# ifdef XMRIG_ALGO_GHOSTRIDER
if (algo.id() == Algorithm::GHOSTRIDER_RTM) {
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
if ((algo.id() == Algorithm::GHOSTRIDER_RTM) || (algo.id() == Algorithm::SHA256CSM)) {
// Raptoreum uses Bitcoin's Stratum protocol
// https://en.bitcoinwiki.org/wiki/Stratum_mining_protocol#mining.notify
@ -534,7 +538,7 @@ void xmrig::EthStratumClient::onSubscribeResponse(const rapidjson::Value &result
setExtraNonce(arr[1]);
# ifdef XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
if ((arr.Size() > 2) && (arr[2].IsUint())) {
m_extraNonce2Size = arr[2].GetUint();
}

View file

@ -47,7 +47,7 @@ protected:
void setExtraNonce(const rapidjson::Value &nonce);
# ifdef XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
inline void setExtraNonce2Size(uint64_t size) { m_extraNonce2Size = size; }
# endif
@ -62,7 +62,7 @@ private:
bool m_authorized = false;
std::pair<uint64_t, String> m_extraNonce{};
# ifdef XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
uint64_t m_extraNonce2Size = 0;
uint64_t m_nextDifficulty = 0;
String m_ntime;

View file

@ -218,9 +218,9 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
IClient *client = nullptr;
if (m_mode == MODE_POOL) {
# if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
const uint32_t f = m_algorithm.family();
if ((f == Algorithm::KAWPOW) || (f == Algorithm::GHOSTRIDER) || (m_coin == Coin::RAVEN)) {
if ((f == Algorithm::KAWPOW) || (f == Algorithm::GHOSTRIDER) || (m_coin == Coin::RAVEN) || (f == Algorithm::SHA256)) {
client = new EthStratumClient(id, Platform::userAgent(), listener);
}
else
@ -237,7 +237,7 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
client = new SelfSelectClient(id, Platform::userAgent(), listener, m_submitToOrigin);
}
# endif
# if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER
# if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER || defined XMRIG_ALGO_SHA256CSM
else if (m_mode == MODE_AUTO_ETH) {
client = new AutoClient(id, Platform::userAgent(), listener);
}

View file

@ -69,6 +69,9 @@ xmrig::BenchConfig::BenchConfig(uint32_t size, const String &id, const rapidjson
if (!m_algorithm.isValid() || (f != Algorithm::RANDOM_X
# ifdef XMRIG_ALGO_GHOSTRIDER
&& f != Algorithm::GHOSTRIDER
# endif
# ifdef XMRIG_ALGO_SHA256CSM
&& f != Algorithm::SHA256
# endif
)) {
m_algorithm = Algorithm::RX_0;

View file

@ -454,6 +454,12 @@ const static uint8_t test_output_gr[256] = {
};
#endif
#ifdef XMRIG_ALGO_SHA256CSM
// "SHA256CSM"
const static uint8_t test_output_sha256csm[32] = {
};
#endif
} // namespace xmrig

View file

@ -783,6 +783,22 @@ void sha256d(void* hash, const void* data, int len)
sph_sha256_full(hash, hash, 32);
}
void sha256csm(void* hash, const void* data, int len)
{
char emptybuffer[112];
memset(emptybuffer, 0, sizeof(emptybuffer));
memcpy(emptybuffer, data, 80);
sph_sha256_context cc;
sph_sha256_init( &cc );
sph_sha256( &cc, emptybuffer, 112 );
sph_sha256_close( &cc, hash );
sph_sha256_init( &cc );
sph_sha256( &cc, hash, 32 );
sph_sha256_close( &cc, hash );
}
/* see sph_sha2.h */
//void
//sph_sha224_comp(const sph_u32 msg[16], sph_u32 val[8])

View file

@ -208,6 +208,7 @@ void sph_sha256_comp(const sph_u32 msg[16], sph_u32 val[8]);
void sph_sha256_full( void *dst, const void *data, size_t len );
void sha256d(void* hash, const void* data, int len);
void sha256csm(void* hash, const void* data, int len);
// These shouldn't be called directly, use sha256-hash.h generic functions
// sha256_transform_le & sha256_transform_be instead.

View file

@ -94,6 +94,9 @@ bool xmrig::Rx::init(const T &seed, const RxConfig &config, const CpuConfig &cpu
# endif
# ifdef XMRIG_ALGO_GHOSTRIDER
&& (f != Algorithm::GHOSTRIDER)
# endif
# ifdef XMRIG_ALGO_SHA256CSM
&& (f != Algorithm::SHA256CSM)
# endif
) {
# ifdef XMRIG_FEATURE_MSR
@ -121,6 +124,12 @@ bool xmrig::Rx::init(const T &seed, const RxConfig &config, const CpuConfig &cpu
}
# endif
# ifdef XMRIG_ALGO_SHA256CSM
if (f == Algorithm::SHA256CSM) {
return true;
}
# endif
randomx_set_scratchpad_prefetch_mode(config.scratchpadPrefetchMode());
randomx_set_huge_pages_jit(cpu.isHugePagesJit());
randomx_set_optimized_dataset_init(config.initDatasetAVX2());

View file

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0069 NEW)
project(sha256)
#set(HEADERS
# sha2.h
#)
#set(SOURCES
# sha2.c
#)
if (CMAKE_C_COMPILER_ID MATCHES MSVC)
# set_source_files_properties(sha2.c PROPERTIES COMPILE_FLAGS "/O1 /Oi /Os")
elseif (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Clang)
# set_source_files_properties(sha2.c PROPERTIES COMPILE_FLAGS "-Os -s")
endif()
include_directories(.)
include_directories(../..)
include_directories(${UV_INCLUDE_DIR})
add_library(sha256 STATIC ${HEADERS} ${SOURCES})