From 86239498bd544406c175e2c4dea0f1e61c72e833 Mon Sep 17 00:00:00 2001 From: Markus Behm Date: Wed, 25 Apr 2018 11:08:15 +0000 Subject: [PATCH] Added support for IPBC --- CMakeLists.txt | 5 +++++ src/common/xmrig.h | 1 + src/core/ConfigLoader_platform.h | 4 ++++ src/crypto/CryptoNight_constants.h | 15 +++++++++++++++ src/crypto/CryptoNight_test.h | 14 ++++++++++++++ src/crypto/CryptoNight_x86.h | 13 +++++++++++++ src/net/Pool.cpp | 18 ++++++++++++++---- src/workers/CpuThread.cpp | 28 ++++++++++++++++++++++++++-- src/workers/MultiWorker.cpp | 12 +++++++++--- 9 files changed, 101 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7017b01..7cddadb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(xmrig) option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON) +option(WITH_IPBC "CryptoNight-IPBC support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(BUILD_STATIC "Build static binary" OFF) @@ -205,6 +206,10 @@ if (NOT WITH_SUMO) add_definitions(/DXMRIG_NO_SUMO) endif() +if (NOT WITH_IPBC) + add_definitions(/DXMRIG_NO_IPBC) +endif() + if (WITH_HTTPD) find_package(MHD) diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 0aa6b842..55289736 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -34,6 +34,7 @@ enum Algo { CRYPTONIGHT, /* CryptoNight (Monero) */ CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */ + CRYPTONIGHT_IPBC, /* CryptoNight-Lite (IPBC) */ }; diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index d02a9e8f..e0b53c25 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -53,6 +53,10 @@ Options:\n\ "\ cryptonight-heavy\n" #endif +#ifndef XMRIG_NO_IPBC +"\ + cryptonight-ipbc\n" +#endif "\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 3c746d47..3142a51a 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -47,11 +47,15 @@ constexpr const size_t CRYPTONIGHT_HEAVY_MEMORY = 4 * 1024 * 1024; constexpr const uint32_t CRYPTONIGHT_HEAVY_MASK = 0x3FFFF0; constexpr const uint32_t CRYPTONIGHT_HEAVY_ITER = 0x40000; +constexpr const size_t CRYPTONIGHT_IPBC_MEMORY = 1 * 1024 * 1024; +constexpr const uint32_t CRYPTONIGHT_IPBC_MASK = 0xFFFF0; +constexpr const uint32_t CRYPTONIGHT_IPBC_ITER = 0x40000; template inline constexpr size_t cn_select_memory() { return 0; } template<> inline constexpr size_t cn_select_memory() { return CRYPTONIGHT_MEMORY; } template<> inline constexpr size_t cn_select_memory() { return CRYPTONIGHT_LITE_MEMORY; } template<> inline constexpr size_t cn_select_memory() { return CRYPTONIGHT_HEAVY_MEMORY; } +template<> inline constexpr size_t cn_select_memory() { return CRYPTONIGHT_IPBC_MEMORY; } inline size_t cn_select_memory(Algo algorithm) { @@ -66,6 +70,9 @@ inline size_t cn_select_memory(Algo algorithm) case CRYPTONIGHT_HEAVY: return CRYPTONIGHT_HEAVY_MEMORY; + case CRYPTONIGHT_IPBC: + return CRYPTONIGHT_IPBC_MEMORY; + default: break; } @@ -78,6 +85,7 @@ template inline constexpr uint32_t cn_select_mask() { retur template<> inline constexpr uint32_t cn_select_mask() { return CRYPTONIGHT_MASK; } template<> inline constexpr uint32_t cn_select_mask() { return CRYPTONIGHT_LITE_MASK; } template<> inline constexpr uint32_t cn_select_mask() { return CRYPTONIGHT_HEAVY_MASK; } +template<> inline constexpr uint32_t cn_select_mask() { return CRYPTONIGHT_IPBC_MASK; } inline uint32_t cn_select_mask(Algo algorithm) { @@ -92,6 +100,9 @@ inline uint32_t cn_select_mask(Algo algorithm) case CRYPTONIGHT_HEAVY: return CRYPTONIGHT_HEAVY_MASK; + case CRYPTONIGHT_IPBC: + return CRYPTONIGHT_IPBC_MASK; + default: break; } @@ -104,6 +115,7 @@ template inline constexpr uint32_t cn_select_iter() { retur template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_LITE_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HEAVY_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_IPBC_ITER; } inline uint32_t cn_select_iter(Algo algorithm) { @@ -118,6 +130,9 @@ inline uint32_t cn_select_iter(Algo algorithm) case CRYPTONIGHT_HEAVY: return CRYPTONIGHT_HEAVY_ITER; + case CRYPTONIGHT_IPBC: + return CRYPTONIGHT_IPBC_ITER; + default: break; } diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 93cbf23d..e528b62a 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -130,5 +130,19 @@ const static uint8_t test_output_heavy[160] = { }; #endif +#ifndef XMRIG_NO_IPBC +const static uint8_t test_output_ipbc[160] = { + 0xe4, 0x93, 0x8c, 0xaa, 0x59, 0x8d, 0x02, 0x8a, 0xb8, 0x6f, 0x25, 0xd2, 0xb1, 0x23, 0xd0, 0xd5, + 0x33, 0xe3, 0x9f, 0x37, 0xac, 0xe5, 0xf8, 0xeb, 0x7a, 0xe8, 0x40, 0xeb, 0x5d, 0xb1, 0x35, 0x5f, + 0xb2, 0x47, 0x86, 0xf0, 0x7f, 0x6f, 0x4b, 0x55, 0x3e, 0xa1, 0xbb, 0xe8, 0xa1, 0x75, 0x00, 0x2d, + 0x07, 0x9a, 0x21, 0x0e, 0xbd, 0x06, 0x6a, 0xb0, 0xfd, 0x96, 0x9e, 0xe6, 0xe4, 0x69, 0x67, 0xbb, + 0x88, 0x45, 0x0b, 0x91, 0x0b, 0x7b, 0xcb, 0x21, 0x3c, 0x3c, 0x09, 0x30, 0x07, 0x71, 0x07, 0xd5, + 0xb8, 0x2d, 0x83, 0x09, 0xaf, 0x7e, 0xb2, 0xa8, 0xac, 0x25, 0xdc, 0x10, 0xf8, 0x63, 0x6a, 0xbc, + 0x73, 0x01, 0x4e, 0xa8, 0x1c, 0xda, 0x9a, 0x86, 0x17, 0xec, 0xa8, 0xfb, 0xaa, 0x23, 0x23, 0x17, + 0xe1, 0x32, 0x68, 0x9c, 0x4c, 0xf4, 0x08, 0xed, 0xb0, 0x15, 0xc3, 0xa9, 0x0f, 0xf0, 0xa2, 0x7e, + 0xd9, 0xe4, 0x23, 0xa7, 0x9e, 0x91, 0xd8, 0x73, 0x94, 0xd6, 0x6c, 0x70, 0x9b, 0x8b, 0x72, 0x92, + 0xa3, 0xa4, 0x0a, 0xe2, 0x3c, 0x0a, 0x34, 0x88, 0xa1, 0x6d, 0xfe, 0x02, 0x44, 0x60, 0x7b, 0x3d, +}; +#endif #endif /* __CRYPTONIGHT_TEST_H__ */ diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index e19eb2c9..e849ad9e 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -461,6 +461,9 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0; VARIANT1_2(ah0, 0); + if (ALGO == xmrig::CRYPTONIGHT_IPBC) { + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + } ah0 ^= ch; al0 ^= cl; @@ -560,6 +563,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*) &l0[idx0 & MASK])[0] = al0; ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; VARIANT1_2(ah0, 0); + if (ALGO == xmrig::CRYPTONIGHT_IPBC) { + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + } ah0 ^= ch; al0 ^= cl; @@ -585,6 +591,9 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*) &l1[idx1 & MASK])[0] = al1; ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; VARIANT1_2(ah1, 1); + if (ALGO == xmrig::CRYPTONIGHT_IPBC) { + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + } ah1 ^= ch; al1 ^= cl; @@ -648,6 +657,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si _mm_store_si128(ptr, a); \ } \ \ + if (ALGO == xmrig::CRYPTONIGHT_IPBC) { \ + ((uint64_t*)&l[idx & MASK])[1] ^= ((uint64_t*)&l[idx & MASK])[0]; \ + } \ + \ a = _mm_xor_si128(a, b); \ idx = EXTRACT64(a); \ \ diff --git a/src/net/Pool.cpp b/src/net/Pool.cpp index 2e167ebd..d1838f5e 100644 --- a/src/net/Pool.cpp +++ b/src/net/Pool.cpp @@ -45,9 +45,14 @@ static const char *algoNames[] = { nullptr, # endif # ifndef XMRIG_NO_SUMO - "cryptonight-heavy" + "cryptonight-heavy", # else - nullptr + nullptr, +# endif +# ifndef XMRIG_NO_IPBC + "cryptonight-ipbc", +# else + nullptr, # endif }; @@ -60,9 +65,14 @@ static const char *algoNamesShort[] = { nullptr, # endif # ifndef XMRIG_NO_SUMO - "cn-heavy" + "cn-heavy", # else - nullptr + nullptr, +# endif +# ifndef XMRIG_NO_IPBC + "cn-ipbc", +# else + nullptr, # endif }; diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 3632e193..dffca9af 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -64,7 +64,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a { assert(variant == VARIANT_NONE || variant == VARIANT_V1); - static const cn_hash_fun func_table[50] = { + static const cn_hash_fun func_table[80] = { cryptonight_single_hash, cryptonight_double_hash, cryptonight_single_hash, @@ -125,9 +125,28 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_triple_hash, cryptonight_quad_hash, cryptonight_penta_hash, -# else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, +# else + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif + +# ifndef XMRIG_NO_IPBC + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, +# else + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, +# endif }; # ifndef XMRIG_NO_SUMO @@ -135,6 +154,11 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a variant = VARIANT_NONE; } # endif +# ifndef XMRIG_NO_IPBC + if (algorithm == CRYPTONIGHT_IPBC) { + variant = VARIANT_V1; + } +# endif return func_table[20 * algorithm + 10 * variant + av - 1]; } diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 09dd568f..504dbde6 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -71,10 +71,16 @@ bool MultiWorker::selfTest() # endif # ifndef XMRIG_NO_SUMO - return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, sizeof m_hash) == 0; -# else - return false; + if (m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, sizeof m_hash) == 0) { + return true; + } # endif + +# ifndef XMRIG_NO_IPBC + return m_thread->algorithm() == xmrig::CRYPTONIGHT_IPBC && memcmp(m_hash, test_output_ipbc, sizeof m_hash) == 0; +# else + return false; +# endif }