From a5c311fad8b61924a2bca02baef9b124d7b4d2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Wed, 18 Apr 2018 21:50:00 +0200 Subject: [PATCH 001/188] Integrate new algo "cryptonight-lite-ipbc" (#100) --- src/Cpu.cpp | 1 + src/Mem.cpp | 1 + src/Mem_unix.cpp | 1 + src/Mem_win.cpp | 1 + src/Options.cpp | 6 + src/Options.h | 1 + src/config.json | 2 +- src/crypto/CryptoNight.cpp | 50 +- src/crypto/CryptoNight.h | 4 +- src/crypto/CryptoNight_arm.h | 873 ++++++++++++++++++++++++++ src/crypto/CryptoNight_test.h | 226 ++++--- src/crypto/CryptoNight_x86.h | 860 +++++++++++++++++++++++++ src/default_config.json | 2 +- src/net/strategies/DonateStrategy.cpp | 6 +- src/net/strategies/DonateStrategy.h | 2 +- src/version.h | 4 +- 16 files changed, 1938 insertions(+), 102 deletions(-) diff --git a/src/Cpu.cpp b/src/Cpu.cpp index ddd4642d..ddc568e7 100644 --- a/src/Cpu.cpp +++ b/src/Cpu.cpp @@ -67,6 +67,7 @@ void CpuImpl::optimizeParameters(size_t& threadsCount, size_t& hashFactor, size_t algoBlockSize; switch (algo) { case Options::ALGO_CRYPTONIGHT_LITE: + case Options::ALGO_CRYPTONIGHT_LITE_IPBC: algoBlockSize = 1024; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Mem.cpp b/src/Mem.cpp index 522deab4..871ee20a 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -44,6 +44,7 @@ cryptonight_ctx *Mem::create(int threadId) switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: + case Options::ALGO_CRYPTONIGHT_LITE_IPBC: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index b52c449b..6cae3a63 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -50,6 +50,7 @@ bool Mem::allocate(const Options* options) switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: + case Options::ALGO_CRYPTONIGHT_LITE_IPBC: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index a52cc5b5..658d0ceb 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -156,6 +156,7 @@ bool Mem::allocate(const Options* options) switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: + case Options::ALGO_CRYPTONIGHT_LITE_IPBC: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Options.cpp b/src/Options.cpp index e0d2b3b9..7a7dacf4 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -259,6 +259,7 @@ static struct option const cc_server_options[] = { static const char *algo_names[] = { "cryptonight", "cryptonight-lite", + "cryptonight-lite-ipbc", "cryptonight-heavy" }; @@ -924,6 +925,11 @@ bool Options::setAlgo(const char *algo) break; } + if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light-ipbc")) { + m_algo = ALGO_CRYPTONIGHT_LITE_IPBC; + break; + } + if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-heavy")) { m_algo = ALGO_CRYPTONIGHT_HEAVY; break; diff --git a/src/Options.h b/src/Options.h index 7824e838..bc1d7474 100644 --- a/src/Options.h +++ b/src/Options.h @@ -44,6 +44,7 @@ public: enum Algo { ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */ ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ + ALGO_CRYPTONIGHT_LITE_IPBC, /* CryptoNight-Lite-IPBC (IPBC) */ ALGO_CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (SUMO) */ }; diff --git a/src/config.json b/src/config.json index 57882604..9c73e15c 100644 --- a/src/config.json +++ b/src/config.json @@ -1,5 +1,5 @@ { - "algo": "cryptonight", // cryptonight (default), cryptonight-lite or cryptopnight-heavy + "algo": "cryptonight", // cryptonight (default), cryptonight-lite, cryptonight-lite-ipbc or cryptopnight-heavy "av": null, // DEPRECATED: algorithm variation, (0 auto, // 1 -> (aesni=1, multihash-factor=1), // 2 -> (aesni=1, multihash-factor=2), diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp index ff2f7553..0362ec91 100644 --- a/src/crypto/CryptoNight.cpp +++ b/src/crypto/CryptoNight.cpp @@ -77,6 +77,17 @@ static void cryptonight_lite_softaes(Options::PowVersion powVersion, const uint8 } } +template +static void cryptonight_lite_ipbc_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { +# if !defined(XMRIG_ARMv7) + CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hashLiteIpbc(input, size, output, ctx); +# endif +} + +template +static void cryptonight_lite_ipbc_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { + CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hashLiteIpbc(input, size, output, ctx); +} template static void cryptonight_heavy_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { @@ -112,6 +123,14 @@ void setCryptoNightHashMethods(Options::Algo algo, bool aesni) } break; + case Options::ALGO_CRYPTONIGHT_LITE_IPBC: + if (aesni) { + cryptonight_hash_ctx[HASH_FACTOR - 1] = cryptonight_lite_ipbc_aesni; + } else { + cryptonight_hash_ctx[HASH_FACTOR - 1] = cryptonight_lite_ipbc_softaes; + } + break; + case Options::ALGO_CRYPTONIGHT_HEAVY: if (aesni) { cryptonight_hash_ctx[HASH_FACTOR - 1] = cryptonight_heavy_aesni; @@ -167,6 +186,7 @@ bool CryptoNight::selfTest(int algo) bool resultV1Pow = true; bool resultV2Pow = true; + bool resultLiteIpbc = true; bool resultHeavy = true; if (algo == Options::ALGO_CRYPTONIGHT_HEAVY) { @@ -184,8 +204,32 @@ bool CryptoNight::selfTest(int algo) cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx); resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 96) == 0; #endif - } - else { + } else if (algo == Options::ALGO_CRYPTONIGHT_LITE_IPBC) { + // cn-lite-ipbc tests + + cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); + resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 32) == 0; + + #if MAX_NUM_HASH_BLOCKS > 1 + cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); + resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 64) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 2 + cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); + resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 96) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 3 + cryptonight_hash_ctx[3](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); + resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 128) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 4 + cryptonight_hash_ctx[4](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); + resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 160) == 0; + #endif + } else { // < v7 tests autodetect cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT,test_input, 76, output, ctx); resultV1Pow = resultV1Pow && @@ -248,5 +292,5 @@ bool CryptoNight::selfTest(int algo) _mm_free(ctx->memory); _mm_free(ctx); - return resultV1Pow && resultV2Pow & resultHeavy; + return resultV1Pow && resultV2Pow & resultLiteIpbc & resultHeavy; } \ No newline at end of file diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index 1baed91a..eb23d715 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -30,8 +30,8 @@ #include "Options.h" -#define MEMORY 2097152 /* 2 MiB */ -#define MEMORY_LITE 1048576 /* 1 MiB */ +#define MEMORY 2097152 /* 2 MiB */ +#define MEMORY_LITE 1048576 /* 1 MiB */ #define MEMORY_HEAVY 4194304 /* 4 MiB */ struct cryptonight_ctx { diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index fbe329dd..d5a2150a 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -732,6 +732,93 @@ public: } } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t *__restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + const uint8_t* l[NUM_HASH_BLOCKS]; + uint64_t* h[NUM_HASH_BLOCKS]; + uint64_t al[NUM_HASH_BLOCKS]; + uint64_t ah[NUM_HASH_BLOCKS]; + __m128i bx[NUM_HASH_BLOCKS]; + uint64_t idx[NUM_HASH_BLOCKS]; + uint64_t tweak1_2[NUM_HASH_BLOCKS]; + + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + keccak(static_cast(input) + hashBlock * size, (int) size, ctx->state[hashBlock], 200); + tweak1_2[hashBlock] = (*reinterpret_cast(input + 35 + hashBlock * size) ^ + *(reinterpret_cast(ctx->state[hashBlock]) + 24)); + } + + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + l[hashBlock] = ctx->memory + hashBlock * MEM; + h[hashBlock] = reinterpret_cast(ctx->state[hashBlock]); + + cn_explode_scratchpad((__m128i*) h[hashBlock], (__m128i*) l[hashBlock]); + + al[hashBlock] = h[hashBlock][0] ^ h[hashBlock][4]; + ah[hashBlock] = h[hashBlock][1] ^ h[hashBlock][5]; + bx[hashBlock] = + _mm_set_epi64x(h[hashBlock][3] ^ h[hashBlock][7], h[hashBlock][2] ^ h[hashBlock][6]); + idx[hashBlock] = h[hashBlock][0] ^ h[hashBlock][4]; + } + + for (size_t i = 0; i < ITERATIONS; i++) { + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + __m128i cx; + + if (SOFT_AES) { + cx = soft_aesenc((uint32_t*)&l[hashBlock][idx[hashBlock] & MASK], _mm_set_epi64x(ah[hashBlock], al[hashBlock])); + } else { + cx = _mm_load_si128((__m128i *) &l[hashBlock][idx[hashBlock] & MASK]); +# ifndef XMRIG_ARMv7 + cx = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah[hashBlock], al[hashBlock]); +# endif + } + + _mm_store_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK], + _mm_xor_si128(bx[hashBlock], cx)); + + const uint8_t tmp = reinterpret_cast(&l[hashBlock][idx[hashBlock] & MASK])[11]; + static const uint32_t table = 0x75310; + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l[hashBlock][idx[hashBlock] & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx[hashBlock] = EXTRACT64(cx); + bx[hashBlock] = cx; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[0]; + ch = ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[1]; + lo = __umul128(idx[hashBlock], cl, &hi); + + al[hashBlock] += hi; + ah[hashBlock] += lo; + + ah[hashBlock] ^= tweak1_2[hashBlock]; + + ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[0] = al[hashBlock]; + ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[1] = ah[hashBlock]; + + ah[hashBlock] ^= tweak1_2[hashBlock]; + + ((uint64_t*)&l[hashBlock][idx[hashBlock] & MASK])[1] ^= ((uint64_t*)&l[hashBlock][idx[hashBlock] & MASK])[0]; + + ah[hashBlock] ^= ch; + al[hashBlock] ^= cl; + idx[hashBlock] = al[hashBlock]; + } + } + + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + cn_implode_scratchpad((__m128i*) l[hashBlock], (__m128i*) h[hashBlock]); + keccakf(h[hashBlock], 24); + extra_hashes[ctx->state[hashBlock][0] & 3](ctx->state[hashBlock], 200, + output + hashBlock * 32); + } + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t *__restrict__ output, @@ -949,6 +1036,78 @@ public: extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t *__restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + const uint8_t* l; + uint64_t* h; + uint64_t al; + uint64_t ah; + __m128i bx; + uint64_t idx; + + keccak(static_cast(input), (int) size, ctx->state[0], 200); + + uint64_t tweak1_2 = (*reinterpret_cast(input + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + l = ctx->memory; + h = reinterpret_cast(ctx->state[0]); + + cn_explode_scratchpad((__m128i*) h, (__m128i*) l); + + al = h[0] ^ h[4]; + ah = h[1] ^ h[5]; + bx = _mm_set_epi64x(h[3] ^ h[7], h[2] ^ h[6]); + idx = h[0] ^ h[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx; + + if (SOFT_AES) { + cx = soft_aesenc((uint32_t*)&l[idx & MASK], _mm_set_epi64x(ah, al)); + } + else { + cx = _mm_load_si128((__m128i *) &l[idx & MASK]); +# ifndef XMRIG_ARMv7 + cx = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah, al); +# endif + } + + _mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx)); + const uint8_t tmp = reinterpret_cast(&l[idx & MASK])[11]; + static const uint32_t table = 0x75310; + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l[idx & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + idx = EXTRACT64(cx); + bx = cx; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l[idx & MASK])[0]; + ch = ((uint64_t*) &l[idx & MASK])[1]; + lo = __umul128(idx, cl, &hi); + + al += hi; + ah += lo; + + ah ^= tweak1_2; + ((uint64_t*) &l[idx & MASK])[0] = al; + ((uint64_t*) &l[idx & MASK])[1] = ah; + ah ^= tweak1_2; + + ((uint64_t*)&l[idx & MASK])[1] ^= ((uint64_t*)&l[idx & MASK])[0]; + + ah ^= ch; + al ^= cl; + idx = al; + } + + cn_implode_scratchpad((__m128i*) l, (__m128i*) h); + keccakf(h, 24); + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t *__restrict__ output, @@ -1226,6 +1385,120 @@ public: extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t *__restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak(input, (int) size, ctx->state[0], 200); + keccak(input + size, (int) size, ctx->state[1], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(input + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(input + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + } else { + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + +# ifndef XMRIG_ARMv7 + cx0 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx0, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah0, al0); + cx1 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx1, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah1, al1); +# endif + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + + bx0 = cx0; + bx1 = cx1; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + + keccakf(h0, 24); + keccakf(h1, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t *__restrict__ output, @@ -1618,6 +1891,164 @@ public: extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t *__restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak(input, (int) size, ctx->state[0], 200); + keccak(input + size, (int) size, ctx->state[1], 200); + keccak(input + 2 * size, (int) size, ctx->state[2], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(input + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(input + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + uint64_t tweak1_2_2 = (*reinterpret_cast(input + 35 + 2 * size) ^ + *(reinterpret_cast(ctx->state[2]) + 24)); + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + const uint8_t* l2 = ctx->memory + 2 * MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + uint64_t* h2 = reinterpret_cast(ctx->state[2]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + cn_explode_scratchpad((__m128i*) h2, (__m128i*) l2); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t al2 = h2[0] ^h2[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + uint64_t ah2 = h2[1] ^h2[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + uint64_t idx2 = h2[0] ^h2[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + __m128i cx2; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx2 = soft_aesenc((uint32_t*)&l2[idx2 & MASK], _mm_set_epi64x(ah2, al2)); + } + else { + cx0 = _mm_load_si128((__m128i *) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i *) &l1[idx1 & MASK]); + cx2 = _mm_load_si128((__m128i *) &l2[idx2 & MASK]); +# ifndef XMRIG_ARMv7 + cx0 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx0, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah0, al0); + cx1 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx1, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah1, al1); + cx2 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx2, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah2, al2); +# endif + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + idx2 = EXTRACT64(cx2); + + bx0 = cx0; + bx1 = cx1; + bx2 = cx2; + + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + + + cl = ((uint64_t*) &l2[idx2 & MASK])[0]; + ch = ((uint64_t*) &l2[idx2 & MASK])[1]; + lo = __umul128(idx2, cl, &hi); + + al2 += hi; + ah2 += lo; + + ah2 ^= tweak1_2_2; + ((uint64_t*) &l2[idx2 & MASK])[0] = al2; + ((uint64_t*) &l2[idx2 & MASK])[1] = ah2; + ah2 ^= tweak1_2_2; + + ((uint64_t*)&l2[idx2 & MASK])[1] ^= ((uint64_t*)&l2[idx2 & MASK])[0]; + + ah2 ^= ch; + al2 ^= cl; + idx2 = al2; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + cn_implode_scratchpad((__m128i*) l2, (__m128i*) h2); + + keccakf(h0, 24); + keccakf(h1, 24); + keccakf(h2, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t *__restrict__ output, @@ -2125,6 +2556,206 @@ public: extra_hashes[ctx->state[3][0] & 3](ctx->state[3], 200, output + 96); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t *__restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak(input, (int) size, ctx->state[0], 200); + keccak(input + size, (int) size, ctx->state[1], 200); + keccak(input + 2 * size, (int) size, ctx->state[2], 200); + keccak(input + 3 * size, (int) size, ctx->state[3], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(input + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(input + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + uint64_t tweak1_2_2 = (*reinterpret_cast(input + 35 + 2 * size) ^ + *(reinterpret_cast(ctx->state[2]) + 24)); + uint64_t tweak1_2_3 = (*reinterpret_cast(input + 35 + 3 * size) ^ + *(reinterpret_cast(ctx->state[3]) + 24)); + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + const uint8_t* l2 = ctx->memory + 2 * MEM; + const uint8_t* l3 = ctx->memory + 3 * MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + uint64_t* h2 = reinterpret_cast(ctx->state[2]); + uint64_t* h3 = reinterpret_cast(ctx->state[3]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + cn_explode_scratchpad((__m128i*) h2, (__m128i*) l2); + cn_explode_scratchpad((__m128i*) h3, (__m128i*) l3); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t al2 = h2[0] ^h2[4]; + uint64_t al3 = h3[0] ^h3[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + uint64_t ah2 = h2[1] ^h2[5]; + uint64_t ah3 = h3[1] ^h3[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); + __m128i bx3 = _mm_set_epi64x(h3[3] ^ h3[7], h3[2] ^ h3[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + uint64_t idx2 = h2[0] ^h2[4]; + uint64_t idx3 = h3[0] ^h3[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + __m128i cx2; + __m128i cx3; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx2 = soft_aesenc((uint32_t*)&l2[idx2 & MASK], _mm_set_epi64x(ah2, al2)); + cx3 = soft_aesenc((uint32_t*)&l3[idx3 & MASK], _mm_set_epi64x(ah3, al3)); + } else { +# ifndef XMRIG_ARMv7 + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + cx2 = _mm_load_si128((__m128i*) &l2[idx2 & MASK]); + cx3 = _mm_load_si128((__m128i*) &l3[idx3 & MASK]); + + cx0 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx0, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah0, al0); + cx1 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx1, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah1, al1); + cx2 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx2, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah2, al2); + cx3 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx3, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah3, al3); +# endif + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2)); + _mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + idx2 = EXTRACT64(cx2); + idx3 = EXTRACT64(cx3); + + bx0 = cx0; + bx1 = cx1; + bx2 = cx2; + bx3 = cx3; + + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + + + cl = ((uint64_t*) &l2[idx2 & MASK])[0]; + ch = ((uint64_t*) &l2[idx2 & MASK])[1]; + lo = __umul128(idx2, cl, &hi); + + al2 += hi; + ah2 += lo; + + ah2 ^= tweak1_2_2; + ((uint64_t*) &l2[idx2 & MASK])[0] = al2; + ((uint64_t*) &l2[idx2 & MASK])[1] = ah2; + ah2 ^= tweak1_2_2; + + ((uint64_t*)&l2[idx2 & MASK])[1] ^= ((uint64_t*)&l2[idx2 & MASK])[0]; + + ah2 ^= ch; + al2 ^= cl; + idx2 = al2; + + + cl = ((uint64_t*) &l3[idx3 & MASK])[0]; + ch = ((uint64_t*) &l3[idx3 & MASK])[1]; + lo = __umul128(idx3, cl, &hi); + + al3 += hi; + ah3 += lo; + + ah3 ^= tweak1_2_3; + ((uint64_t*) &l3[idx3 & MASK])[0] = al3; + ((uint64_t*) &l3[idx3 & MASK])[1] = ah3; + ah3 ^= tweak1_2_3; + + ((uint64_t*)&l3[idx3 & MASK])[1] ^= ((uint64_t*)&l3[idx3 & MASK])[0]; + + ah3 ^= ch; + al3 ^= cl; + idx3 = al3; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + cn_implode_scratchpad((__m128i*) l2, (__m128i*) h2); + cn_implode_scratchpad((__m128i*) l3, (__m128i*) h3); + + keccakf(h0, 24); + keccakf(h1, 24); + keccakf(h2, 24); + keccakf(h3, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); + extra_hashes[ctx->state[3][0] & 3](ctx->state[3], 200, output + 96); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t *__restrict__ output, @@ -2744,6 +3375,248 @@ public: extra_hashes[ctx->state[4][0] & 3](ctx->state[4], 200, output + 128); } + inline static void hashLiteIpbc (const uint8_t* __restrict__ input, + size_t size, + uint8_t *__restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak(input, (int) size, ctx->state[0], 200); + keccak(input + size, (int) size, ctx->state[1], 200); + keccak(input + 2 * size, (int) size, ctx->state[2], 200); + keccak(input + 3 * size, (int) size, ctx->state[3], 200); + keccak(input + 4 * size, (int) size, ctx->state[4], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(input + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(input + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + uint64_t tweak1_2_2 = (*reinterpret_cast(input + 35 + 2 * size) ^ + *(reinterpret_cast(ctx->state[2]) + 24)); + uint64_t tweak1_2_3 = (*reinterpret_cast(input + 35 + 3 * size) ^ + *(reinterpret_cast(ctx->state[3]) + 24)); + uint64_t tweak1_2_4 = (*reinterpret_cast(input + 35 + 4 * size) ^ + *(reinterpret_cast(ctx->state[4]) + 24)); + + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + const uint8_t* l2 = ctx->memory + 2 * MEM; + const uint8_t* l3 = ctx->memory + 3 * MEM; + const uint8_t* l4 = ctx->memory + 4 * MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + uint64_t* h2 = reinterpret_cast(ctx->state[2]); + uint64_t* h3 = reinterpret_cast(ctx->state[3]); + uint64_t* h4 = reinterpret_cast(ctx->state[4]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + cn_explode_scratchpad((__m128i*) h2, (__m128i*) l2); + cn_explode_scratchpad((__m128i*) h3, (__m128i*) l3); + cn_explode_scratchpad((__m128i*) h4, (__m128i*) l4); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t al2 = h2[0] ^h2[4]; + uint64_t al3 = h3[0] ^h3[4]; + uint64_t al4 = h4[0] ^h4[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + uint64_t ah2 = h2[1] ^h2[5]; + uint64_t ah3 = h3[1] ^h3[5]; + uint64_t ah4 = h4[1] ^h4[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); + __m128i bx3 = _mm_set_epi64x(h3[3] ^ h3[7], h3[2] ^ h3[6]); + __m128i bx4 = _mm_set_epi64x(h4[3] ^ h4[7], h4[2] ^ h4[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + uint64_t idx2 = h2[0] ^h2[4]; + uint64_t idx3 = h3[0] ^h3[4]; + uint64_t idx4 = h4[0] ^h4[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + __m128i cx2; + __m128i cx3; + __m128i cx4; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx2 = soft_aesenc((uint32_t*)&l2[idx2 & MASK], _mm_set_epi64x(ah2, al2)); + cx3 = soft_aesenc((uint32_t*)&l3[idx3 & MASK], _mm_set_epi64x(ah3, al3)); + cx4 = soft_aesenc((uint32_t*)&l4[idx4 & MASK], _mm_set_epi64x(ah4, al4)); + } else { +# ifndef XMRIG_ARMv7 + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + cx2 = _mm_load_si128((__m128i*) &l2[idx2 & MASK]); + cx3 = _mm_load_si128((__m128i*) &l3[idx3 & MASK]); + cx4 = _mm_load_si128((__m128i*) &l4[idx4 & MASK]); + + cx0 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx0, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah0, al0); + cx1 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx1, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah1, al1); + cx2 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx2, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah2, al2); + cx3 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx3, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah3, al3); + cx4 = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx4, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah4, al4); +# endif + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2)); + _mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3)); + _mm_store_si128((__m128i*) &l4[idx4 & MASK], _mm_xor_si128(bx4, cx4)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l4[idx4 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l4[idx4 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + idx2 = EXTRACT64(cx2); + idx3 = EXTRACT64(cx3); + idx4 = EXTRACT64(cx4); + + bx0 = cx0; + bx1 = cx1; + bx2 = cx2; + bx3 = cx3; + bx4 = cx4; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + + + cl = ((uint64_t*) &l2[idx2 & MASK])[0]; + ch = ((uint64_t*) &l2[idx2 & MASK])[1]; + lo = __umul128(idx2, cl, &hi); + + al2 += hi; + ah2 += lo; + + ah2 ^= tweak1_2_2; + ((uint64_t*) &l2[idx2 & MASK])[0] = al2; + ((uint64_t*) &l2[idx2 & MASK])[1] = ah2; + ah2 ^= tweak1_2_2; + + ((uint64_t*)&l2[idx2 & MASK])[1] ^= ((uint64_t*)&l2[idx2 & MASK])[0]; + + ah2 ^= ch; + al2 ^= cl; + idx2 = al2; + + + cl = ((uint64_t*) &l3[idx3 & MASK])[0]; + ch = ((uint64_t*) &l3[idx3 & MASK])[1]; + lo = __umul128(idx3, cl, &hi); + + al3 += hi; + ah3 += lo; + + ah3 ^= tweak1_2_3; + ((uint64_t*) &l3[idx3 & MASK])[0] = al3; + ((uint64_t*) &l3[idx3 & MASK])[1] = ah3; + ah3 ^= tweak1_2_3; + + ((uint64_t*)&l3[idx3 & MASK])[1] ^= ((uint64_t*)&l3[idx3 & MASK])[0]; + + ah3 ^= ch; + al3 ^= cl; + idx3 = al3; + + + cl = ((uint64_t*) &l4[idx4 & MASK])[0]; + ch = ((uint64_t*) &l4[idx4 & MASK])[1]; + lo = __umul128(idx4, cl, &hi); + + al4 += hi; + ah4 += lo; + + ah4 ^= tweak1_2_4; + ((uint64_t*) &l4[idx4 & MASK])[0] = al4; + ((uint64_t*) &l4[idx4 & MASK])[1] = ah4; + ah4 ^= tweak1_2_4; + + ((uint64_t*)&l4[idx4 & MASK])[1] ^= ((uint64_t*)&l4[idx4 & MASK])[0]; + + ah4 ^= ch; + al4 ^= cl; + idx4 = al4; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + cn_implode_scratchpad((__m128i*) l2, (__m128i*) h2); + cn_implode_scratchpad((__m128i*) l3, (__m128i*) h3); + cn_implode_scratchpad((__m128i*) l4, (__m128i*) h4); + + keccakf(h0, 24); + keccakf(h1, 24); + keccakf(h2, 24); + keccakf(h3, 24); + keccakf(h4, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); + extra_hashes[ctx->state[3][0] & 3](ctx->state[3], 200, output + 96); + extra_hashes[ctx->state[4][0] & 3](ctx->state[4], 200, output + 128); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t *__restrict__ output, diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 3c103693..b9c735f4 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -26,130 +26,174 @@ const static uint8_t test_input[] = { - 0x01, 0x00, 0xFB, 0x8E, 0x8A, 0xC8, 0x05, 0x89, 0x93, 0x23, 0x37, 0x1B, 0xB7, 0x90, 0xDB, 0x19, - 0x21, 0x8A, 0xFD, 0x8D, 0xB8, 0xE3, 0x75, 0x5D, 0x8B, 0x90, 0xF3, 0x9B, 0x3D, 0x55, 0x06, 0xA9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, 0xFB, 0x8E, 0x8A, 0xC8, 0x05, 0x89, 0x93, 0x23, 0x37, 0x1B, 0xB7, 0x90, 0xDB, 0x19, + 0x21, 0x8A, 0xFD, 0x8D, 0xB8, 0xE3, 0x75, 0x5D, 0x8B, 0x90, 0xF3, 0x9B, 0x3D, 0x55, 0x06, 0xA9, + 0xAB, 0xCE, 0x4F, 0xA9, 0x12, 0x24, 0x45, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x81, 0x46, 0xD4, 0x9F, + 0xA9, 0x3E, 0xE7, 0x24, 0xDE, 0xB5, 0x7D, 0x12, 0xCB, 0xC6, 0xC6, 0xF3, 0xB9, 0x24, 0xD9, 0x46, + 0x12, 0x7C, 0x7A, 0x97, 0x41, 0x8F, 0x93, 0x48, 0x82, 0x8F, 0x0F, 0x02, + 0x03, 0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00, + 0x7C, 0xBF, 0x34, 0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B, + 0x30, 0x9A, 0xCE, 0x19, 0x23, 0xA0, 0x96, 0x4B, 0x00, 0x00, 0x00, 0x08, 0xBA, 0x93, 0x9A, 0x62, + 0x72, 0x4C, 0x0D, 0x75, 0x81, 0xFC, 0xE5, 0x76, 0x1E, 0x9D, 0x8A, 0x0E, 0x6A, 0x1C, 0x3F, 0x92, + 0x4F, 0xDD, 0x84, 0x93, 0xD1, 0x11, 0x56, 0x49, 0xC0, 0x5E, 0xB6, 0x01 }; const static uint8_t test_output[] = { - 0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66, - 0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52,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 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F, + 0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7, + 0x1B, 0x31, 0x10, 0xD8, 0x86, 0x01, 0x1E, 0x87, 0x7E, 0xE5, 0x78, 0x6A, 0xFD, 0x08, 0x01, 0x00, - 0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66, - 0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F, - 0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7, - 0x1B, 0x31, 0x10, 0xD8, 0x86, 0x01, 0x1E, 0x87, 0x7E, 0xE5, 0x78, 0x6A, 0xFD, 0x08, 0x01, 0x00 + 0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66, + 0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F, + 0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7, + 0x1B, 0x31, 0x10, 0xD8, 0x86, 0x01, 0x1E, 0x87, 0x7E, 0xE5, 0x78, 0x6A, 0xFD, 0x08, 0x01, 0x00 }; const static uint8_t test_output_light[] = { - 0x28, 0xA2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 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, + 0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88 }; const static uint8_t test_input_monero_v2_pow_0[] = { - 0x85, 0x19, 0xe0, 0x39, 0x17, 0x2b, 0x0d, 0x70, 0xe5, 0xca, 0x7b, 0x33, 0x83, 0xd6, 0xb3, 0x16, - 0x73, 0x15, 0xa4, 0x22, 0x74, 0x7b, 0x73, 0xf0, 0x19, 0xcf, 0x95, 0x28, 0xf0, 0xfd, 0xe3, 0x41, - 0xfd, 0x0f, 0x2a, 0x63, 0x03, 0x0b, 0xa6, 0x45, 0x05, 0x25, 0xcf, 0x6d, 0xe3, 0x18, 0x37, 0x66, - 0x9a, 0xf6, 0xf1, 0xdf, 0x81, 0x31, 0xfa, 0xf5, 0x0a, 0xaa, 0xb8, 0xd3, 0xa7, 0x40, 0x55, 0x89 + 0x85, 0x19, 0xe0, 0x39, 0x17, 0x2b, 0x0d, 0x70, 0xe5, 0xca, 0x7b, 0x33, 0x83, 0xd6, 0xb3, 0x16, + 0x73, 0x15, 0xa4, 0x22, 0x74, 0x7b, 0x73, 0xf0, 0x19, 0xcf, 0x95, 0x28, 0xf0, 0xfd, 0xe3, 0x41, + 0xfd, 0x0f, 0x2a, 0x63, 0x03, 0x0b, 0xa6, 0x45, 0x05, 0x25, 0xcf, 0x6d, 0xe3, 0x18, 0x37, 0x66, + 0x9a, 0xf6, 0xf1, 0xdf, 0x81, 0x31, 0xfa, 0xf5, 0x0a, 0xaa, 0xb8, 0xd3, 0xa7, 0x40, 0x55, 0x89 }; const static uint8_t test_input_monero_v2_pow_1[] = { - 0x37, 0xa6, 0x36, 0xd7, 0xda, 0xfd, 0xf2, 0x59, 0xb7, 0x28, 0x7e, 0xdd, 0xca, 0x2f, 0x58, 0x09, - 0x9e, 0x98, 0x61, 0x9d, 0x2f, 0x99, 0xbd, 0xb8, 0x96, 0x9d, 0x7b, 0x14, 0x49, 0x81, 0x02, 0xcc, - 0x06, 0x52, 0x01, 0xc8, 0xbe, 0x90, 0xbd, 0x77, 0x73, 0x23, 0xf4, 0x49, 0x84, 0x8b, 0x21, 0x5d, - 0x29, 0x77, 0xc9, 0x2c, 0x4c, 0x1c, 0x2d, 0xa3, 0x6a, 0xb4, 0x6b, 0x2e, 0x38, 0x96, 0x89, 0xed, - 0x97, 0xc1, 0x8f, 0xec, 0x08, 0xcd, 0x3b, 0x03, 0x23, 0x5c, 0x5e, 0x4c, 0x62, 0xa3, 0x7a, 0xd8, - 0x8c, 0x7b, 0x67, 0x93, 0x24, 0x95, 0xa7, 0x10, 0x90, 0xe8, 0x5d, 0xd4, 0x02, 0x0a, 0x93, 0x00 + 0x37, 0xa6, 0x36, 0xd7, 0xda, 0xfd, 0xf2, 0x59, 0xb7, 0x28, 0x7e, 0xdd, 0xca, 0x2f, 0x58, 0x09, + 0x9e, 0x98, 0x61, 0x9d, 0x2f, 0x99, 0xbd, 0xb8, 0x96, 0x9d, 0x7b, 0x14, 0x49, 0x81, 0x02, 0xcc, + 0x06, 0x52, 0x01, 0xc8, 0xbe, 0x90, 0xbd, 0x77, 0x73, 0x23, 0xf4, 0x49, 0x84, 0x8b, 0x21, 0x5d, + 0x29, 0x77, 0xc9, 0x2c, 0x4c, 0x1c, 0x2d, 0xa3, 0x6a, 0xb4, 0x6b, 0x2e, 0x38, 0x96, 0x89, 0xed, + 0x97, 0xc1, 0x8f, 0xec, 0x08, 0xcd, 0x3b, 0x03, 0x23, 0x5c, 0x5e, 0x4c, 0x62, 0xa3, 0x7a, 0xd8, + 0x8c, 0x7b, 0x67, 0x93, 0x24, 0x95, 0xa7, 0x10, 0x90, 0xe8, 0x5d, 0xd4, 0x02, 0x0a, 0x93, 0x00 }; const static uint8_t test_input_monero_v2_pow_2[] = { - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb }; const static uint8_t test_output_monero_v2_pow[3][32] = { - {0x5b, 0xb4, 0x0c, 0x58, 0x80, 0xce, 0xf2, 0xf7, 0x39, 0xbd, 0xb6, 0xaa, 0xaf, 0x16, 0x16, 0x1e, - 0xaa, 0xe5, 0x55, 0x30, 0xe7, 0xb1, 0x0d, 0x7e, 0xa9, 0x96, 0xb7, 0x51, 0xa2, 0x99, 0xe9, 0x49}, - {0x61, 0x3e, 0x63, 0x85, 0x05, 0xba, 0x1f, 0xd0, 0x5f, 0x42, 0x8d, 0x5c, 0x9f, 0x8e, 0x08, 0xf8, - 0x16, 0x56, 0x14, 0x34, 0x2d, 0xac, 0x41, 0x9a, 0xdc, 0x6a, 0x47, 0xdc, 0xe2, 0x57, 0xeb, 0x3e}, - {0xed, 0x08, 0x2e, 0x49, 0xdb, 0xd5, 0xbb, 0xe3, 0x4a, 0x37, 0x26, 0xa0, 0xd1, 0xda, 0xd9, 0x81, - 0x14, 0x60, 0x62, 0xb3, 0x9d, 0x36, 0xd6, 0x2c, 0x71, 0xeb, 0x1e, 0xd8, 0xab, 0x49, 0x45, 0x9b} + {0x5b, 0xb4, 0x0c, 0x58, 0x80, 0xce, 0xf2, 0xf7, 0x39, 0xbd, 0xb6, 0xaa, 0xaf, 0x16, 0x16, 0x1e, + 0xaa, 0xe5, 0x55, 0x30, 0xe7, 0xb1, 0x0d, 0x7e, 0xa9, 0x96, 0xb7, 0x51, 0xa2, 0x99, 0xe9, 0x49}, + {0x61, 0x3e, 0x63, 0x85, 0x05, 0xba, 0x1f, 0xd0, 0x5f, 0x42, 0x8d, 0x5c, 0x9f, 0x8e, 0x08, 0xf8, + 0x16, 0x56, 0x14, 0x34, 0x2d, 0xac, 0x41, 0x9a, 0xdc, 0x6a, 0x47, 0xdc, 0xe2, 0x57, 0xeb, 0x3e}, + {0xed, 0x08, 0x2e, 0x49, 0xdb, 0xd5, 0xbb, 0xe3, 0x4a, 0x37, 0x26, 0xa0, 0xd1, 0xda, 0xd9, 0x81, + 0x14, 0x60, 0x62, 0xb3, 0x9d, 0x36, 0xd6, 0x2c, 0x71, 0xeb, 0x1e, 0xd8, 0xab, 0x49, 0x45, 0x9b} }; const static uint8_t test_output_monero_v2_pow_light[3][32] = { - {0xbb, 0x19, 0x6c, 0x4c, 0x0c, 0x9d, 0xc1, 0xc4, 0xe4, 0x4c, 0x2a, 0x6f, 0x9e, 0x61, 0x20, 0x0f, - 0xe3, 0xc8, 0xb4, 0xef, 0x23, 0x21, 0x34, 0xe6, 0x5c, 0x3c, 0x78, 0x62, 0xc7, 0xd3, 0xdf, 0x6a}, - {0x45, 0x21, 0x03, 0x73, 0x1d, 0xd8, 0xd7, 0x0c, 0xe3, 0x2f, 0x72, 0x6b, 0x8e, 0x71, 0xfc, 0xd9, - 0x10, 0x05, 0xfb, 0x3c, 0xb2, 0xab, 0xd7, 0x8f, 0x2b, 0x73, 0x57, 0xbb, 0x07, 0xf8, 0xc8, 0xbc}, - {0x4e, 0x78, 0x53, 0x76, 0xed, 0x27, 0x33, 0x26, 0x2d, 0x83, 0xcc, 0x25, 0x32, 0x1a, 0x9d, 0x00, - 0x03, 0xf5, 0x39, 0x53, 0x15, 0xde, 0x91, 0x9a, 0xcf, 0x1b, 0x97, 0xf0, 0xa8, 0x4f, 0xbd, 0x2d} + {0xbb, 0x19, 0x6c, 0x4c, 0x0c, 0x9d, 0xc1, 0xc4, 0xe4, 0x4c, 0x2a, 0x6f, 0x9e, 0x61, 0x20, 0x0f, + 0xe3, 0xc8, 0xb4, 0xef, 0x23, 0x21, 0x34, 0xe6, 0x5c, 0x3c, 0x78, 0x62, 0xc7, 0xd3, 0xdf, 0x6a}, + {0x45, 0x21, 0x03, 0x73, 0x1d, 0xd8, 0xd7, 0x0c, 0xe3, 0x2f, 0x72, 0x6b, 0x8e, 0x71, 0xfc, 0xd9, + 0x10, 0x05, 0xfb, 0x3c, 0xb2, 0xab, 0xd7, 0x8f, 0x2b, 0x73, 0x57, 0xbb, 0x07, 0xf8, 0xc8, 0xbc}, + {0x4e, 0x78, 0x53, 0x76, 0xed, 0x27, 0x33, 0x26, 0x2d, 0x83, 0xcc, 0x25, 0x32, 0x1a, 0x9d, 0x00, + 0x03, 0xf5, 0x39, 0x53, 0x15, 0xde, 0x91, 0x9a, 0xcf, 0x1b, 0x97, 0xf0, 0xa8, 0x4f, 0xbd, 0x2d} +}; + +const static uint8_t test_input_lite_ipbc[] = { + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, + + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, + + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, + + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, + + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, + + 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, + 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, + 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb +}; + + +const static uint8_t test_output_lite_ipbc[] = { + 0xb4, 0x42, 0xa2, 0xb9, 0x56, 0xe6, 0x3f, 0xef, 0xe8, 0x1b, 0xfa, 0x8b, 0xcb, 0xc4, 0xdd, 0xd6, 0xb6, 0x3f, + 0x86, 0x53, 0x0e, 0xea, 0xa4, 0x65, 0x88, 0x31, 0x1d, 0x29, 0x0a, 0xfb, 0xb2, 0xc0, + + 0xb4, 0x42, 0xa2, 0xb9, 0x56, 0xe6, 0x3f, 0xef, 0xe8, 0x1b, 0xfa, 0x8b, 0xcb, 0xc4, 0xdd, 0xd6, 0xb6, 0x3f, + 0x86, 0x53, 0x0e, 0xea, 0xa4, 0x65, 0x88, 0x31, 0x1d, 0x29, 0x0a, 0xfb, 0xb2, 0xc0, + + 0xb4, 0x42, 0xa2, 0xb9, 0x56, 0xe6, 0x3f, 0xef, 0xe8, 0x1b, 0xfa, 0x8b, 0xcb, 0xc4, 0xdd, 0xd6, 0xb6, 0x3f, + 0x86, 0x53, 0x0e, 0xea, 0xa4, 0x65, 0x88, 0x31, 0x1d, 0x29, 0x0a, 0xfb, 0xb2, 0xc0, + + 0xb4, 0x42, 0xa2, 0xb9, 0x56, 0xe6, 0x3f, 0xef, 0xe8, 0x1b, 0xfa, 0x8b, 0xcb, 0xc4, 0xdd, 0xd6, 0xb6, 0x3f, + 0x86, 0x53, 0x0e, 0xea, 0xa4, 0x65, 0x88, 0x31, 0x1d, 0x29, 0x0a, 0xfb, 0xb2, 0xc0, + + 0xb4, 0x42, 0xa2, 0xb9, 0x56, 0xe6, 0x3f, 0xef, 0xe8, 0x1b, 0xfa, 0x8b, 0xcb, 0xc4, 0xdd, 0xd6, 0xb6, 0x3f, + 0x86, 0x53, 0x0e, 0xea, 0xa4, 0x65, 0x88, 0x31, 0x1d, 0x29, 0x0a, 0xfb, 0xb2, 0xc0 }; const static uint8_t test_output_heavy[] = { - 0x4D, 0x94, 0x7D, 0x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14, 0xD7, 0x86, 0x64, + 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2 }; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 4e602e7e..18488bff 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -626,6 +626,91 @@ public: } } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t* __restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + const uint8_t* l[NUM_HASH_BLOCKS]; + uint64_t* h[NUM_HASH_BLOCKS]; + uint64_t al[NUM_HASH_BLOCKS]; + uint64_t ah[NUM_HASH_BLOCKS]; + __m128i bx[NUM_HASH_BLOCKS]; + uint64_t idx[NUM_HASH_BLOCKS]; + uint64_t tweak1_2[NUM_HASH_BLOCKS]; + + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + keccak(static_cast(input) + hashBlock * size, (int) size, ctx->state[hashBlock], 200); + tweak1_2[hashBlock] = (*reinterpret_cast(reinterpret_cast(input) + 35 + hashBlock * size) ^ + *(reinterpret_cast(ctx->state[hashBlock]) + 24)); + } + + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + l[hashBlock] = ctx->memory + hashBlock * MEM; + h[hashBlock] = reinterpret_cast(ctx->state[hashBlock]); + + cn_explode_scratchpad((__m128i*) h[hashBlock], (__m128i*) l[hashBlock]); + + al[hashBlock] = h[hashBlock][0] ^ h[hashBlock][4]; + ah[hashBlock] = h[hashBlock][1] ^ h[hashBlock][5]; + bx[hashBlock] = + _mm_set_epi64x(h[hashBlock][3] ^ h[hashBlock][7], h[hashBlock][2] ^ h[hashBlock][6]); + idx[hashBlock] = h[hashBlock][0] ^ h[hashBlock][4]; + } + + for (size_t i = 0; i < ITERATIONS; i++) { + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + __m128i cx; + + if (SOFT_AES) { + cx = soft_aesenc((uint32_t*) &l[hashBlock][idx[hashBlock] & MASK], _mm_set_epi64x(ah[hashBlock], al[hashBlock])); + } else { + cx = _mm_load_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK]); + cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah[hashBlock], al[hashBlock])); + } + + _mm_store_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK], + _mm_xor_si128(bx[hashBlock], cx)); + + const uint8_t tmp = reinterpret_cast(&l[hashBlock][idx[hashBlock] & MASK])[11]; + static const uint32_t table = 0x75310; + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l[hashBlock][idx[hashBlock] & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx[hashBlock] = EXTRACT64(cx); + bx[hashBlock] = cx; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[0]; + ch = ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[1]; + lo = __umul128(idx[hashBlock], cl, &hi); + + al[hashBlock] += hi; + ah[hashBlock] += lo; + + ah[hashBlock] ^= tweak1_2[hashBlock]; + + ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[0] = al[hashBlock]; + ((uint64_t*) &l[hashBlock][idx[hashBlock] & MASK])[1] = ah[hashBlock]; + + ah[hashBlock] ^= tweak1_2[hashBlock]; + + ((uint64_t*)&l[hashBlock][idx[hashBlock] & MASK])[1] ^= ((uint64_t*)&l[hashBlock][idx[hashBlock] & MASK])[0]; + + ah[hashBlock] ^= ch; + al[hashBlock] ^= cl; + idx[hashBlock] = al[hashBlock]; + } + } + + for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) { + cn_implode_scratchpad((__m128i*) l[hashBlock], (__m128i*) h[hashBlock]); + keccakf(h[hashBlock], 24); + extra_hashes[ctx->state[hashBlock][0] & 3](ctx->state[hashBlock], 200, + output + hashBlock * 32); + } + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t* __restrict__ output, @@ -835,6 +920,75 @@ public: extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t* __restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + const uint8_t* l; + uint64_t* h; + uint64_t al; + uint64_t ah; + __m128i bx; + uint64_t idx; + + keccak(static_cast(input), (int) size, ctx->state[0], 200); + + uint64_t tweak1_2 = (*reinterpret_cast(reinterpret_cast(input) + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + l = ctx->memory; + h = reinterpret_cast(ctx->state[0]); + + cn_explode_scratchpad((__m128i*) h, (__m128i*) l); + + al = h[0] ^ h[4]; + ah = h[1] ^ h[5]; + bx = _mm_set_epi64x(h[3] ^ h[7], h[2] ^ h[6]); + idx = h[0] ^ h[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx; + + if (SOFT_AES) { + cx = soft_aesenc((uint32_t*)&l[idx & MASK], _mm_set_epi64x(ah, al)); + } else { + cx = _mm_load_si128((__m128i*) &l[idx & MASK]); + cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah, al)); + } + + _mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx)); + const uint8_t tmp = reinterpret_cast(&l[idx & MASK])[11]; + static const uint32_t table = 0x75310; + const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l[idx & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + idx = EXTRACT64(cx); + bx = cx; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l[idx & MASK])[0]; + ch = ((uint64_t*) &l[idx & MASK])[1]; + lo = __umul128(idx, cl, &hi); + + al += hi; + ah += lo; + + ah ^= tweak1_2; + ((uint64_t*) &l[idx & MASK])[0] = al; + ((uint64_t*) &l[idx & MASK])[1] = ah; + ah ^= tweak1_2; + + ((uint64_t*)&l[idx & MASK])[1] ^= ((uint64_t*)&l[idx & MASK])[0]; + + ah ^= ch; + al ^= cl; + idx = al; + } + + cn_implode_scratchpad((__m128i*) l, (__m128i*) h); + keccakf(h, 24); + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t* __restrict__ output, @@ -1105,6 +1259,118 @@ public: extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t* __restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak((const uint8_t*) input, (int) size, ctx->state[0], 200); + keccak((const uint8_t*) input + size, (int) size, ctx->state[1], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(reinterpret_cast(input) + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(reinterpret_cast(input) + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + } else { + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + + cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); + cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + + bx0 = cx0; + bx1 = cx1; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + + keccakf(h0, 24); + keccakf(h1, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t* __restrict__ output, @@ -1492,6 +1758,162 @@ public: extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t* __restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak((const uint8_t*) input, (int) size, ctx->state[0], 200); + keccak((const uint8_t*) input + size, (int) size, ctx->state[1], 200); + keccak((const uint8_t*) input + 2 * size, (int) size, ctx->state[2], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(reinterpret_cast(input) + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(reinterpret_cast(input) + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + uint64_t tweak1_2_2 = (*reinterpret_cast(reinterpret_cast(input) + 35 + 2 * size) ^ + *(reinterpret_cast(ctx->state[2]) + 24)); + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + const uint8_t* l2 = ctx->memory + 2 * MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + uint64_t* h2 = reinterpret_cast(ctx->state[2]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + cn_explode_scratchpad((__m128i*) h2, (__m128i*) l2); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t al2 = h2[0] ^h2[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + uint64_t ah2 = h2[1] ^h2[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + uint64_t idx2 = h2[0] ^h2[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + __m128i cx2; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx2 = soft_aesenc((uint32_t*)&l2[idx2 & MASK], _mm_set_epi64x(ah2, al2)); + } else { + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + cx2 = _mm_load_si128((__m128i*) &l2[idx2 & MASK]); + + cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); + cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); + cx2 = _mm_aesenc_si128(cx2, _mm_set_epi64x(ah2, al2)); + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + idx2 = EXTRACT64(cx2); + + bx0 = cx0; + bx1 = cx1; + bx2 = cx2; + + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + + + cl = ((uint64_t*) &l2[idx2 & MASK])[0]; + ch = ((uint64_t*) &l2[idx2 & MASK])[1]; + lo = __umul128(idx2, cl, &hi); + + al2 += hi; + ah2 += lo; + + ah2 ^= tweak1_2_2; + ((uint64_t*) &l2[idx2 & MASK])[0] = al2; + ((uint64_t*) &l2[idx2 & MASK])[1] = ah2; + ah2 ^= tweak1_2_2; + + ((uint64_t*)&l2[idx2 & MASK])[1] ^= ((uint64_t*)&l2[idx2 & MASK])[0]; + + ah2 ^= ch; + al2 ^= cl; + idx2 = al2; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + cn_implode_scratchpad((__m128i*) l2, (__m128i*) h2); + + keccakf(h0, 24); + keccakf(h1, 24); + keccakf(h2, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t* __restrict__ output, @@ -1993,6 +2415,204 @@ public: extra_hashes[ctx->state[3][0] & 3](ctx->state[3], 200, output + 96); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t* __restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak((const uint8_t*) input, (int) size, ctx->state[0], 200); + keccak((const uint8_t*) input + size, (int) size, ctx->state[1], 200); + keccak((const uint8_t*) input + 2 * size, (int) size, ctx->state[2], 200); + keccak((const uint8_t*) input + 3 * size, (int) size, ctx->state[3], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(reinterpret_cast(input) + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(reinterpret_cast(input) + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + uint64_t tweak1_2_2 = (*reinterpret_cast(reinterpret_cast(input) + 35 + 2 * size) ^ + *(reinterpret_cast(ctx->state[2]) + 24)); + uint64_t tweak1_2_3 = (*reinterpret_cast(reinterpret_cast(input) + 35 + 3 * size) ^ + *(reinterpret_cast(ctx->state[3]) + 24)); + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + const uint8_t* l2 = ctx->memory + 2 * MEM; + const uint8_t* l3 = ctx->memory + 3 * MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + uint64_t* h2 = reinterpret_cast(ctx->state[2]); + uint64_t* h3 = reinterpret_cast(ctx->state[3]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + cn_explode_scratchpad((__m128i*) h2, (__m128i*) l2); + cn_explode_scratchpad((__m128i*) h3, (__m128i*) l3); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t al2 = h2[0] ^h2[4]; + uint64_t al3 = h3[0] ^h3[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + uint64_t ah2 = h2[1] ^h2[5]; + uint64_t ah3 = h3[1] ^h3[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); + __m128i bx3 = _mm_set_epi64x(h3[3] ^ h3[7], h3[2] ^ h3[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + uint64_t idx2 = h2[0] ^h2[4]; + uint64_t idx3 = h3[0] ^h3[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + __m128i cx2; + __m128i cx3; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx2 = soft_aesenc((uint32_t*)&l2[idx2 & MASK], _mm_set_epi64x(ah2, al2)); + cx3 = soft_aesenc((uint32_t*)&l3[idx3 & MASK], _mm_set_epi64x(ah3, al3)); + } else { + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + cx2 = _mm_load_si128((__m128i*) &l2[idx2 & MASK]); + cx3 = _mm_load_si128((__m128i*) &l3[idx3 & MASK]); + + cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); + cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); + cx2 = _mm_aesenc_si128(cx2, _mm_set_epi64x(ah2, al2)); + cx3 = _mm_aesenc_si128(cx3, _mm_set_epi64x(ah3, al3)); + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2)); + _mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + idx2 = EXTRACT64(cx2); + idx3 = EXTRACT64(cx3); + + bx0 = cx0; + bx1 = cx1; + bx2 = cx2; + bx3 = cx3; + + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + + + cl = ((uint64_t*) &l2[idx2 & MASK])[0]; + ch = ((uint64_t*) &l2[idx2 & MASK])[1]; + lo = __umul128(idx2, cl, &hi); + + al2 += hi; + ah2 += lo; + + ah2 ^= tweak1_2_2; + ((uint64_t*) &l2[idx2 & MASK])[0] = al2; + ((uint64_t*) &l2[idx2 & MASK])[1] = ah2; + ah2 ^= tweak1_2_2; + + ((uint64_t*)&l2[idx2 & MASK])[1] ^= ((uint64_t*)&l2[idx2 & MASK])[0]; + + ah2 ^= ch; + al2 ^= cl; + idx2 = al2; + + + cl = ((uint64_t*) &l3[idx3 & MASK])[0]; + ch = ((uint64_t*) &l3[idx3 & MASK])[1]; + lo = __umul128(idx3, cl, &hi); + + al3 += hi; + ah3 += lo; + + ah3 ^= tweak1_2_3; + ((uint64_t*) &l3[idx3 & MASK])[0] = al3; + ((uint64_t*) &l3[idx3 & MASK])[1] = ah3; + ah3 ^= tweak1_2_3; + + ((uint64_t*)&l3[idx3 & MASK])[1] ^= ((uint64_t*)&l3[idx3 & MASK])[0]; + + ah3 ^= ch; + al3 ^= cl; + idx3 = al3; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + cn_implode_scratchpad((__m128i*) l2, (__m128i*) h2); + cn_implode_scratchpad((__m128i*) l3, (__m128i*) h3); + + keccakf(h0, 24); + keccakf(h1, 24); + keccakf(h2, 24); + keccakf(h3, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); + extra_hashes[ctx->state[3][0] & 3](ctx->state[3], 200, output + 96); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t* __restrict__ output, @@ -2606,6 +3226,246 @@ public: extra_hashes[ctx->state[4][0] & 3](ctx->state[4], 200, output + 128); } + inline static void hashLiteIpbc(const uint8_t* __restrict__ input, + size_t size, + uint8_t* __restrict__ output, + cryptonight_ctx* __restrict__ ctx) + { + keccak((const uint8_t*) input, (int) size, ctx->state[0], 200); + keccak((const uint8_t*) input + size, (int) size, ctx->state[1], 200); + keccak((const uint8_t*) input + 2 * size, (int) size, ctx->state[2], 200); + keccak((const uint8_t*) input + 3 * size, (int) size, ctx->state[3], 200); + keccak((const uint8_t*) input + 4 * size, (int) size, ctx->state[4], 200); + + uint64_t tweak1_2_0 = (*reinterpret_cast(reinterpret_cast(input) + 35) ^ + *(reinterpret_cast(ctx->state[0]) + 24)); + uint64_t tweak1_2_1 = (*reinterpret_cast(reinterpret_cast(input) + 35 + size) ^ + *(reinterpret_cast(ctx->state[1]) + 24)); + uint64_t tweak1_2_2 = (*reinterpret_cast(reinterpret_cast(input) + 35 + 2 * size) ^ + *(reinterpret_cast(ctx->state[2]) + 24)); + uint64_t tweak1_2_3 = (*reinterpret_cast(reinterpret_cast(input) + 35 + 3 * size) ^ + *(reinterpret_cast(ctx->state[3]) + 24)); + uint64_t tweak1_2_4 = (*reinterpret_cast(reinterpret_cast(input) + 35 + 4 * size) ^ + *(reinterpret_cast(ctx->state[4]) + 24)); + + + const uint8_t* l0 = ctx->memory; + const uint8_t* l1 = ctx->memory + MEM; + const uint8_t* l2 = ctx->memory + 2 * MEM; + const uint8_t* l3 = ctx->memory + 3 * MEM; + const uint8_t* l4 = ctx->memory + 4 * MEM; + uint64_t* h0 = reinterpret_cast(ctx->state[0]); + uint64_t* h1 = reinterpret_cast(ctx->state[1]); + uint64_t* h2 = reinterpret_cast(ctx->state[2]); + uint64_t* h3 = reinterpret_cast(ctx->state[3]); + uint64_t* h4 = reinterpret_cast(ctx->state[4]); + + cn_explode_scratchpad((__m128i*) h0, (__m128i*) l0); + cn_explode_scratchpad((__m128i*) h1, (__m128i*) l1); + cn_explode_scratchpad((__m128i*) h2, (__m128i*) l2); + cn_explode_scratchpad((__m128i*) h3, (__m128i*) l3); + cn_explode_scratchpad((__m128i*) h4, (__m128i*) l4); + + uint64_t al0 = h0[0] ^h0[4]; + uint64_t al1 = h1[0] ^h1[4]; + uint64_t al2 = h2[0] ^h2[4]; + uint64_t al3 = h3[0] ^h3[4]; + uint64_t al4 = h4[0] ^h4[4]; + uint64_t ah0 = h0[1] ^h0[5]; + uint64_t ah1 = h1[1] ^h1[5]; + uint64_t ah2 = h2[1] ^h2[5]; + uint64_t ah3 = h3[1] ^h3[5]; + uint64_t ah4 = h4[1] ^h4[5]; + + __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); + __m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]); + __m128i bx2 = _mm_set_epi64x(h2[3] ^ h2[7], h2[2] ^ h2[6]); + __m128i bx3 = _mm_set_epi64x(h3[3] ^ h3[7], h3[2] ^ h3[6]); + __m128i bx4 = _mm_set_epi64x(h4[3] ^ h4[7], h4[2] ^ h4[6]); + + uint64_t idx0 = h0[0] ^h0[4]; + uint64_t idx1 = h1[0] ^h1[4]; + uint64_t idx2 = h2[0] ^h2[4]; + uint64_t idx3 = h3[0] ^h3[4]; + uint64_t idx4 = h4[0] ^h4[4]; + + for (size_t i = 0; i < ITERATIONS; i++) { + __m128i cx0; + __m128i cx1; + __m128i cx2; + __m128i cx3; + __m128i cx4; + + if (SOFT_AES) { + cx0 = soft_aesenc((uint32_t*)&l0[idx0 & MASK], _mm_set_epi64x(ah0, al0)); + cx1 = soft_aesenc((uint32_t*)&l1[idx1 & MASK], _mm_set_epi64x(ah1, al1)); + cx2 = soft_aesenc((uint32_t*)&l2[idx2 & MASK], _mm_set_epi64x(ah2, al2)); + cx3 = soft_aesenc((uint32_t*)&l3[idx3 & MASK], _mm_set_epi64x(ah3, al3)); + cx4 = soft_aesenc((uint32_t*)&l4[idx4 & MASK], _mm_set_epi64x(ah4, al4)); + } else { + cx0 = _mm_load_si128((__m128i*) &l0[idx0 & MASK]); + cx1 = _mm_load_si128((__m128i*) &l1[idx1 & MASK]); + cx2 = _mm_load_si128((__m128i*) &l2[idx2 & MASK]); + cx3 = _mm_load_si128((__m128i*) &l3[idx3 & MASK]); + cx4 = _mm_load_si128((__m128i*) &l4[idx4 & MASK]); + + cx0 = _mm_aesenc_si128(cx0, _mm_set_epi64x(ah0, al0)); + cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); + cx2 = _mm_aesenc_si128(cx2, _mm_set_epi64x(ah2, al2)); + cx3 = _mm_aesenc_si128(cx3, _mm_set_epi64x(ah3, al3)); + cx4 = _mm_aesenc_si128(cx4, _mm_set_epi64x(ah4, al4)); + } + + _mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); + _mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); + _mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2)); + _mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3)); + _mm_store_si128((__m128i*) &l4[idx4 & MASK], _mm_xor_si128(bx4, cx4)); + + static const uint32_t table = 0x75310; + uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; + uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + tmp = reinterpret_cast(&l4[idx4 & MASK])[11]; + index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + ((uint8_t*)(&l4[idx4 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); + + idx0 = EXTRACT64(cx0); + idx1 = EXTRACT64(cx1); + idx2 = EXTRACT64(cx2); + idx3 = EXTRACT64(cx3); + idx4 = EXTRACT64(cx4); + + bx0 = cx0; + bx1 = cx1; + bx2 = cx2; + bx3 = cx3; + bx4 = cx4; + + uint64_t hi, lo, cl, ch; + cl = ((uint64_t*) &l0[idx0 & MASK])[0]; + ch = ((uint64_t*) &l0[idx0 & MASK])[1]; + lo = __umul128(idx0, cl, &hi); + + al0 += hi; + ah0 += lo; + + ah0 ^= tweak1_2_0; + ((uint64_t*) &l0[idx0 & MASK])[0] = al0; + ((uint64_t*) &l0[idx0 & MASK])[1] = ah0; + ah0 ^= tweak1_2_0; + + ((uint64_t*)&l0[idx0 & MASK])[1] ^= ((uint64_t*)&l0[idx0 & MASK])[0]; + + ah0 ^= ch; + al0 ^= cl; + idx0 = al0; + + + cl = ((uint64_t*) &l1[idx1 & MASK])[0]; + ch = ((uint64_t*) &l1[idx1 & MASK])[1]; + lo = __umul128(idx1, cl, &hi); + + al1 += hi; + ah1 += lo; + + ah1 ^= tweak1_2_1; + ((uint64_t*) &l1[idx1 & MASK])[0] = al1; + ((uint64_t*) &l1[idx1 & MASK])[1] = ah1; + ah1 ^= tweak1_2_1; + + ((uint64_t*)&l1[idx1 & MASK])[1] ^= ((uint64_t*)&l1[idx1 & MASK])[0]; + + ah1 ^= ch; + al1 ^= cl; + idx1 = al1; + + + cl = ((uint64_t*) &l2[idx2 & MASK])[0]; + ch = ((uint64_t*) &l2[idx2 & MASK])[1]; + lo = __umul128(idx2, cl, &hi); + + al2 += hi; + ah2 += lo; + + ah2 ^= tweak1_2_2; + ((uint64_t*) &l2[idx2 & MASK])[0] = al2; + ((uint64_t*) &l2[idx2 & MASK])[1] = ah2; + ah2 ^= tweak1_2_2; + + ((uint64_t*)&l2[idx2 & MASK])[1] ^= ((uint64_t*)&l2[idx2 & MASK])[0]; + + ah2 ^= ch; + al2 ^= cl; + idx2 = al2; + + + cl = ((uint64_t*) &l3[idx3 & MASK])[0]; + ch = ((uint64_t*) &l3[idx3 & MASK])[1]; + lo = __umul128(idx3, cl, &hi); + + al3 += hi; + ah3 += lo; + + ah3 ^= tweak1_2_3; + ((uint64_t*) &l3[idx3 & MASK])[0] = al3; + ((uint64_t*) &l3[idx3 & MASK])[1] = ah3; + ah3 ^= tweak1_2_3; + + ((uint64_t*)&l3[idx3 & MASK])[1] ^= ((uint64_t*)&l3[idx3 & MASK])[0]; + + ah3 ^= ch; + al3 ^= cl; + idx3 = al3; + + + cl = ((uint64_t*) &l4[idx4 & MASK])[0]; + ch = ((uint64_t*) &l4[idx4 & MASK])[1]; + lo = __umul128(idx4, cl, &hi); + + al4 += hi; + ah4 += lo; + + ah4 ^= tweak1_2_4; + ((uint64_t*) &l4[idx4 & MASK])[0] = al4; + ((uint64_t*) &l4[idx4 & MASK])[1] = ah4; + ah4 ^= tweak1_2_4; + + ((uint64_t*)&l4[idx4 & MASK])[1] ^= ((uint64_t*)&l4[idx4 & MASK])[0]; + + ah4 ^= ch; + al4 ^= cl; + idx4 = al4; + } + + cn_implode_scratchpad((__m128i*) l0, (__m128i*) h0); + cn_implode_scratchpad((__m128i*) l1, (__m128i*) h1); + cn_implode_scratchpad((__m128i*) l2, (__m128i*) h2); + cn_implode_scratchpad((__m128i*) l3, (__m128i*) h3); + cn_implode_scratchpad((__m128i*) l4, (__m128i*) h4); + + keccakf(h0, 24); + keccakf(h1, 24); + keccakf(h2, 24); + keccakf(h3, 24); + keccakf(h4, 24); + + extra_hashes[ctx->state[0][0] & 3](ctx->state[0], 200, output); + extra_hashes[ctx->state[1][0] & 3](ctx->state[1], 200, output + 32); + extra_hashes[ctx->state[2][0] & 3](ctx->state[2], 200, output + 64); + extra_hashes[ctx->state[3][0] & 3](ctx->state[3], 200, output + 96); + extra_hashes[ctx->state[4][0] & 3](ctx->state[4], 200, output + 128); + } + inline static void hashHeavy(const uint8_t* __restrict__ input, size_t size, uint8_t* __restrict__ output, diff --git a/src/default_config.json b/src/default_config.json index b7eaf97f..3dc4ae32 100644 --- a/src/default_config.json +++ b/src/default_config.json @@ -1,5 +1,5 @@ { - "algo": "cryptonight", // cryptonight (default), cryptonight-lite or cryptopnight-heavy + "algo": "cryptonight", // cryptonight (default), cryptonight-lite, cryptonight-lite-ipbc or cryptopnight-heavy "av": null, // DEPRECATED: algorithm variation, (0 auto, // 1 -> (aesni=1, multihash-factor=1), // 2 -> (aesni=1, multihash-factor=2), diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index a047ae9c..9079c214 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -58,6 +58,8 @@ DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : #ifndef XMRIG_NO_TLS if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_HEAVY) { url = new Url("donate2.graef.in", 8443, userId, nullptr, true, false, true); + } else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE_IPBC) { + url = new Url("donate2.graef.in", 1080, userId, nullptr, true, false, true); } else { if (Options::i()->forcePowVersion() == Options::POW_V1) { url = new Url("donate.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 8080 : 8081, userId, nullptr, true, false, true); @@ -70,6 +72,8 @@ DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : #else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_HEAVY) { url = new Url("donate.graef.in", 8443, userId, nullptr, false, false, true); + } else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE_IPBC) { + url = new Url("donate.graef.in", 1080, userId, nullptr, false, false, true); } else { if (Options::i()->forcePowVersion() == Options::POW_V1) { url = new Url("donate.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 80 : 443, userId, nullptr, false, false, true); @@ -153,7 +157,7 @@ void DonateStrategy::onResultAccepted(Client *client, const SubmitResult &result } -void DonateStrategy::idle(uint64_t timeout) +void DonateStrategy::idle(int64_t timeout) { uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0); } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index fa3e06a5..841070c5 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -58,7 +58,7 @@ protected: void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; private: - void idle(uint64_t timeout); + void idle(int64_t timeout); void suspend(); static void onTimer(uv_timer_t *handle); diff --git a/src/version.h b/src/version.h index 3c6d42c5..e27bd5f2 100644 --- a/src/version.h +++ b/src/version.h @@ -36,14 +36,14 @@ #define APP_DESC "XMRigCC CPU miner" #define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id" #endif -#define APP_VERSION "1.6.0 (based on XMRig 2.5.2)" +#define APP_VERSION "1.6.1-beta1 (based on XMRig 2.5.2)" #define APP_DOMAIN "" #define APP_SITE "https://github.com/Bendr0id/xmrigCC" #define APP_KIND "cpu" #define APP_VER_MAJOR 1 #define APP_VER_MINOR 6 -#define APP_VER_BUILD 0 +#define APP_VER_BUILD 1 #define APP_VER_REV 0 #ifndef NDEBUG From abf623da82bcac48700211b91055f38e7104415b Mon Sep 17 00:00:00 2001 From: BenDroid Date: Wed, 18 Apr 2018 22:06:05 +0200 Subject: [PATCH 002/188] Preparation #1.6.1 --- CHANGELOG.md | 4 ++++ README.md | 1 + src/Options.cpp | 2 +- src/version.h | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b020b8..a574a93c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.6.1 +- Implementation of CN-Lite-IPBC algo +- Fixed Windows 32bit build +- Fixed XMRigCCServer crash when auth header is manipulated # 1.6.0 - Complete rewrite of the stratum TCP/TLS network communication using boost::asio to fix connection issues and crashs - Force of PoW via "variant" parameter in xmrg-proxy 2.5.2+, it now overrules local settings diff --git a/README.md b/README.md index 41bda3e9..b3bda660 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ The modified version can also handle commands like "update config", "start/stop Full Windows/Linux compatible, and you can mix Linux and Windows miner on one XMRigCCServer. ## Additional features of XMRigCC (on top of XMRig) +* **NEW: Support of Crytptonight-Lite-IPBC** * **NEW: Support of Crytptonight-Heavy (Sumokoin, Haven, ...)** * **NEW: Ready for Monero v7 PoW changes on April 6 2018** * **NEW: Ready for Aeon v7 PoW changes on April 7? 2018** diff --git a/src/Options.cpp b/src/Options.cpp index 7a7dacf4..0e395f87 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -64,7 +64,7 @@ Usage: " APP_ID " [OPTIONS]\n\ Options:\n" # ifndef XMRIG_CC_SERVER "\ - -a, --algo=ALGO cryptonight (default), cryptonight-lite or cryptonight-heavy\n\ + -a, --algo=ALGO cryptonight (default), cryptonight-lite, cryptonight-lite-ipbc or cryptonight-heavy\n\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ -u, --user=USERNAME username for mining server\n\ diff --git a/src/version.h b/src/version.h index e27bd5f2..c14a4239 100644 --- a/src/version.h +++ b/src/version.h @@ -36,7 +36,7 @@ #define APP_DESC "XMRigCC CPU miner" #define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id" #endif -#define APP_VERSION "1.6.1-beta1 (based on XMRig 2.5.2)" +#define APP_VERSION "1.6.1 (based on XMRig 2.5.2)" #define APP_DOMAIN "" #define APP_SITE "https://github.com/Bendr0id/xmrigCC" #define APP_KIND "cpu" From 581cf9794d1eed861a7f842bc611481157f0f87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Thu, 19 Apr 2018 16:05:33 +0200 Subject: [PATCH 003/188] Update Job.h --- src/net/Job.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/net/Job.h b/src/net/Job.h index 40f348d0..01502b18 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -68,7 +68,7 @@ public: bool operator!=(const Job &other) const; private: - alignas(16) uint8_t m_blob[84]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. + uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. bool m_nicehash; int m_poolId; @@ -78,11 +78,6 @@ private: uint64_t m_diff; uint64_t m_target; Options::PowVersion m_powVersion; - -# ifdef XMRIG_PROXY_PROJECT - VAR_ALIGN(16, char m_rawBlob[169]); - VAR_ALIGN(16, char m_rawTarget[17]); -# endif }; #endif /* __JOB_H__ */ From 8b6c062c90657ffe655697cb05841272efe21777 Mon Sep 17 00:00:00 2001 From: BenDr0id Date: Thu, 19 Apr 2018 17:19:23 +0200 Subject: [PATCH 004/188] Fixed crashes on 32bit Windows --- src/net/Client.h | 2 +- src/net/Job.cpp | 10 ---------- src/net/strategies/DonateStrategy.cpp | 2 +- src/net/strategies/DonateStrategy.h | 2 +- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/net/Client.h b/src/net/Client.h index 46e07bf0..03832b46 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -105,7 +105,7 @@ private: int m_id; int m_retryPause; int64_t m_failures; - int64_t m_jobs; + uint64_t m_jobs; Job m_job; size_t m_recvBufPos; static int64_t m_sequence; diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 194a7f12..23dd85b0 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -96,11 +96,6 @@ bool Job::setBlob(const char *blob) m_nicehash = true; } -# ifdef XMRIG_PROXY_PROJECT - memset(m_rawBlob, 0, sizeof(m_rawBlob)); - memcpy(m_rawBlob, blob, m_size * 2); -# endif - return true; } @@ -137,11 +132,6 @@ bool Job::setTarget(const char *target) return false; } -# ifdef XMRIG_PROXY_PROJECT - memset(m_rawTarget, 0, sizeof(m_rawTarget)); - memcpy(m_rawTarget, target, len); -# endif - m_diff = toDiff(m_target); return true; } diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 9079c214..8e2d1561 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -157,7 +157,7 @@ void DonateStrategy::onResultAccepted(Client *client, const SubmitResult &result } -void DonateStrategy::idle(int64_t timeout) +void DonateStrategy::idle(uint64_t timeout) { uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0); } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 841070c5..fa3e06a5 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -58,7 +58,7 @@ protected: void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; private: - void idle(int64_t timeout); + void idle(uint64_t timeout); void suspend(); static void onTimer(uv_timer_t *handle); From 84ba73120f62417a7b1aaa00d32525886f6f6626 Mon Sep 17 00:00:00 2001 From: BenDr0id Date: Thu, 19 Apr 2018 17:20:46 +0200 Subject: [PATCH 005/188] Changenlog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a574a93c..3cc53aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 1.6.1 - Implementation of CN-Lite-IPBC algo -- Fixed Windows 32bit build +- Fixed Windows 32bit build / crashes - Fixed XMRigCCServer crash when auth header is manipulated # 1.6.0 - Complete rewrite of the stratum TCP/TLS network communication using boost::asio to fix connection issues and crashs From f0039013b5786cf562fdb3901826803d74babad6 Mon Sep 17 00:00:00 2001 From: BenDr0id Date: Thu, 19 Apr 2018 17:23:24 +0200 Subject: [PATCH 006/188] Bumped version to 1.6.2 --- CHANGELOG.md | 4 +++- src/version.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cc53aa3..100ce1d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -# 1.6.1 +# 1.6.2 - Implementation of CN-Lite-IPBC algo - Fixed Windows 32bit build / crashes - Fixed XMRigCCServer crash when auth header is manipulated +# 1.6.1 +- beta # 1.6.0 - Complete rewrite of the stratum TCP/TLS network communication using boost::asio to fix connection issues and crashs - Force of PoW via "variant" parameter in xmrg-proxy 2.5.2+, it now overrules local settings diff --git a/src/version.h b/src/version.h index c14a4239..bc101ced 100644 --- a/src/version.h +++ b/src/version.h @@ -36,14 +36,14 @@ #define APP_DESC "XMRigCC CPU miner" #define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id" #endif -#define APP_VERSION "1.6.1 (based on XMRig 2.5.2)" +#define APP_VERSION "1.6.2 (based on XMRig 2.5.2)" #define APP_DOMAIN "" #define APP_SITE "https://github.com/Bendr0id/xmrigCC" #define APP_KIND "cpu" #define APP_VER_MAJOR 1 #define APP_VER_MINOR 6 -#define APP_VER_BUILD 1 +#define APP_VER_BUILD 2 #define APP_VER_REV 0 #ifndef NDEBUG From dc6bcacaed1bc0c8c5e8e88ae9cd421ef17e7867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Sun, 22 Apr 2018 07:04:07 +0200 Subject: [PATCH 007/188] Fixed leak in Logger --- src/log/Log.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/log/Log.cpp b/src/log/Log.cpp index 7a754926..f37d4424 100644 --- a/src/log/Log.cpp +++ b/src/log/Log.cpp @@ -64,6 +64,8 @@ void Log::message(Log::Level level, const char* fmt, ...) va_end(copy); } + va_end(args); + uv_mutex_unlock(&m_mutex); } From f54ce3c95caa4b8d48fa5f38c2f3d1f6df9a99cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Wed, 23 May 2018 23:23:49 +0200 Subject: [PATCH 008/188] Merged features for # 1.6.3 (#114) - Added shift+click function for multi row selection to Dashboard - Added -DBUILD_STATIC=ON/OFF option to CMake configuration to create fully static builds - Added current algo and list of supported_varaints to login message for future usage on proxy - Added support for latest Stellite (XTL) and Alloy (XAO) variants - Simplification of configuration, "force-pow-variant" and "cryptonight-lite-ipbc" parameters are now deprecated see [Coin Configuration](https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations) for guidance - Fixed leaks in transport shutdown --- CHANGELOG.md | 7 + CMakeLists.txt | 5 + README.md | 13 +- index.html | 4 +- src/Cpu.cpp | 1 - src/Mem.cpp | 1 - src/Mem_unix.cpp | 1 - src/Mem_win.cpp | 1 - src/Options.cpp | 83 ++++++-- src/Options.h | 23 +-- src/PowVariant.h | 110 +++++++++++ src/crypto/CryptoNight.cpp | 265 +++++++++++++++---------- src/crypto/CryptoNight.h | 5 +- src/crypto/CryptoNight_arm.h | 86 ++++---- src/crypto/CryptoNight_test.h | 270 +++++++++++--------------- src/crypto/CryptoNight_x86.h | 92 +++++---- src/net/BoostConnection.h | 4 + src/net/Client.cpp | 51 +++-- src/net/Connection.cpp | 4 + src/net/Job.cpp | 19 +- src/net/Job.h | 7 +- src/net/Network.cpp | 7 +- src/net/strategies/DonateStrategy.cpp | 20 +- src/version.h | 4 +- src/workers/MultiWorker.cpp | 2 +- 25 files changed, 654 insertions(+), 431 deletions(-) create mode 100644 src/PowVariant.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 100ce1d3..2acd802b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.6.3 +- Added shift+click function for multi row selection to Dashboard +- Added -DBUILD_STATIC=ON/OFF option to CMake configuration to create fully static builds +- Added current algo and list of supported_varaints to login message for future usage on proxy +- Added support for latest Stellite (XTL) and Alloy (XAO) variants +- Simplification of configuration, "force-pow-variant" and "cryptonight-lite-ipbc" parameters are now deprecated see [Coin Configuration](https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations) for guidance +- Fixed leaks in transport shutdown # 1.6.2 - Implementation of CN-Lite-IPBC algo - Fixed Windows 32bit build / crashes diff --git a/CMakeLists.txt b/CMakeLists.txt index 69c2e5b0..ffcbc8f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ option(WITH_HTTPD "HTTP REST API" OFF) option(WITH_CC_CLIENT "CC Client" ON) option(WITH_CC_SERVER "CC Server" ON) option(WITH_TLS "TLS support" ON) +option(BUILD_STATIC "Build static binary" OFF) set(MINER_EXECUTABLE_NAME "xmrigMiner" CACHE STRING "Miner executable file name") set(DAEMON_EXECUTABLE_NAME "xmrigDaemon" CACHE STRING "Daemon executable file name") @@ -209,6 +210,10 @@ else() add_definitions(/DXMRIG_NO_CC) endif() +if (BUILD_STATIC) + set(CMAKE_EXE_LINKER_FLAGS " -static") +endif() + include_directories(src) include_directories(src/3rdparty) include_directories(${UV_INCLUDE_DIR}) diff --git a/README.md b/README.md index b3bda660..25533065 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # XMRigCC -:warning: **To be prepared for the upcoming PoW changes you need to update your miners to at least release (1.5.5).** +:warning: **Confused by all the forks? Check the [Coin Configuration](https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations) guide.** [![Windows Build status](https://ci.appveyor.com/api/projects/status/l8v7cuuy320a4tpd?svg=true)](https://ci.appveyor.com/project/Bendr0id/xmrigcc) @@ -21,10 +21,15 @@ The modified version can also handle commands like "update config", "start/stop Full Windows/Linux compatible, and you can mix Linux and Windows miner on one XMRigCCServer. ## Additional features of XMRigCC (on top of XMRig) -* **NEW: Support of Crytptonight-Lite-IPBC** + +Check the [Coin Configuration](https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations) guide + +* **NEW: Support of Crytptonight Stellite (XTL) v4 variant** +* **NEW: Support of Crytptonight Alloy (XAO) variant** +* **NEW: Support of Crytptonight-Lite IPBC/TUBE variant** * **NEW: Support of Crytptonight-Heavy (Sumokoin, Haven, ...)** -* **NEW: Ready for Monero v7 PoW changes on April 6 2018** -* **NEW: Ready for Aeon v7 PoW changes on April 7? 2018** +* **Support of Crytptonight v7 PoW changes** +* **Support of Crytptonight-Lite v7 PoW changes** * Full SSL/TLS support for the whole communication: [Howto](https://github.com/Bendr0id/xmrigCC/wiki/tls) - XMRigCCServer Dashboard <-> Browser - XMRigCCServer <-> XMRigMiner diff --git a/index.html b/index.html index 277566ea..5a999dfb 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - + @@ -127,7 +127,7 @@ ], rowId: 'client_status.client_id', select: { - style: "multi" + style: "multi+shift" }, order: [1, 'asc'], lengthChange: false, diff --git a/src/Cpu.cpp b/src/Cpu.cpp index ddc568e7..ddd4642d 100644 --- a/src/Cpu.cpp +++ b/src/Cpu.cpp @@ -67,7 +67,6 @@ void CpuImpl::optimizeParameters(size_t& threadsCount, size_t& hashFactor, size_t algoBlockSize; switch (algo) { case Options::ALGO_CRYPTONIGHT_LITE: - case Options::ALGO_CRYPTONIGHT_LITE_IPBC: algoBlockSize = 1024; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Mem.cpp b/src/Mem.cpp index 871ee20a..522deab4 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -44,7 +44,6 @@ cryptonight_ctx *Mem::create(int threadId) switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: - case Options::ALGO_CRYPTONIGHT_LITE_IPBC: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 6cae3a63..b52c449b 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -50,7 +50,6 @@ bool Mem::allocate(const Options* options) switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: - case Options::ALGO_CRYPTONIGHT_LITE_IPBC: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index 658d0ceb..a52cc5b5 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -156,7 +156,6 @@ bool Mem::allocate(const Options* options) switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: - case Options::ALGO_CRYPTONIGHT_LITE_IPBC: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: diff --git a/src/Options.cpp b/src/Options.cpp index 0e395f87..93b9980e 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -58,13 +58,12 @@ Options *Options::m_self = nullptr; - static char const usage[] = "\ Usage: " APP_ID " [OPTIONS]\n\ Options:\n" # ifndef XMRIG_CC_SERVER "\ - -a, --algo=ALGO cryptonight (default), cryptonight-lite, cryptonight-lite-ipbc or cryptonight-heavy\n\ + -a, --algo=ALGO cryptonight (default), cryptonight-lite or cryptonight-heavy\n\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ -u, --user=USERNAME username for mining server\n\ @@ -75,7 +74,7 @@ Options:\n" -k, --keepalive send keepalived for prevent timeout (need pool support)\n\ -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ - --force-pow-version=N force to use specific PoW variation (default: 0 POW_AUTODETECT, 1 POW_V1, 2 POW_V2)\n\ + --force-pow-version=N force to use specific PoW variation (default: 0 POW_AUTODETECT, 1 POW_V0, 2 POW_MONERO_V7)\n\ --multihash-factor=N number of hash blocks to process at a time (not set or 0 enables automatic selection of optimal number of hash blocks)\n\ --multihash-thread-mask for av=2/4 only, limits multihash to given threads (mask), (default: all threads)\n\ --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ @@ -165,6 +164,7 @@ static struct option const options[] = { { "version", 0, nullptr, 'V' }, { "use-tls", 0, nullptr, 1015 }, { "force-pow-version",1, nullptr, 1016 }, + { "pow-variant" ,1, nullptr, 1017 }, { "api-port", 1, nullptr, 4000 }, { "api-access-token", 1, nullptr, 4001 }, { "api-worker-id", 1, nullptr, 4002 }, @@ -208,6 +208,7 @@ static struct option const config_options[] = { { "threads", 1, nullptr, 't' }, { "user-agent", 1, nullptr, 1008 }, { "force-pow-version", 1, nullptr, 1016 }, + { "pow-variant", 1, nullptr, 1017 }, { "doublehash-thread-mask", 1, nullptr, 4013 }, { "multihash-thread-mask", 1, nullptr, 4013 }, { nullptr, 0, nullptr, 0 } @@ -259,10 +260,23 @@ static struct option const cc_server_options[] = { static const char *algo_names[] = { "cryptonight", "cryptonight-lite", - "cryptonight-lite-ipbc", "cryptonight-heavy" }; +static const char *algo_short_names[] = { + "cn", + "cn-lite", + "cn-heavy" +}; + +constexpr static const char *pow_variant_names[] = { + "auto", + "0", + "1", + "ipbc", + "alloy", + "xtl" +}; Options *Options::parse(int argc, char **argv) { @@ -282,6 +296,10 @@ const char *Options::algoName() const return algo_names[m_algo]; } +const char *Options::algoShortName() const +{ + return algo_short_names[m_algo]; +} Options::Options(int argc, char **argv) : m_background(false), @@ -309,7 +327,7 @@ Options::Options(int argc, char **argv) : m_algo(ALGO_CRYPTONIGHT), m_algoVariant(AV0_AUTO), m_aesni(AESNI_AUTO), - m_forcePowVersion(POW_AUTODETECT), + m_powVariant(POW_AUTODETECT), m_hashFactor(0), m_apiPort(0), m_donateLevel(kDonateLevel), @@ -548,6 +566,9 @@ bool Options::parseArg(int key, const char *arg) case 1015: /* --use-tls */ return parseBoolean(key, true); + case 1017: /* --pow-variant */ + return parsePowVariant(arg); + case 4016: /* --cc-use-tls */ return parseBoolean(key, true); @@ -626,6 +647,7 @@ bool Options::parseArg(int key, uint64_t arg) break; case 'v': /* --av */ + showDeprecateWarning("av", "aesni"); if (arg > 1000) { showUsage(1); return false; @@ -677,12 +699,13 @@ bool Options::parseArg(int key, uint64_t arg) break; case 1016: /* --force-pow-version */ - if (arg < POW_AUTODETECT || arg > POW_V2) { + showDeprecateWarning("force-pow-version", "pow-variant"); + if (arg != POW_AUTODETECT && arg != POW_V0 && arg != POW_V1) { showUsage(1); return false; } - m_forcePowVersion = static_cast(arg); + m_powVariant = static_cast(arg); break; case 1020: /* --cpu-affinity */ @@ -875,6 +898,10 @@ void Options::showUsage(int status) const } } +void Options::showDeprecateWarning(const char* deprecated, const char* newParam) const +{ + fprintf(stderr, "Parameter \"%s\" is deprecated, please used \"%s\" instead.\n", deprecated, newParam); +} void Options::showVersion() { @@ -920,17 +947,19 @@ bool Options::setAlgo(const char *algo) break; } - if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) { + if (i == ARRAY_SIZE(algo_names) - 1 && (!strcmp(algo, "cn-lite") || !strcmp(algo, "cryptonight-light"))) { m_algo = ALGO_CRYPTONIGHT_LITE; break; } - if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light-ipbc")) { - m_algo = ALGO_CRYPTONIGHT_LITE_IPBC; + if (i == ARRAY_SIZE(algo_names) - 1 && (!strcmp(algo, "cryptonight-lite-ipbc") || !strcmp(algo, "cryptonight-light-ipbc") || !strcmp(algo, "cn-lite-ipbc"))) { + showDeprecateWarning("cryptonight-light-ipbc", "cryptonight-light (with variant \"ipbc\")"); + m_algo = ALGO_CRYPTONIGHT_LITE; + m_powVariant = POW_IPBC; break; } - if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-heavy")) { + if (i == ARRAY_SIZE(algo_names) - 1 && (!strcmp(algo, "cryptonight-heavy") || !strcmp(algo, "cn-heavy"))) { m_algo = ALGO_CRYPTONIGHT_HEAVY; break; } @@ -944,6 +973,38 @@ bool Options::setAlgo(const char *algo) return true; } +bool Options::parsePowVariant(const char *powVariant) +{ + for (size_t i = 0; i < ARRAY_SIZE(pow_variant_names); i++) { + if (pow_variant_names[i] && !strcmp(powVariant, pow_variant_names[i])) { + m_powVariant = static_cast(i); + break; + } + + if (i == ARRAY_SIZE(pow_variant_names) - 1 && !strcmp(powVariant, "auto")) { + m_powVariant = POW_AUTODETECT; + break; + } + + if (i == ARRAY_SIZE(pow_variant_names) - 1 && (!strcmp(powVariant, "monerov7") || !strcmp(powVariant, "aeonv7") || !strcmp(powVariant, "v7"))) { + m_powVariant = POW_V1; + break; + } + + if (i == ARRAY_SIZE(pow_variant_names) - 1 && !strcmp(powVariant, "stellite")) { + m_powVariant = POW_XTL; + break; + } + + if (i == ARRAY_SIZE(pow_variant_names) - 1) { + showUsage(1); + return false; + } + } + + return true; +} + void Options::optimizeAlgorithmConfiguration() { // backwards compatibility for configs still setting algo variant (av) diff --git a/src/Options.h b/src/Options.h index bc1d7474..b2434f02 100644 --- a/src/Options.h +++ b/src/Options.h @@ -33,6 +33,7 @@ #include #include "rapidjson/fwd.h" +#include "PowVariant.h" class Url; struct option; @@ -42,10 +43,9 @@ class Options { public: enum Algo { - ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */ - ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ - ALGO_CRYPTONIGHT_LITE_IPBC, /* CryptoNight-Lite-IPBC (IPBC) */ - ALGO_CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (SUMO) */ + ALGO_CRYPTONIGHT, /* CryptoNight (2MB ScratchPad) */ + ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (1MB ScratchPad) */ + ALGO_CRYPTONIGHT_HEAVY /* CryptoNight-Heavy (4MB ScratchPad) */ }; enum AlgoVariant { @@ -63,12 +63,6 @@ public: AESNI_OFF }; - enum PowVersion { - POW_AUTODETECT, /* Default, automatic detect by block version */ - POW_V1, /* Force to use PoW algo before 28.03.2018 */ - POW_V2, /* Force to use PoW algo used by Monero V7 (after 28.03.2018) and AEON */ - }; - static inline Options* i() { return m_self; } static Options *parse(int argc, char **argv); @@ -94,7 +88,7 @@ public: inline const char *ccCertFile() const { return m_ccCertFile == nullptr ? "server.pem" : m_ccCertFile; } inline const std::vector &pools() const { return m_pools; } inline Algo algo() const { return m_algo; } - inline PowVersion forcePowVersion() const { return m_forcePowVersion; } + inline PowVariant powVariant() const { return m_powVariant; } inline bool aesni() const { return m_aesni == AESNI_ON; } inline size_t hashFactor() const { return m_hashFactor; } inline int apiPort() const { return m_apiPort; } @@ -110,9 +104,10 @@ public: inline int64_t multiHashThreadMask() const { return m_multiHashThreadMask; } inline void setColors(bool colors) { m_colors = colors; } - inline static void release() { delete m_self; } + inline static void release() { delete m_self; } const char *algoName() const; + const char *algoShortName() const; private: constexpr static uint16_t kDefaultCCPort = 3344; @@ -133,9 +128,11 @@ private: void parseConfig(const char *fileName); void parseJSON(const struct option *option, const rapidjson::Value &object); void showUsage(int status) const; + void showDeprecateWarning(const char* deprecated, const char* newParam) const; void showVersion(void); bool setAlgo(const char *algo); + bool parsePowVariant(const char *powVariant); void optimizeAlgorithmConfiguration(); @@ -164,7 +161,7 @@ private: Algo m_algo; AlgoVariant m_algoVariant; AesNi m_aesni; - PowVersion m_forcePowVersion; + PowVariant m_powVariant; size_t m_hashFactor; int m_apiPort; int m_donateLevel; diff --git a/src/PowVariant.h b/src/PowVariant.h new file mode 100644 index 00000000..73d5583d --- /dev/null +++ b/src/PowVariant.h @@ -0,0 +1,110 @@ +/* XMRigCC + * Copyright 2018- BenDr0id + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __POW_VARIANT_H__ +#define __POW_VARIANT_H__ + +#include +#include + +enum PowVariant +{ + POW_AUTODETECT, + POW_V0, + POW_V1, + POW_IPBC, + POW_ALLOY, + POW_XTL, + LAST_ITEM +}; + +inline std::string getPowVariantName(PowVariant powVariant) +{ + switch (powVariant) + { + case POW_V0: + return "0"; + case POW_V1: + return "1"; + case POW_IPBC: + return "ipbc"; + case POW_ALLOY: + return "alloy"; + case POW_XTL: + return "xtl"; + case POW_AUTODETECT: + default: + return "-1"; + } +} + +inline std::list getSupportedPowVariants() +{ + std::list supportedPowVariants; + + for (int variant = 0; variant != LAST_ITEM; variant++) + { + supportedPowVariants.push_back(getPowVariantName(static_cast(variant))); + } + + return supportedPowVariants; +} + +inline PowVariant parseVariant(int variant) +{ + PowVariant powVariant = PowVariant::POW_AUTODETECT; + + switch (variant) { + case -1: + powVariant = PowVariant::POW_AUTODETECT; + break; + case 0: + powVariant = PowVariant::POW_V0; + break; + case 1: + powVariant = PowVariant::POW_V1; + break; + default: + break; + } + + return powVariant; +} + + +inline PowVariant parseVariant(const std::string variant) +{ + PowVariant powVariant = PowVariant::POW_AUTODETECT; + + if (variant == "0") { + powVariant = PowVariant::POW_V0; + } else if (variant == "1") { + powVariant = PowVariant::POW_V1; + } else if (variant == "ipbc") { + powVariant = PowVariant::POW_IPBC; + } else if (variant == "alloy") { + powVariant = PowVariant::POW_ALLOY; + } else if (variant == "xtl") { + powVariant = PowVariant::POW_XTL; + } + + return powVariant; +} + + +#endif /* __POW_VARIANT_H__ */ diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp index 0362ec91..0f9feac3 100644 --- a/src/crypto/CryptoNight.cpp +++ b/src/crypto/CryptoNight.cpp @@ -34,74 +34,70 @@ #include "crypto/CryptoNight_test.h" template -static void cryptonight_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { +static void cryptonight_aesni(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { # if !defined(XMRIG_ARMv7) - if ((reinterpret_cast(input)[0] > 6 && powVersion == Options::PowVersion::POW_AUTODETECT) || - powVersion == Options::PowVersion::POW_V2) { - CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); + if (powVersion == PowVariant::POW_V1) { + CryptoNightMultiHash<0x80000, POW_DEFAULT_INDEX_SHIFT, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); + } else if (powVersion == PowVariant::POW_ALLOY) { + CryptoNightMultiHash<0x100000, POW_DEFAULT_INDEX_SHIFT, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); + } else if (powVersion == PowVariant::POW_XTL) { + CryptoNightMultiHash<0x80000, POW_XLT_V4_INDEX_SHIFT, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); } else { - CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); + CryptoNightMultiHash<0x80000, POW_DEFAULT_INDEX_SHIFT, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); } # endif } template -static void cryptonight_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { - if ((reinterpret_cast(input)[0] > 6 && powVersion == Options::PowVersion::POW_AUTODETECT) || - powVersion == Options::PowVersion::POW_V2) { - CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); +static void cryptonight_softaes(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { + if (powVersion == PowVariant::POW_V1) { + CryptoNightMultiHash<0x80000, POW_DEFAULT_INDEX_SHIFT, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); + } else if (powVersion == PowVariant::POW_ALLOY) { + CryptoNightMultiHash<0x100000, POW_DEFAULT_INDEX_SHIFT, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); + } else if (powVersion == PowVariant::POW_XTL) { + CryptoNightMultiHash<0x80000, POW_XLT_V4_INDEX_SHIFT, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); } else { - CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); + CryptoNightMultiHash<0x80000, POW_DEFAULT_INDEX_SHIFT, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); } } template -static void cryptonight_lite_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { +static void cryptonight_lite_aesni(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { # if !defined(XMRIG_ARMv7) - if ((reinterpret_cast(input)[0] > 1 && powVersion == Options::PowVersion::POW_AUTODETECT) || - powVersion == Options::PowVersion::POW_V2) { - CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); + if (powVersion == PowVariant::POW_V1) { + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); + } else if (powVersion == PowVariant::POW_IPBC) { + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hashLiteIpbc(input, size, output, ctx); } else { - CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); } # endif } template -static void cryptonight_lite_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { - if ((reinterpret_cast(input)[0] > 1 && powVersion == Options::PowVersion::POW_AUTODETECT) || - powVersion == Options::PowVersion::POW_V2) { - CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); +static void cryptonight_lite_softaes(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { + if (powVersion == PowVariant::POW_V1) { + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx); + } else if (powVersion == PowVariant::POW_IPBC) { + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hashLiteIpbc(input, size, output, ctx); } else { - CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx); } } template -static void cryptonight_lite_ipbc_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { +static void cryptonight_heavy_aesni(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { # if !defined(XMRIG_ARMv7) - CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hashLiteIpbc(input, size, output, ctx); + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_HEAVY, 0x3FFFF0, false, NUM_HASH_BLOCKS>::hashHeavy(input, size, output, ctx); # endif } template -static void cryptonight_lite_ipbc_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { - CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hashLiteIpbc(input, size, output, ctx); +static void cryptonight_heavy_softaes(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { + CryptoNightMultiHash<0x40000, POW_DEFAULT_INDEX_SHIFT, MEMORY_HEAVY, 0x3FFFF0, true, NUM_HASH_BLOCKS>::hashHeavy(input, size, output, ctx); } -template -static void cryptonight_heavy_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { -# if !defined(XMRIG_ARMv7) - CryptoNightMultiHash<0x40000, MEMORY_HEAVY, 0x3FFFF0, false, NUM_HASH_BLOCKS>::hashHeavy(input, size, output, ctx); -# endif -} - -template -static void cryptonight_heavy_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) { - CryptoNightMultiHash<0x40000, MEMORY_HEAVY, 0x3FFFF0, true, NUM_HASH_BLOCKS>::hashHeavy(input, size, output, ctx); -} - -void (*cryptonight_hash_ctx[MAX_NUM_HASH_BLOCKS])(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx); +void (*cryptonight_hash_ctx[MAX_NUM_HASH_BLOCKS])(PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx); template void setCryptoNightHashMethods(Options::Algo algo, bool aesni) @@ -123,14 +119,6 @@ void setCryptoNightHashMethods(Options::Algo algo, bool aesni) } break; - case Options::ALGO_CRYPTONIGHT_LITE_IPBC: - if (aesni) { - cryptonight_hash_ctx[HASH_FACTOR - 1] = cryptonight_lite_ipbc_aesni; - } else { - cryptonight_hash_ctx[HASH_FACTOR - 1] = cryptonight_lite_ipbc_softaes; - } - break; - case Options::ALGO_CRYPTONIGHT_HEAVY: if (aesni) { cryptonight_hash_ctx[HASH_FACTOR - 1] = cryptonight_heavy_aesni; @@ -155,7 +143,7 @@ bool CryptoNight::init(int algo, bool aesni) return selfTest(algo); } -void CryptoNight::hash(size_t factor, Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx) +void CryptoNight::hash(size_t factor, PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx) { cryptonight_hash_ctx[factor-1](powVersion, input, size, output, ctx); } @@ -184,113 +172,180 @@ bool CryptoNight::selfTest(int algo) auto ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16); ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 6, 16); - bool resultV1Pow = true; - bool resultV2Pow = true; - bool resultLiteIpbc = true; + bool result = true; + bool resultLite = true; bool resultHeavy = true; if (algo == Options::ALGO_CRYPTONIGHT_HEAVY) { - // cn-heavy tests + // cn-heavy - cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx); + cryptonight_hash_ctx[0](PowVariant::POW_V0, test_input, 76, output, ctx); resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 32) == 0; #if MAX_NUM_HASH_BLOCKS > 1 - cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx); + cryptonight_hash_ctx[1](PowVariant::POW_V0, test_input, 76, output, ctx); resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 64) == 0; #endif #if MAX_NUM_HASH_BLOCKS > 2 - cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx); + cryptonight_hash_ctx[2](PowVariant::POW_V0, test_input, 76, output, ctx); resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 96) == 0; #endif - } else if (algo == Options::ALGO_CRYPTONIGHT_LITE_IPBC) { - // cn-lite-ipbc tests + } else if (algo == Options::ALGO_CRYPTONIGHT_LITE) { + // cn-lite v0 - cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); - resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 32) == 0; + cryptonight_hash_ctx[0](PowVariant::POW_V0, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v0_lite, 32) == 0; #if MAX_NUM_HASH_BLOCKS > 1 - cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); - resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 64) == 0; + cryptonight_hash_ctx[1](PowVariant::POW_V0, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v0_lite, 64) == 0; #endif #if MAX_NUM_HASH_BLOCKS > 2 - cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); - resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 96) == 0; + cryptonight_hash_ctx[2](PowVariant::POW_V0, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v0_lite, 96) == 0; #endif #if MAX_NUM_HASH_BLOCKS > 3 - cryptonight_hash_ctx[3](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); - resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 128) == 0; + cryptonight_hash_ctx[3](PowVariant::POW_V0, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v0_lite, 128) == 0; #endif #if MAX_NUM_HASH_BLOCKS > 4 - cryptonight_hash_ctx[4](Options::PowVersion::POW_AUTODETECT, test_input_lite_ipbc, 43, output, ctx); - resultLiteIpbc = resultLiteIpbc && memcmp(output, test_output_lite_ipbc, 160) == 0; + cryptonight_hash_ctx[4](PowVariant::POW_V0, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v0_lite, 160) == 0; #endif + + // cn-lite v7 tests + + cryptonight_hash_ctx[0](PowVariant::POW_V1, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v1_lite, 32) == 0; + + #if MAX_NUM_HASH_BLOCKS > 1 + cryptonight_hash_ctx[1](PowVariant::POW_V1, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v1_lite, 64) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 2 + cryptonight_hash_ctx[2](PowVariant::POW_V1, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v1_lite, 96) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 3 + cryptonight_hash_ctx[3](PowVariant::POW_V1, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v1_lite, 128) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 4 + cryptonight_hash_ctx[4](PowVariant::POW_V1, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_v1_lite, 160) == 0; + #endif + + + // cn-lite ibpc tests + + cryptonight_hash_ctx[0](PowVariant::POW_IPBC, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_ipbc_lite, 32) == 0; + + #if MAX_NUM_HASH_BLOCKS > 1 + cryptonight_hash_ctx[1](PowVariant::POW_IPBC, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_ipbc_lite, 64) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 2 + cryptonight_hash_ctx[2](PowVariant::POW_IPBC, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_ipbc_lite, 96) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 3 + cryptonight_hash_ctx[3](PowVariant::POW_IPBC, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_ipbc_lite, 128) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 4 + cryptonight_hash_ctx[4](PowVariant::POW_IPBC, test_input, 76, output, ctx); + resultLite = resultLite && memcmp(output, test_output_ipbc_lite, 160) == 0; + #endif + } else { - // < v7 tests autodetect - cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT,test_input, 76, output, ctx); - resultV1Pow = resultV1Pow && - memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, - 32) == 0; + // cn v0 + + cryptonight_hash_ctx[0](PowVariant::POW_V0,test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v0, 32) == 0; #if MAX_NUM_HASH_BLOCKS > 1 - cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx); - resultV1Pow = resultV1Pow && - memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, - 64) == 0; + cryptonight_hash_ctx[1](PowVariant::POW_V0, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v0, 64) == 0; #endif #if MAX_NUM_HASH_BLOCKS > 2 - cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx); - resultV1Pow = resultV1Pow && - memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, - 96) == 0; + cryptonight_hash_ctx[2](PowVariant::POW_V0, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v0, 96) == 0; #endif - // < v7 tests force pow #if MAX_NUM_HASH_BLOCKS > 3 - cryptonight_hash_ctx[3](Options::PowVersion::POW_V1, test_input, 76, output, ctx); - resultV1Pow = resultV1Pow && - memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, - 128) == 0; + cryptonight_hash_ctx[3](PowVariant::POW_V0, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v0, 128) == 0; #endif #if MAX_NUM_HASH_BLOCKS > 4 - cryptonight_hash_ctx[4](Options::PowVersion::POW_V1, test_input, 76, output, ctx); - resultV1Pow = resultV1Pow && - memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, - 160) == 0; + cryptonight_hash_ctx[4](PowVariant::POW_V0, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v0, 160) == 0; #endif - // v7 tests autodetect - cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT, test_input_monero_v2_pow_0, - sizeof(test_input_monero_v2_pow_0), output, ctx); - resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE - ? test_output_monero_v2_pow_light[0] - : test_output_monero_v2_pow[0], 32) == 0; + // cn v7 + + cryptonight_hash_ctx[0](PowVariant::POW_V1, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v1, 32) == 0; #if MAX_NUM_HASH_BLOCKS > 1 - cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input_monero_v2_pow_1, - sizeof(test_input_monero_v2_pow_1), output, ctx); - resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE - ? test_output_monero_v2_pow_light[1] - : test_output_monero_v2_pow[1], 32) == 0; + cryptonight_hash_ctx[1](PowVariant::POW_V1, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v1, 64) == 0; #endif - // v7 tests force pow #if MAX_NUM_HASH_BLOCKS > 2 - cryptonight_hash_ctx[2](Options::PowVersion::POW_V2, test_input_monero_v2_pow_2, - sizeof(test_input_monero_v2_pow_2), output, ctx); - resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE - ? test_output_monero_v2_pow_light[2] - : test_output_monero_v2_pow[2], 32) == 0; + cryptonight_hash_ctx[2](PowVariant::POW_V1, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v1, 96) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 3 + cryptonight_hash_ctx[3](PowVariant::POW_V1, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v1, 128) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 4 + cryptonight_hash_ctx[4](PowVariant::POW_V1, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_v1, 160) == 0; + #endif + + // cn xtl + + cryptonight_hash_ctx[0](PowVariant::POW_XTL,test_input, 76, output, ctx); + result = result && memcmp(output, test_output_xtl, 32) == 0; + + #if MAX_NUM_HASH_BLOCKS > 1 + cryptonight_hash_ctx[1](PowVariant::POW_XTL, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_xtl, 64) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 2 + cryptonight_hash_ctx[2](PowVariant::POW_XTL, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_xtl, 96) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 3 + cryptonight_hash_ctx[3](PowVariant::POW_XTL, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_xtl, 128) == 0; + #endif + + #if MAX_NUM_HASH_BLOCKS > 4 + cryptonight_hash_ctx[4](PowVariant::POW_XTL, test_input, 76, output, ctx); + result = result && memcmp(output, test_output_xtl, 160) == 0; #endif } _mm_free(ctx->memory); _mm_free(ctx); - return resultV1Pow && resultV2Pow & resultLiteIpbc & resultHeavy; + return result && resultLite & resultHeavy; } \ No newline at end of file diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index eb23d715..4032802d 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -34,6 +34,9 @@ #define MEMORY_LITE 1048576 /* 1 MiB */ #define MEMORY_HEAVY 4194304 /* 4 MiB */ +#define POW_DEFAULT_INDEX_SHIFT 3 +#define POW_XLT_V4_INDEX_SHIFT 4 + struct cryptonight_ctx { alignas(16) uint8_t state[MAX_NUM_HASH_BLOCKS][208]; // 208 instead of 200 to maintain aligned to 16 byte boundaries alignas(16) uint8_t* memory; @@ -48,7 +51,7 @@ class CryptoNight public: static bool init(int algo, bool aesni); - static void hash(size_t factor, Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx); + static void hash(size_t factor, PowVariant powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx); private: static bool selfTest(int algo); diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index d5a2150a..d8b9aa48 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -570,7 +570,7 @@ static inline void cn_implode_scratchpad_heavy(const __m128i* input, __m128i* ou } // n-Loop version. Seems to be little bit slower then the hardcoded one. -template +template class CryptoNightMultiHash { public: @@ -697,7 +697,7 @@ public: const uint8_t tmp = reinterpret_cast(&l[hashBlock][idx[hashBlock] & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[hashBlock][idx[hashBlock] & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx[hashBlock] = EXTRACT64(cx); @@ -782,7 +782,7 @@ public: const uint8_t tmp = reinterpret_cast(&l[hashBlock][idx[hashBlock] & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[hashBlock][idx[hashBlock] & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx[hashBlock] = EXTRACT64(cx); @@ -900,8 +900,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -1008,7 +1008,7 @@ public: _mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx)); const uint8_t tmp = reinterpret_cast(&l[idx & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[idx & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx = EXTRACT64(cx); bx = cx; @@ -1078,7 +1078,7 @@ public: _mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx)); const uint8_t tmp = reinterpret_cast(&l[idx & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[idx & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx = EXTRACT64(cx); bx = cx; @@ -1178,8 +1178,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -1329,10 +1329,10 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -1439,10 +1439,10 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -1607,8 +1607,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -1808,13 +1808,13 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -1960,13 +1960,13 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -2199,8 +2199,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -2448,16 +2448,16 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -2640,16 +2640,16 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -2946,8 +2946,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -3243,19 +3243,19 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l4[idx4 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l4[idx4 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -3475,19 +3475,19 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l4[idx4 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l4[idx4 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index b9c735f4..e51f4424 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2016-2017 XMRig + * Copyright 2018 BenDroid * * * This program is free software: you can redistribute it and/or modify @@ -24,177 +25,136 @@ #ifndef __CRYPTONIGHT_TEST_H__ #define __CRYPTONIGHT_TEST_H__ - -const static uint8_t test_input[] = { - 0x01, 0x00, 0xFB, 0x8E, 0x8A, 0xC8, 0x05, 0x89, 0x93, 0x23, 0x37, 0x1B, 0xB7, 0x90, 0xDB, 0x19, - 0x21, 0x8A, 0xFD, 0x8D, 0xB8, 0xE3, 0x75, 0x5D, 0x8B, 0x90, 0xF3, 0x9B, 0x3D, 0x55, 0x06, 0xA9, - 0xAB, 0xCE, 0x4F, 0xA9, 0x12, 0x24, 0x45, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x81, 0x46, 0xD4, 0x9F, - 0xA9, 0x3E, 0xE7, 0x24, 0xDE, 0xB5, 0x7D, 0x12, 0xCB, 0xC6, 0xC6, 0xF3, 0xB9, 0x24, 0xD9, 0x46, - 0x12, 0x7C, 0x7A, 0x97, 0x41, 0x8F, 0x93, 0x48, 0x82, 0x8F, 0x0F, 0x02, - 0x03, 0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00, - 0x7C, 0xBF, 0x34, 0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B, - 0x30, 0x9A, 0xCE, 0x19, 0x23, 0xA0, 0x96, 0x4B, 0x00, 0x00, 0x00, 0x08, 0xBA, 0x93, 0x9A, 0x62, - 0x72, 0x4C, 0x0D, 0x75, 0x81, 0xF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, 0x93, 0x23, 0x37, 0x1B, 0xB7, 0x90, 0xDB, 0x19, - 0x21, 0x8A, 0xFD, 0x8D, 0xB8, 0xE3, 0x75, 0x5D, 0x8B, 0x90, 0xF3, 0x9B, 0x3D, 0x55, 0x06, 0xA9, - 0xAB, 0xCE, 0x4F, 0xA9, 0x12, 0x24, 0x45, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x81, 0x46, 0xD4, 0x9F, - 0xA9, 0x3E, 0xE7, 0x24, 0xDE, 0xB5, 0x7D, 0x12, 0xCB, 0xC6, 0xC6, 0xF3, 0xB9, 0x24, 0xD9, 0x46, - 0x12, 0x7C, 0x7A, 0x97, 0x41, 0x8F, 0x93, 0x48, 0x82, 0x8F, 0x0F, 0x02, - 0x03, 0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00, - 0x7C, 0xBF, 0x34, 0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B, - 0x30, 0x9A, 0xCE, 0x19, 0x23, 0xA0, 0x96, 0x4B, 0x00, 0x00, 0x00, 0x08, 0xBA, 0x93, 0x9A, 0x62, - 0x72, 0x4C, 0x0D, 0x75, 0x81, 0xFC, 0xE5, 0x76, 0x1E, 0x9D, 0x8A, 0x0E, 0x6A, 0x1C, 0x3F, 0x92, - 0x4F, 0xDD, 0x84, 0x93, 0xD1, 0x11, 0x56, 0x49, 0xC0, 0x5E, 0xB6, 0x01 +const static uint8_t test_input[380] = { + 0x03, 0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00, + 0x7C, 0xBF, 0x34, 0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B, + 0x30, 0x9A, 0xCE, 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int8_t test_output_v0[160] = { + 0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7, + 0x1B, 0x31, 0x10, 0xD8, 0x86, 0x01, 0x1E, 0x87, 0x7E, 0xE5, 0x78, 0x6A, 0xFD, 0x08, 0x01, 0x00, + 0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66, + 0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F, + 0xA1, 0xB4, 0xFA, 0xE3, 0xE5, 0x76, 0xCE, 0xCF, 0xB7, 0x9C, 0xAF, 0x3E, 0x29, 0x92, 0xE4, 0xE0, + 0x31, 0x24, 0x05, 0x48, 0xBF, 0x8D, 0x5F, 0x7B, 0x11, 0x03, 0x60, 0xAA, 0xD7, 0x50, 0x3F, 0x0C, + 0x2D, 0x30, 0xF3, 0x87, 0x4F, 0x86, 0xA1, 0x4A, 0xB5, 0xA2, 0x1A, 0x08, 0xD0, 0x44, 0x2C, 0x9D, + 0x16, 0xE9, 0x28, 0x49, 0xA1, 0xFF, 0x85, 0x6F, 0x12, 0xBB, 0x7D, 0xAB, 0x11, 0x1C, 0xE7, 0xF7, + 0x2D, 0x9D, 0x19, 0xE4, 0xD2, 0x26, 0x44, 0x1E, 0xCD, 0x22, 0x08, 0x24, 0xA8, 0x97, 0x46, 0x62, + 0x04, 0x84, 0x90, 0x4A, 0xEE, 0x99, 0x14, 0xED, 0xB8, 0xC6, 0x0D, 0x37, 0xA1, 0x66, 0x17, 0xB0 }; -const static uint8_t test_output_light[] = { - 0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x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const static uint8_t test_output_v1[160] = { + 0xF2, 0x2D, 0x3D, 0x62, 0x03, 0xD2, 0xA0, 0x8B, 0x41, 0xD9, 0x02, 0x72, 0x78, 0xD8, 0xBC, 0xC9, + 0x83, 0xAC, 0xAD, 0xA9, 0xB6, 0x8E, 0x52, 0xE3, 0xC6, 0x89, 0x69, 0x2A, 0x50, 0xE9, 0x21, 0xD9, + 0xC9, 0xFA, 0xE8, 0x42, 0x5D, 0x86, 0x88, 0xDC, 0x23, 0x6B, 0xCD, 0xBC, 0x42, 0xFD, 0xB4, 0x2D, + 0x37, 0x6C, 0x6E, 0xC1, 0x90, 0x50, 0x1A, 0xA8, 0x4B, 0x04, 0xA4, 0xB4, 0xCF, 0x1E, 0xE1, 0x22, + 0xE7, 0x8C, 0x5A, 0x6E, 0x38, 0x30, 0x68, 0x4A, 0x73, 0xFC, 0x1B, 0xC6, 0x6D, 0xFC, 0x8D, 0x98, + 0xB4, 0xC2, 0x23, 0x39, 0xAD, 0xE0, 0x9D, 0xF6, 0x6D, 0x8C, 0x6A, 0xAA, 0xF9, 0xB2, 0xE3, 0x4C, + 0xB6, 0x90, 0x6C, 0xE6, 0x15, 0x5E, 0x46, 0x07, 0x9C, 0xB2, 0x6B, 0xAC, 0x3B, 0xAC, 0x1A, 0xDE, + 0x92, 0x2C, 0xD6, 0x0C, 0x46, 0x9D, 0x9B, 0xC2, 0x84, 0x52, 0x65, 0xF6, 0xBD, 0xFA, 0x0D, 0x74, + 0x00, 0x66, 0x10, 0x07, 0xF1, 0x19, 0x06, 0x3A, 0x6C, 0xFF, 0xEE, 0xB2, 0x40, 0xE5, 0x88, 0x2B, + 0x6C, 0xAB, 0x6B, 0x1D, 0x88, 0xB8, 0x44, 0x25, 0xF4, 0xEA, 0xB7, 0xEC, 0xBA, 0x12, 0x8A, 0x24 }; -const static uint8_t test_input_monero_v2_pow_0[] = { - 0x85, 0x19, 0xe0, 0x39, 0x17, 0x2b, 0x0d, 0x70, 0xe5, 0xca, 0x7b, 0x33, 0x83, 0xd6, 0xb3, 0x16, - 0x73, 0x15, 0xa4, 0x22, 0x74, 0x7b, 0x73, 0xf0, 0x19, 0xcf, 0x95, 0x28, 0xf0, 0xfd, 0xe3, 0x41, - 0xfd, 0x0f, 0x2a, 0x63, 0x03, 0x0b, 0xa6, 0x45, 0x05, 0x25, 0xcf, 0x6d, 0xe3, 0x18, 0x37, 0x66, - 0x9a, 0xf6, 0xf1, 0xdf, 0x81, 0x31, 0xfa, 0xf5, 0x0a, 0xaa, 0xb8, 0xd3, 0xa7, 0x40, 0x55, 0x89 -}; - -const static uint8_t test_input_monero_v2_pow_1[] = { - 0x37, 0xa6, 0x36, 0xd7, 0xda, 0xfd, 0xf2, 0x59, 0xb7, 0x28, 0x7e, 0xdd, 0xca, 0x2f, 0x58, 0x09, - 0x9e, 0x98, 0x61, 0x9d, 0x2f, 0x99, 0xbd, 0xb8, 0x96, 0x9d, 0x7b, 0x14, 0x49, 0x81, 0x02, 0xcc, - 0x06, 0x52, 0x01, 0xc8, 0xbe, 0x90, 0xbd, 0x77, 0x73, 0x23, 0xf4, 0x49, 0x84, 0x8b, 0x21, 0x5d, - 0x29, 0x77, 0xc9, 0x2c, 0x4c, 0x1c, 0x2d, 0xa3, 0x6a, 0xb4, 0x6b, 0x2e, 0x38, 0x96, 0x89, 0xed, - 0x97, 0xc1, 0x8f, 0xec, 0x08, 0xcd, 0x3b, 0x03, 0x23, 0x5c, 0x5e, 0x4c, 0x62, 0xa3, 0x7a, 0xd8, - 0x8c, 0x7b, 0x67, 0x93, 0x24, 0x95, 0xa7, 0x10, 0x90, 0xe8, 0x5d, 0xd4, 0x02, 0x0a, 0x93, 0x00 -}; - -const static uint8_t test_input_monero_v2_pow_2[] = { - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb -}; - -const static uint8_t test_output_monero_v2_pow[3][32] = { - {0x5b, 0xb4, 0x0c, 0x58, 0x80, 0xce, 0xf2, 0xf7, 0x39, 0xbd, 0xb6, 0xaa, 0xaf, 0x16, 0x16, 0x1e, - 0xaa, 0xe5, 0x55, 0x30, 0xe7, 0xb1, 0x0d, 0x7e, 0xa9, 0x96, 0xb7, 0x51, 0xa2, 0x99, 0xe9, 0x49}, - {0x61, 0x3e, 0x63, 0x85, 0x05, 0xba, 0x1f, 0xd0, 0x5f, 0x42, 0x8d, 0x5c, 0x9f, 0x8e, 0x08, 0xf8, - 0x16, 0x56, 0x14, 0x34, 0x2d, 0xac, 0x41, 0x9a, 0xdc, 0x6a, 0x47, 0xdc, 0xe2, 0x57, 0xeb, 0x3e}, - {0xed, 0x08, 0x2e, 0x49, 0xdb, 0xd5, 0xbb, 0xe3, 0x4a, 0x37, 0x26, 0xa0, 0xd1, 0xda, 0xd9, 0x81, - 0x14, 0x60, 0x62, 0xb3, 0x9d, 0x36, 0xd6, 0x2c, 0x71, 0xeb, 0x1e, 0xd8, 0xab, 0x49, 0x45, 0x9b} -}; - -const static uint8_t test_output_monero_v2_pow_light[3][32] = { - {0xbb, 0x19, 0x6c, 0x4c, 0x0c, 0x9d, 0xc1, 0xc4, 0xe4, 0x4c, 0x2a, 0x6f, 0x9e, 0x61, 0x20, 0x0f, - 0xe3, 0xc8, 0xb4, 0xef, 0x23, 0x21, 0x34, 0xe6, 0x5c, 0x3c, 0x78, 0x62, 0xc7, 0xd3, 0xdf, 0x6a}, - {0x45, 0x21, 0x03, 0x73, 0x1d, 0xd8, 0xd7, 0x0c, 0xe3, 0x2f, 0x72, 0x6b, 0x8e, 0x71, 0xfc, 0xd9, - 0x10, 0x05, 0xfb, 0x3c, 0xb2, 0xab, 0xd7, 0x8f, 0x2b, 0x73, 0x57, 0xbb, 0x07, 0xf8, 0xc8, 0xbc}, - {0x4e, 0x78, 0x53, 0x76, 0xed, 0x27, 0x33, 0x26, 0x2d, 0x83, 0xcc, 0x25, 0x32, 0x1a, 0x9d, 0x00, - 0x03, 0xf5, 0x39, 0x53, 0x15, 0xde, 0x91, 0x9a, 0xcf, 0x1b, 0x97, 0xf0, 0xa8, 0x4f, 0xbd, 0x2d} -}; - -const static uint8_t test_input_lite_ipbc[] = { - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, - - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, - - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, - - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, - - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb, - - 0x38, 0x27, 0x4c, 0x97, 0xc4, 0x5a, 0x17, 0x2c, 0xfc, 0x97, 0x67, 0x98, 0x70, 0x42, 0x2e, 0x3a, - 0x1a, 0xb0, 0x78, 0x49, 0x60, 0xc6, 0x05, 0x14, 0xd8, 0x16, 0x27, 0x14, 0x15, 0xc3, 0x06, 0xee, - 0x3a, 0x3e, 0xd1, 0xa7, 0x7e, 0x31, 0xf6, 0xa8, 0x85, 0xc3, 0xcb +// CN XTL +const static uint8_t test_output_xtl[160] = { + 0x8F, 0xE5, 0xF0, 0x5F, 0x02, 0x2A, 0x61, 0x7D, 0xE5, 0x3F, 0x79, 0x36, 0x4B, 0x25, 0xCB, 0xC3, + 0xC0, 0x8E, 0x0E, 0x1F, 0xE3, 0xBE, 0x48, 0x57, 0x07, 0x03, 0xFE, 0xE1, 0xEC, 0x0E, 0xB0, 0xB1, + 0x21, 0x26, 0xFF, 0x98, 0xE6, 0x86, 0x08, 0x5B, 0xC9, 0x96, 0x44, 0xA3, 0xB8, 0x4E, 0x28, 0x90, + 0x76, 0xED, 0xAD, 0xB9, 0xAA, 0xAC, 0x01, 0x94, 0x1D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9E, 0xDB, 0xC7, 0xDF, 0x2E, 0x71, 0x9A, 0x16, 0x97, 0xC4, 0x18, + 0x4B, 0x97, 0x07, 0xFE, 0x5D, 0x98, 0x9A, 0xD6, 0xD8, 0xE5, 0x92, 0x66, 0x87, 0x7F, 0x19, 0x37, + 0xA2, 0x5E, 0xE6, 0x96, 0xB5, 0x97, 0x33, 0x89, 0xE0, 0xA7, 0xC9, 0xDD, 0x4A, 0x7E, 0x9E, 0x53, + 0xBE, 0x91, 0x2B, 0xF5, 0xF5, 0xAF, 0xDD, 0x09, 0xA2, 0xF4, 0xA4, 0x56, 0xEB, 0x96, 0x22, 0xC9, + 0x94, 0xFB, 0x7B, 0x28, 0xC9, 0x97, 0x65, 0x04, 0xAC, 0x4F, 0x84, 0x71, 0xDA, 0x6E, 0xD8, 0xC5 }; -const static uint8_t test_output_heavy[] = { - 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, - 0x1F, 0x1A, 0xA2, 0x5B, 0xFC, 0x0A, 0xAD, 0x82, 0xDE, 0xA8, 0x99, 0x96, 0x88, 0x52, 0xD2, 0x7D, - 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, - 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2, - 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, - 0x1F, 0x1A, 0xA2, 0x5B, 0xFC, 0x0A, 0xAD, 0x82, 0xDE, 0xA8, 0x99, 0x96, 0x88, 0x52, 0xD2, 0x7D, - 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, - 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2, - - 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, - 0x1F, 0x1A, 0xA2, 0x5B, 0xFC, 0x0A, 0xAD, 0x82, 0xDE, 0xA8, 0x99, 0x96, 0x88, 0x52, 0xD2, 0x7D, - 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, - 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2 +// CN-Lite v7 +const static uint8_t test_output_v1_lite[160] = { + 0x6D, 0x8C, 0xDC, 0x44, 0x4E, 0x9B, 0xBB, 0xFD, 0x68, 0xFC, 0x43, 0xFC, 0xD4, 0x85, 0x5B, 0x22, + 0x8C, 0x8A, 0x1B, 0xD9, 0x1D, 0x9D, 0x00, 0x28, 0x5B, 0xEC, 0x02, 0xB7, 0xCA, 0x2D, 0x67, 0x41, + 0x87, 0xC4, 0xE5, 0x70, 0x65, 0x3E, 0xB4, 0xC2, 0xB4, 0x2B, 0x7A, 0x0D, 0x54, 0x65, 0x59, 0x45, + 0x2D, 0xFA, 0xB5, 0x73, 0xB8, 0x2E, 0xC5, 0x2F, 0x15, 0x2B, 0x7F, 0xF9, 0x8E, 0x79, 0x44, 0x6F, + 0x16, 0x08, 0x74, 0xC7, 0xA2, 0xD2, 0xA3, 0x97, 0x95, 0x76, 0xCA, 0x4D, 0x06, 0x39, 0x7A, 0xAB, + 0x6C, 0x87, 0x58, 0x33, 0x4D, 0xC8, 0x5A, 0xAB, 0x04, 0x27, 0xFE, 0x8B, 0x1C, 0x23, 0x2F, 0x32, + 0xC0, 0x44, 0xFF, 0x0D, 0xB5, 0x3B, 0x27, 0x96, 0x06, 0x89, 0x7B, 0xA3, 0x0B, 0xD0, 0xCE, 0x9E, + 0x90, 0x22, 0x77, 0x5A, 0xAD, 0xA1, 0xE5, 0xB6, 0xFC, 0xCB, 0x39, 0x7E, 0x2B, 0x10, 0xEE, 0xB4, + 0x8C, 0x2B, 0xA4, 0x1F, 0x60, 0x76, 0x39, 0xD7, 0xF6, 0x46, 0x77, 0x18, 0x20, 0xAD, 0xD4, 0xC9, + 0x87, 0xF7, 0x37, 0xDA, 0xFD, 0xBA, 0xBA, 0xD2, 0xF2, 0x68, 0xDC, 0x26, 0x8D, 0x1B, 0x08, 0xC6 }; +// CN-Lite IPBC +const static uint8_t test_output_ipbc_lite[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 +}; + + +// CN-Heavy +const static uint8_t test_output_heavy[160] = { + 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, + 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2, + 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, + 0x1F, 0x1A, 0xA2, 0x5B, 0xFC, 0x0A, 0xAD, 0x82, 0xDE, 0xA8, 0x99, 0x96, 0x88, 0x52, 0xD2, 0x7D, + 0x3E, 0xE1, 0x23, 0x03, 0x5A, 0x63, 0x7B, 0x66, 0xF6, 0xD7, 0xC2, 0x2A, 0x34, 0x5E, 0x88, 0xE7, + 0xFA, 0xC4, 0x25, 0x36, 0x54, 0xCB, 0xD2, 0x5C, 0x2F, 0x80, 0x2A, 0xF9, 0xCC, 0x43, 0xF7, 0xCD, + 0xE5, 0x18, 0xA8, 0x05, 0x60, 0x18, 0xA5, 0x73, 0x72, 0x9B, 0x32, 0xDC, 0x69, 0x83, 0xC1, 0xE1, + 0x1F, 0xDB, 0xDA, 0x6B, 0xAC, 0xEC, 0x9F, 0x67, 0xF8, 0x27, 0x1D, 0xC7, 0xE6, 0x46, 0x42, 0xF9, + 0x53, 0x62, 0x0A, 0x54, 0x7D, 0x43, 0xEA, 0x18, 0x94, 0xED, 0xD8, 0x92, 0x06, 0x6A, 0xA1, 0x51, + 0xAD, 0xB1, 0xFD, 0x89, 0xFB, 0x5C, 0xB4, 0x25, 0x6A, 0xDD, 0xB0, 0x09, 0xC5, 0x72, 0x87, 0xEB +}; + #endif /* __CRYPTONIGHT_TEST_H__ */ diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 18488bff..4ebbd1c9 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -468,7 +468,7 @@ static inline void cn_implode_scratchpad_heavy(const __m128i* input, __m128i* ou } // n-Loop version. Seems to be little bit slower then the hardcoded one. -template +template class CryptoNightMultiHash { public: @@ -570,8 +570,7 @@ public: al[hashBlock] = h[hashBlock][0] ^ h[hashBlock][4]; ah[hashBlock] = h[hashBlock][1] ^ h[hashBlock][5]; - bx[hashBlock] = - _mm_set_epi64x(h[hashBlock][3] ^ h[hashBlock][7], h[hashBlock][2] ^ h[hashBlock][6]); + bx[hashBlock] = _mm_set_epi64x(h[hashBlock][3] ^ h[hashBlock][7], h[hashBlock][2] ^ h[hashBlock][6]); idx[hashBlock] = h[hashBlock][0] ^ h[hashBlock][4]; } @@ -586,12 +585,11 @@ public: cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah[hashBlock], al[hashBlock])); } - _mm_store_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK], - _mm_xor_si128(bx[hashBlock], cx)); + _mm_store_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK], _mm_xor_si128(bx[hashBlock], cx)); const uint8_t tmp = reinterpret_cast(&l[hashBlock][idx[hashBlock] & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[hashBlock][idx[hashBlock] & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx[hashBlock] = EXTRACT64(cx); @@ -674,7 +672,7 @@ public: const uint8_t tmp = reinterpret_cast(&l[hashBlock][idx[hashBlock] & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[hashBlock][idx[hashBlock] & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx[hashBlock] = EXTRACT64(cx); @@ -790,8 +788,8 @@ public: }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -892,7 +890,7 @@ public: _mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx)); const uint8_t tmp = reinterpret_cast(&l[idx & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[idx & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx = EXTRACT64(cx); bx = cx; @@ -959,7 +957,7 @@ public: _mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx)); const uint8_t tmp = reinterpret_cast(&l[idx & MASK])[11]; static const uint32_t table = 0x75310; - const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + const uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l[idx & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx = EXTRACT64(cx); bx = cx; @@ -1056,8 +1054,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -1203,10 +1201,10 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -1311,10 +1309,10 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -1478,8 +1476,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -1675,13 +1673,13 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -1825,13 +1823,13 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -2062,8 +2060,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -2307,16 +2305,16 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -2497,16 +2495,16 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -2801,8 +2799,8 @@ public: } }; -template -class CryptoNightMultiHash +template +class CryptoNightMultiHash { public: inline static void hash(const uint8_t* __restrict__ input, @@ -3094,19 +3092,19 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l4[idx4 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l4[idx4 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); @@ -3324,19 +3322,19 @@ public: static const uint32_t table = 0x75310; uint8_t tmp = reinterpret_cast(&l0[idx0 & MASK])[11]; - uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + uint8_t index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l0[idx0 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l1[idx1 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l1[idx1 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l2[idx2 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l2[idx2 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l3[idx3 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l3[idx3 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); tmp = reinterpret_cast(&l4[idx4 & MASK])[11]; - index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; + index = (((tmp >> INDEX_SHIFT) & 6) | (tmp & 1)) << 1; ((uint8_t*)(&l4[idx4 & MASK]))[11] = tmp ^ ((table >> index) & 0x30); idx0 = EXTRACT64(cx0); diff --git a/src/net/BoostConnection.h b/src/net/BoostConnection.h index 7f74ec5c..31b19f0f 100644 --- a/src/net/BoostConnection.h +++ b/src/net/BoostConnection.h @@ -71,10 +71,14 @@ public: { if (isConnected()) { LOG_DEBUG("[%s:%d] Disconnecting", getConnectedIp().c_str(), getConnectedPort()); + + boost::system::error_code ec; + socket_.get().lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); socket_.get().lowest_layer().close(); } ioService_.stop(); + ioService_.reset(); } bool isConnected() const override diff --git a/src/net/Client.cpp b/src/net/Client.cpp index db19db38..b9300d06 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -30,6 +30,8 @@ #include #include +#include "PowVariant.h" + #include "interfaces/IClientListener.h" #include "log/Log.h" #include "net/Client.h" @@ -224,26 +226,34 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } - if (params.HasMember("variant")) { - int variantFromProxy = params["variant"].GetInt(); + PowVariant powVariant = Options::i()->powVariant(); - switch (variantFromProxy) { - case -1: - job.setPowVersion(Options::POW_AUTODETECT); - break; - case 0: - job.setPowVersion(Options::POW_V1); - break; - case 1: - job.setPowVersion(Options::POW_V2); - break; - default: - break; + if (params.HasMember("algo")) { + std::string algo = params["algo"].GetString(); + + if (algo.find("/") != std::string::npos) { + powVariant = parseVariant(algo.substr(algo.find("/")+1)); } - } else { - job.setPowVersion(Options::i()->forcePowVersion()); } + if (params.HasMember("variant")) { + const rapidjson::Value &variant = params["variant"]; + + PowVariant parsedVariant = powVariant; + + if (variant.IsInt()) { + parsedVariant = parseVariant(variant.GetInt()); + } else if (variant.IsString()) { + parsedVariant = parseVariant(variant.GetString()); + } + + if (parsedVariant != POW_AUTODETECT) { + powVariant = parsedVariant; + } + } + + job.setPowVariant(powVariant); + if (m_job != job) { m_jobs++; m_job = std::move(job); @@ -350,6 +360,15 @@ void Client::login() params.AddMember("pass", rapidjson::StringRef(m_url.password()), allocator); params.AddMember("agent", rapidjson::StringRef(m_agent), allocator); + params.AddMember("algo", rapidjson::StringRef(Options::i()->algoShortName()), allocator); + + rapidjson::Value supportedPowVariantsList(rapidjson::kArrayType); + for (auto& supportedPowVariant : getSupportedPowVariants()) { + supportedPowVariantsList.PushBack(rapidjson::StringRef(supportedPowVariant.c_str()), allocator); + } + + params.AddMember("supported-variants", supportedPowVariantsList, allocator); + doc.AddMember("params", params, allocator); rapidjson::StringBuffer buffer(0, 512); diff --git a/src/net/Connection.cpp b/src/net/Connection.cpp index 9405025a..c663df33 100644 --- a/src/net/Connection.cpp +++ b/src/net/Connection.cpp @@ -82,6 +82,10 @@ Connection::Ptr establishConnection(const ConnectionListener::Ptr& listener, } catch (...) { LOG_ERR("[%s:%d] Failed to establish connection: %s", host.c_str(), port, boost::current_exception_diagnostic_information().c_str()); + + if (connection) { + connection->disconnect(); + } } diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 23dd85b0..e73cf0e4 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -62,7 +62,7 @@ Job::Job(int poolId, bool nicehash) : m_size(0), m_diff(0), m_target(0), - m_powVersion(Options::POW_AUTODETECT) + m_powVariant(PowVariant::POW_AUTODETECT) { } @@ -136,6 +136,21 @@ bool Job::setTarget(const char *target) return true; } +PowVariant Job::powVariant() const +{ + if (m_powVariant == PowVariant::POW_AUTODETECT) + { + return (m_blob[0] > 6 ? PowVariant::POW_V1 : PowVariant::POW_V0); + } + else if (m_powVariant == PowVariant::POW_XTL && m_blob[0] < 4) + { + return POW_V1; + } + else + { + return m_powVariant; + } +} bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) { @@ -150,7 +165,6 @@ bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) return true; } - void Job::toHex(const unsigned char* in, unsigned int len, char* out) { for (unsigned int i = 0; i < len; i++) { @@ -159,7 +173,6 @@ void Job::toHex(const unsigned char* in, unsigned int len, char* out) } } - bool Job::operator==(const Job &other) const { return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; diff --git a/src/net/Job.h b/src/net/Job.h index 01502b18..4bd4642c 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -41,6 +41,7 @@ public: bool setBlob(const char *blob); bool setTarget(const char *target); + PowVariant powVariant() const; inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } @@ -49,15 +50,13 @@ public: inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } inline int poolId() const { return m_poolId; } - inline int threadId() const { return m_threadId; } - inline Options::PowVersion powVersion() const { return m_powVersion; } inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } inline uint32_t diff() const { return (uint32_t) m_diff; } inline uint64_t target() const { return m_target; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } inline void setThreadId(int threadId) { m_threadId = threadId; } - inline void setPowVersion(Options::PowVersion powVersion) { m_powVersion = powVersion; } + inline void setPowVariant(PowVariant powVariant) { m_powVariant = powVariant; } static bool fromHex(const char* in, unsigned int len, unsigned char* out); static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast(blob + 39); } @@ -77,7 +76,7 @@ private: size_t m_size; uint64_t m_diff; uint64_t m_target; - Options::PowVersion m_powVersion; + PowVariant m_powVariant; }; #endif /* __JOB_H__ */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 9a929711..7eeb7dba 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -170,12 +170,11 @@ void Network::onResultAccepted(Client *client, const SubmitResult &result, const void Network::setJob(Client *client, const Job &job) { if (m_options->colors()) { - LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m with diff \x1B[01;37m%d\x1B[0m and PoW \x1B[01;37mv%d", - client->host(), client->port(), job.diff(), job.powVersion()); + LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m with diff \x1B[01;37m%d\x1B[0m and PoW \x1B[01;37m%s", + client->host(), client->port(), job.diff(), getPowVariantName(job.powVariant()).c_str()); } else { - LOG_INFO("new job from %s:%d with diff %d and PoW v%d", - client->host(), client->port(), job.diff(), job.powVersion()); + LOG_INFO("new job from %s:%d with diff %d and PoW %s", client->host(), client->port(), job.diff(), getPowVariantName(job.powVariant()).c_str()); } m_state.diff = job.diff(); diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 8e2d1561..bcd059b3 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -58,30 +58,18 @@ DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : #ifndef XMRIG_NO_TLS if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_HEAVY) { url = new Url("donate2.graef.in", 8443, userId, nullptr, true, false, true); - } else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE_IPBC) { + } else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE) { url = new Url("donate2.graef.in", 1080, userId, nullptr, true, false, true); } else { - if (Options::i()->forcePowVersion() == Options::POW_V1) { - url = new Url("donate.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 8080 : 8081, userId, nullptr, true, false, true); - } else if (Options::i()->forcePowVersion() == Options::POW_V2) { - url = new Url("donate2.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 995 : 993, userId, nullptr, true, false, true); - } else { - url = new Url("donate2.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 8081 : 443, userId, nullptr, true, false, true); - } + url = new Url("donate2.graef.in", 443, userId, nullptr, true, false, true); } #else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_HEAVY) { url = new Url("donate.graef.in", 8443, userId, nullptr, false, false, true); - } else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE_IPBC) { + } else if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE) { url = new Url("donate.graef.in", 1080, userId, nullptr, false, false, true); } else { - if (Options::i()->forcePowVersion() == Options::POW_V1) { - url = new Url("donate.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 80 : 443, userId, nullptr, false, false, true); - } else if (Options::i()->forcePowVersion() == Options::POW_V2) { - url = new Url("donate.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 995 : 993, userId, nullptr, false, false, true); - } else { - url = new Url("donate2.graef.in", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 8080 : 80, userId, nullptr, false, false, true); - } + url = new Url("donate2.graef.in", 80, userId, nullptr, false, false, true); } #endif diff --git a/src/version.h b/src/version.h index bc101ced..5f85da28 100644 --- a/src/version.h +++ b/src/version.h @@ -36,14 +36,14 @@ #define APP_DESC "XMRigCC CPU miner" #define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id" #endif -#define APP_VERSION "1.6.2 (based on XMRig 2.5.2)" +#define APP_VERSION "1.6.3 (based on XMRig)" #define APP_DOMAIN "" #define APP_SITE "https://github.com/Bendr0id/xmrigCC" #define APP_KIND "cpu" #define APP_VER_MAJOR 1 #define APP_VER_MINOR 6 -#define APP_VER_BUILD 2 +#define APP_VER_BUILD 3 #define APP_VER_REV 0 #ifndef NDEBUG diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 14a0fde5..d1d16ad6 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -120,7 +120,7 @@ void MultiWorker::start() *Job::nonce(m_state->blob + i * m_state->job.size()) = ++m_state->nonces[i]; } - CryptoNight::hash(m_hashMultiplier, m_state->job.powVersion(), m_state->blob, m_state->job.size(), m_hash, m_ctx); + CryptoNight::hash(m_hashMultiplier, m_state->job.powVariant(), m_state->blob, m_state->job.size(), m_hash, m_ctx); for (size_t i=0; i < m_hashMultiplier; ++i) { if (*reinterpret_cast(m_hash + 24 + i * 32) < m_state->job.target()) { From e3b1a800390f5787c5d94b1b0ae1e0aaf3265d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Thu, 24 May 2018 10:54:42 +0200 Subject: [PATCH 009/188] Update Dockerfile --- Dockerfile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4291fd78..f5059597 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,9 @@ FROM ubuntu:latest RUN apt-get update && \ - apt-get install software-properties-common git build-essential libbz2-dev cmake libuv1-dev libssl-dev wget -y - -RUN add-apt-repository ppa:jonathonf/gcc-7.1 && \ - apt-get update && \ - apt-get install gcc-7 g++-7 -y && \ + apt-get install software-properties-common git build-essential libbz2-dev cmake libuv1-dev libssl-dev wget gcc g++ -y \ apt-get clean && \ - rm -rf /var/lib/apt/lists/* + rm -rf /var/lib/apt/lists/* RUN wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz \ && tar xfz boost_1_66_0.tar.gz \ @@ -18,7 +14,7 @@ RUN wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar. RUN git clone https://github.com/Bendr0id/xmrigCC.git && \ cd xmrigCC && \ - cmake . -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 -DWITH_CC_SERVER=OFF -DWITH_HTTPD=OFF && \ + cmake . -DWITH_CC_SERVER=OFF -DWITH_HTTPD=OFF && \ make COPY Dockerfile /Dockerfile From e65ea5594ce3595ede67cbfcdcf359eeab04aa09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Thu, 24 May 2018 11:03:59 +0200 Subject: [PATCH 010/188] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f5059597..ca0f4d05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM ubuntu:latest RUN apt-get update && \ - apt-get install software-properties-common git build-essential libbz2-dev cmake libuv1-dev libssl-dev wget gcc g++ -y \ - apt-get clean && \ + apt install software-properties-common git build-essential libbz2-dev cmake libuv1-dev libssl-dev wget gcc g++ -y && \ + apt clean && \ rm -rf /var/lib/apt/lists/* RUN wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz \ From 58bafab2438482d7275c9cf991788524e6f65c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Thu, 24 May 2018 16:07:09 +0200 Subject: [PATCH 011/188] Update appveyor.yml --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 65ae7df1..40ac70f4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,7 @@ clone_folder: c:\xmrigCC install: - mkdir c:\xmrigCC-deps - - curl -sL https://github.com/Bendr0id/xmrigCC-deps/releases/download/v1/xmrigCC-deps.zip -o xmrigCC-deps.zip + - curl -sL https://github.com/Bendr0id/xmrigCC-deps/releases/download/v2/xmrigCC-deps.zip -o xmrigCC-deps.zip - 7z x xmrigCC-deps.zip -o"c:\xmrigCC-deps" -y > nul build_script: From 1c4914b64e03abe6459d4e50c762f3cf457709ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Thu, 24 May 2018 21:13:43 +0200 Subject: [PATCH 012/188] Updated default configs and help printout --- src/Options.cpp | 16 +++++++++++----- src/config.json | 17 ++++------------- src/default_config.json | 17 ++++------------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 93b9980e..3c370213 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -69,14 +69,14 @@ Options:\n" -u, --user=USERNAME username for mining server\n\ -p, --pass=PASSWORD password for mining server\n\ -t, --threads=N number of miner threads\n\ - -v, --av=N algorithm variation, 0 auto select\n\ -A, --aesni=N selection of AES-NI mode (0 auto, 1 on, 2 off)\n\ -k, --keepalive send keepalived for prevent timeout (need pool support)\n\ -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ - --force-pow-version=N force to use specific PoW variation (default: 0 POW_AUTODETECT, 1 POW_V0, 2 POW_MONERO_V7)\n\ - --multihash-factor=N number of hash blocks to process at a time (not set or 0 enables automatic selection of optimal number of hash blocks)\n\ - --multihash-thread-mask for av=2/4 only, limits multihash to given threads (mask), (default: all threads)\n\ + --pow-variant=V specificy the PoW variat to use: -> auto (default), 0 (v0), 1 (v1, aka monerov7, aeonv7), ipbc (tube), alloy, xtl (including autodetect for v5)\n\ + for further help see: https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations\n\ + --multihash-factor=N number of hash blocks to process at a time (don't set or 0 enables automatic selection of optimal number of hash blocks)\n\ + --multihash-thread-mask=MASK limits multihash to given threads (mask), (default: all threads)\n\ --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --no-huge-pages disable huge pages support\n\ @@ -981,7 +981,7 @@ bool Options::parsePowVariant(const char *powVariant) break; } - if (i == ARRAY_SIZE(pow_variant_names) - 1 && !strcmp(powVariant, "auto")) { + if (i == ARRAY_SIZE(pow_variant_names) - 1 && (!strcmp(powVariant, "auto") || !strcmp(powVariant, "-1"))) { m_powVariant = POW_AUTODETECT; break; } @@ -996,6 +996,12 @@ bool Options::parsePowVariant(const char *powVariant) break; } + + if (i == ARRAY_SIZE(pow_variant_names) - 1 && !strcmp(powVariant, "tube")) { + m_powVariant = POW_IPBC; + break; + } + if (i == ARRAY_SIZE(pow_variant_names) - 1) { showUsage(1); return false; diff --git a/src/config.json b/src/config.json index 9c73e15c..f1c86923 100644 --- a/src/config.json +++ b/src/config.json @@ -1,22 +1,18 @@ { - "algo": "cryptonight", // cryptonight (default), cryptonight-lite, cryptonight-lite-ipbc or cryptopnight-heavy - "av": null, // DEPRECATED: algorithm variation, (0 auto, - // 1 -> (aesni=1, multihash-factor=1), - // 2 -> (aesni=1, multihash-factor=2), - // 3 -> (aesni=2, multihash-factor=1), - // 4 -> (aesni=2, multihash-factor=2)) + "algo": "cryptonight", // cryptonight (default), cryptonight-lite or cryptopnight-heavy "aesni": 0, // selection of AES-NI mode (0 auto, 1 on, 2 off) "threads": 0, // number of miner threads (not set or 0 enables automatic selection of optimal thread count) "multihash-factor": 0, // number of hash blocks to process at a time (not set or 0 enables automatic selection of optimal number of hash blocks) "multihash-thread-mask" : null, // for multihash-factors>0 only, limits multihash to given threads (mask), mask "0x3" means run multihash on thread 0 and 1 only (default: all threads) - "force-pow-version" : 0, // force to use specific PoW variation (default: 0 POW_AUTODETECT, 1 POW_V1, 2 POW_V2) + "pow-variant" : "auto", // specificy the PoW variat to use: -> auto (default), 0 (v0), 1 (v1, aka monerov7, aeonv7), ipbc (tube), alloy, xtl (including autodetect for v5) + // for further help see: https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations "background": false, // true to run the miner in the background (Windows only, for *nix plase use screen/tmux or systemd service instead) "colors": true, // false to disable colored output "cpu-affinity": null, // set process affinity to CPU core(s), mask "0x3" for cores 0 and 1 "cpu-priority": null, // set process priority (0 idle, 2 normal to 5 highest) "donate-level": 5, // donate level, mininum 1% "log-file": null, // log all output to a file, example: "c:/some/path/xmrig.log" - "max-cpu-usage": 75, // maximum CPU usage for automatic mode, usually limiting factor is CPU cache not this option. + "max-cpu-usage": 100, // maximum CPU usage for automatic mode, usually limiting factor is CPU cache not this option. "print-time": 60, // print hashrate report every N seconds "retries": 5, // number of times to retry before switch to backup server "retry-pause": 5, // time to pause between retries @@ -32,11 +28,6 @@ "nicehash": false // enable nicehash/xmrig-proxy support } ], - "api": { - "port": 0, // port for the miner API https://github.com/xmrig/xmrig/wiki/API - "access-token": null, // access token for API - "worker-id": null // custom worker-id for API - }, "cc-client": { "url": "localhost:3344", // url of the CC Server (ip:port) "use-tls" : false, // enable tls for CC communication (needs to be enabled on CC Server too) diff --git a/src/default_config.json b/src/default_config.json index 3dc4ae32..f1c86923 100644 --- a/src/default_config.json +++ b/src/default_config.json @@ -1,22 +1,18 @@ { - "algo": "cryptonight", // cryptonight (default), cryptonight-lite, cryptonight-lite-ipbc or cryptopnight-heavy - "av": null, // DEPRECATED: algorithm variation, (0 auto, - // 1 -> (aesni=1, multihash-factor=1), - // 2 -> (aesni=1, multihash-factor=2), - // 3 -> (aesni=2, multihash-factor=1), - // 4 -> (aesni=2, multihash-factor=2)) + "algo": "cryptonight", // cryptonight (default), cryptonight-lite or cryptopnight-heavy "aesni": 0, // selection of AES-NI mode (0 auto, 1 on, 2 off) "threads": 0, // number of miner threads (not set or 0 enables automatic selection of optimal thread count) "multihash-factor": 0, // number of hash blocks to process at a time (not set or 0 enables automatic selection of optimal number of hash blocks) "multihash-thread-mask" : null, // for multihash-factors>0 only, limits multihash to given threads (mask), mask "0x3" means run multihash on thread 0 and 1 only (default: all threads) - "force-pow-version" : 0, // force to use specific PoW variation (default: 0 POW_AUTODETECT, 1 POW_V1, 2 POW_V2) + "pow-variant" : "auto", // specificy the PoW variat to use: -> auto (default), 0 (v0), 1 (v1, aka monerov7, aeonv7), ipbc (tube), alloy, xtl (including autodetect for v5) + // for further help see: https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations "background": false, // true to run the miner in the background (Windows only, for *nix plase use screen/tmux or systemd service instead) "colors": true, // false to disable colored output "cpu-affinity": null, // set process affinity to CPU core(s), mask "0x3" for cores 0 and 1 "cpu-priority": null, // set process priority (0 idle, 2 normal to 5 highest) "donate-level": 5, // donate level, mininum 1% "log-file": null, // log all output to a file, example: "c:/some/path/xmrig.log" - "max-cpu-usage": 75, // maximum CPU usage for automatic mode, usually limiting factor is CPU cache not this option. + "max-cpu-usage": 100, // maximum CPU usage for automatic mode, usually limiting factor is CPU cache not this option. "print-time": 60, // print hashrate report every N seconds "retries": 5, // number of times to retry before switch to backup server "retry-pause": 5, // time to pause between retries @@ -32,11 +28,6 @@ "nicehash": false // enable nicehash/xmrig-proxy support } ], - "api": { - "port": 0, // port for the miner API https://github.com/xmrig/xmrig/wiki/API - "access-token": null, // access token for API - "worker-id": null // custom worker-id for API - }, "cc-client": { "url": "localhost:3344", // url of the CC Server (ip:port) "use-tls" : false, // enable tls for CC communication (needs to be enabled on CC Server too) From 7d667ef9c51bf02e38c898b6c575e301401cda94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Fri, 25 May 2018 11:07:38 +0200 Subject: [PATCH 013/188] Update README.md --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 25533065..e85605f5 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,10 @@ ### About XMRigCC XMRigCC is a fork of [XMRig](https://github.com/xmrig/xmrig) which adds the ability to remote control your XMRig instances via a Webfrontend and REST api. -This fork is based on XMRig (2.4.5) and adds a "Command and Control" (C&C) server, a daemon to reload XMRig on config changes and modifications in XMRig to send the current status to the C&C Server. -The modified version can also handle commands like "update config", "start/stop mining" or "restart/shutdown" which can be send from the C&C-Server. +This fork is based on XMRig and adds a "Command and Control" (C&C) server, a daemon to reload XMRigCCMiner on config changes and modifications in XMRig to send the current status to the C&C Server. +The modified version can also handle commands like "update config", "start/stop mining" or "restart/shutdown" which can be send from the C&C-Server. + +**AND MANY MORE** Full Windows/Linux compatible, and you can mix Linux and Windows miner on one XMRigCCServer. @@ -124,15 +126,15 @@ xmrigDaemon -o pool.minemonero.pro:5555 -u YOUR_WALLET -p x -k --cc-url=IP_OF_CC -O, --userpass=U:P username:password pair for mining server -u, --user=USERNAME username for mining server -p, --pass=PASSWORD password for mining server - -t, --threads=N number of miner threads (0 enables automatic selection of optimal number of threads, default: 0) - -m, --multihash-factor=N number of hash blocks per thread to process at a time (0 enables automatic selection of optimal number of hash blocks, default: 0) - -A, --aesni=N selection of AES-NI mode (0 auto, 1 on, 2 off, default: 0) + -t, --threads=N number of miner threads + -A, --aesni=N selection of AES-NI mode (0 auto, 1 on, 2 off) -k, --keepalive send keepalived for prevent timeout (need pool support) -r, --retries=N number of times to retry before switch to backup server (default: 5) -R, --retry-pause=N time to pause between retries (default: 5) - --force-pow-version=N force to use specific PoW variation (default: 0 POW_AUTODETECT, 1 POW_V1, 2 POW_V2) - --multihash-factor=N number of hash blocks to process at a time (not set or 0 enables automatic selection of optimal number of hash blocks) - --multihash-thread-mask for multihash-factor > 1 only, limits multihash to given threads (mask), (default: all threads) + --pow-variant=V specificy the PoW variat to use: -> auto (default), 0 (v0), 1 (v1, aka monerov7, aeonv7), ipbc (tube), alloy, xtl (including autodetect for v5) + for further help see: https://github.com/Bendr0id/xmrigCC/wiki/Coin-configurations + --multihash-factor=N number of hash blocks to process at a time (don't set or 0 enables automatic selection of optimal number of hash blocks) + --multihash-thread-mask=MASK limits multihash to given threads (mask), (default: all threads) --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1 --cpu-priority set process priority (0 idle, 2 normal to 5 highest) --no-huge-pages disable huge pages support @@ -158,9 +160,6 @@ xmrigDaemon -o pool.minemonero.pro:5555 -u YOUR_WALLET -p x -k --cc-url=IP_OF_CC -l, --log-file=FILE log all output to a file -h, --help display this help and exit -V, --version output version information and exit - -v, --av=N DEPRECATED - algorithm variation, 0 auto select - --doublehash-thread-mask DEPRECATED - same as multihash-thread-mask - ``` Also you can use configuration via config file, default **[config.json](https://github.com/Bendr0id/xmrigCC/wiki/Config-XMRigDaemon)**. You can load multiple config files and combine it with command line options. From 872fce72b5bf1b7ddb1daa097b50b5a6545569ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Thu, 7 Jun 2018 10:21:01 +0200 Subject: [PATCH 014/188] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e85605f5..f4b37160 100644 --- a/README.md +++ b/README.md @@ -285,4 +285,5 @@ BTC: `1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT` ## Contact * ben [at] graef.in * Telegram: @BenDr0id +* [discord](https://discord.gg/r3rCKTB) * [reddit](https://www.reddit.com/user/BenDr0id/) From b379f21cb3d76e16240e28773b2ce30f111dad47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Tue, 12 Jun 2018 09:15:04 +0200 Subject: [PATCH 015/188] Fix connection issues and add enhancement to the Dashboard (#130) * Fix connection errors when doing DNS lookup * Fix connection handling when an error occurs * Add remote logging feature * Add algo variant to dashboard --- CMakeLists.txt | 1 + index.html | 87 +++++++++++++++++++++++++++++++----- src/App.cpp | 6 ++- src/Options.cpp | 32 ++++++++++++-- src/Options.h | 4 ++ src/api/NetworkState.h | 2 + src/cc/CCClient.cpp | 29 ++++++++---- src/cc/CCClient.h | 14 +++--- src/cc/ClientStatus.cpp | 32 ++++++++++++++ src/cc/ClientStatus.h | 8 ++++ src/config.json | 2 + src/default_config.json | 2 + src/log/FileLog.cpp | 5 ++- src/log/RemoteLog.cpp | 93 +++++++++++++++++++++++++++++++++++++++ src/log/RemoteLog.h | 48 ++++++++++++++++++++ src/net/BoostConnection.h | 58 ++++++++++++++---------- src/net/Connection.cpp | 4 +- src/net/Connection.h | 7 +-- src/net/Network.cpp | 1 + src/version.h | 4 +- 20 files changed, 377 insertions(+), 62 deletions(-) create mode 100644 src/log/RemoteLog.cpp create mode 100644 src/log/RemoteLog.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ffcbc8f4..4686286a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ set(SOURCES_COMMON src/Options.cpp src/log/ConsoleLog.cpp src/log/FileLog.cpp + src/log/RemoteLog.cpp src/log/Log.cpp src/Platform.cpp src/Cpu.cpp diff --git a/index.html b/index.html index 5a999dfb..52eb308d 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ - +