Implemented Monero v1 pow changes

* Adds arm implementation and test code for single hash
* Fixed build break for when APP_DEBUG is set
* Applied new icons / design
This commit is contained in:
sebastianstolzenberg 2018-03-13 20:19:20 +01:00 committed by Ben Gräf
parent 3f46dfeb08
commit 278720f5e9
9 changed files with 317 additions and 19 deletions

2
.gitignore vendored
View file

@ -5,7 +5,7 @@
/.idea
/CMakeFiles
/src/3rdparty
/cmake-build-debug
/cmake-build-*
CMakeCache.txt
cmake_install.cmake
Makefile

View file

@ -10,6 +10,8 @@
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.4/css/select.dataTables.min.css">
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<link rel="shortcut icon" href="http://root.graef.in/static/xmrigcc/favicon.ico">
<style>
.right{text-align:right;}
.left{text-align:left;}
@ -583,7 +585,7 @@
<div id="statusBar"></div>
<div class="center">
<h1>XMRigCC Dashboard</h1>
<img src="http://root.graef.in/static/xmrigcc/banner.png"/>
</div>
<form style="padding-bottom: 25px">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Before After
Before After

View file

@ -105,7 +105,7 @@ bool CryptoNight::selfTest(int algo)
{
if (cryptonight_hash_ctx[0] == nullptr || cryptonight_hash_ctx[2] == nullptr ||
cryptonight_hash_ctx[2] == nullptr || cryptonight_hash_ctx[3] == nullptr ||
cryptonight_hash_ctx[4] == nullptr) {
cryptonight_hash_ctx[4] == nullptr) {
return false;
}
@ -115,22 +115,35 @@ bool CryptoNight::selfTest(int algo)
ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 6, 16);
cryptonight_hash_ctx[0](test_input, 76, output, ctx);
bool resultSingle = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 32) == 0;
bool resultSingle = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, 32) == 0;
cryptonight_hash_ctx[1](test_input, 76, output, ctx);
bool resultDouble = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 64) == 0;
bool resultDouble = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, 64) == 0;
cryptonight_hash_ctx[2](test_input, 76, output, ctx);
bool resultTriple = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 96) == 0;
bool resultTriple = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, 96) == 0;
cryptonight_hash_ctx[3](test_input, 76, output, ctx);
bool resultQuadruple = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 128) == 0;
bool resultQuadruple = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, 128) == 0;
cryptonight_hash_ctx[4](test_input, 76, output, ctx);
bool resultQuintuple = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 160) == 0;
bool resultQuintuple = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output, 160) == 0;
// monero v1 pow
bool resultV1Pow = true;
if (algo == Options::ALGO_CRYPTONIGHT)
{
cryptonight_hash_ctx[0](test_input_monero_v1_pow_0, sizeof(test_input_monero_v1_pow_0), output, ctx);
resultV1Pow = resultV1Pow &&memcmp(output, test_output_monero_v1_pow[0], 32) == 0;
cryptonight_hash_ctx[1](test_input_monero_v1_pow_1, sizeof(test_input_monero_v1_pow_1), output, ctx);
resultV1Pow = resultV1Pow &&memcmp(output, test_output_monero_v1_pow[1], 32) == 0;
cryptonight_hash_ctx[2](test_input_monero_v1_pow_2, sizeof(test_input_monero_v1_pow_2), output, ctx);
resultV1Pow = resultV1Pow &&memcmp(output, test_output_monero_v1_pow[2], 32) == 0;
//TODO test multihashs
}
_mm_free(ctx->memory);
_mm_free(ctx);
return resultSingle && resultDouble && resultTriple && resultQuadruple && resultQuintuple;
return resultSingle && resultDouble && resultTriple && resultQuadruple && resultQuintuple && resultV1Pow;
}

View file

@ -36,6 +36,7 @@
#include "crypto/CryptoNight.h"
#include "crypto/CryptoNight_monero.h"
#include "crypto/soft_aes.h"
@ -370,10 +371,19 @@ public:
uint64_t ah[NUM_HASH_BLOCKS];
__m128i bx[NUM_HASH_BLOCKS];
uint64_t idx[NUM_HASH_BLOCKS];
uint64_t tweak1_2[NUM_HASH_BLOCKS];
uint64_t version[NUM_HASH_BLOCKS];
for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) {
keccak(static_cast<const uint8_t*>(input) + hashBlock * size, (int) size,
ctx->state[hashBlock], 200);
version[hashBlock] = static_cast<const uint8_t*>(input)[hashBlock * size];
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
tweak1_2[hashBlock] = (*reinterpret_cast<const uint64_t*>(reinterpret_cast<const uint8_t*>(input) + 35 + hashBlock * size) ^
*(reinterpret_cast<const uint64_t*>(ctx->state[hashBlock]) + 24));
}
}
}
for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) {
@ -402,6 +412,16 @@ public:
_mm_store_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK],
_mm_xor_si128(bx[hashBlock], cx));
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
const uint8_t tmp = reinterpret_cast<const uint8_t*>(&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;
@ -413,9 +433,21 @@ public:
al[hashBlock] += hi;
ah[hashBlock] += lo;
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
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];
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
ah[hashBlock] ^= tweak1_2[hashBlock];
}
}
ah[hashBlock] ^= ch;
al[hashBlock] ^= cl;
idx[hashBlock] = al[hashBlock];
@ -449,6 +481,8 @@ public:
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state[0], 200);
VARIANT1_INIT(0);
l = ctx->memory;
h = reinterpret_cast<uint64_t*>(ctx->state[0]);
@ -473,6 +507,7 @@ public:
}
_mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx));
VARIANT1_1(&l[idx & MASK], 0);
idx = EXTRACT64(cx);
bx = cx;
@ -484,8 +519,10 @@ public:
al += hi;
ah += lo;
VARIANT1_2(ah, 0);
((uint64_t*) &l[idx & MASK])[0] = al;
((uint64_t*) &l[idx & MASK])[1] = ah;
VARIANT1_2(ah, 0);
ah ^= ch;
al ^= cl;
@ -510,6 +547,9 @@ public:
keccak((const uint8_t*) input, (int) size, ctx->state[0], 200);
keccak((const uint8_t*) input + size, (int) size, ctx->state[1], 200);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state[0]);
@ -549,6 +589,9 @@ public:
_mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
_mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
@ -563,8 +606,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -577,8 +622,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -609,6 +656,10 @@ public:
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);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
VARIANT1_INIT(2);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
const uint8_t* l2 = ctx->memory + 2 * MEM;
@ -660,6 +711,10 @@ public:
_mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
_mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
VARIANT1_1(&l2[idx2 & MASK], 2);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
idx2 = EXTRACT64(cx2);
@ -677,8 +732,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -692,8 +749,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -707,8 +766,10 @@ public:
al2 += hi;
ah2 += lo;
VARIANT1_2(ah2, 2);
((uint64_t*) &l2[idx2 & MASK])[0] = al2;
((uint64_t*) &l2[idx2 & MASK])[1] = ah2;
VARIANT1_2(ah2, 2);
ah2 ^= ch;
al2 ^= cl;
@ -743,6 +804,11 @@ public:
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);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
VARIANT1_INIT(2);
VARIANT1_INIT(3);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
const uint8_t* l2 = ctx->memory + 2 * MEM;
@ -806,6 +872,11 @@ public:
_mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2));
_mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
VARIANT1_1(&l2[idx2 & MASK], 2);
VARIANT1_1(&l3[idx3 & MASK], 3);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
idx2 = EXTRACT64(cx2);
@ -825,8 +896,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -840,8 +913,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -855,8 +930,10 @@ public:
al2 += hi;
ah2 += lo;
VARIANT1_2(ah2, 2);
((uint64_t*) &l2[idx2 & MASK])[0] = al2;
((uint64_t*) &l2[idx2 & MASK])[1] = ah2;
VARIANT1_2(ah2, 2);
ah2 ^= ch;
al2 ^= cl;
@ -870,8 +947,10 @@ public:
al3 += hi;
ah3 += lo;
VARIANT1_2(ah3, 3);
((uint64_t*) &l3[idx3 & MASK])[0] = al3;
((uint64_t*) &l3[idx3 & MASK])[1] = ah3;
VARIANT1_2(ah3, 3);
ah3 ^= ch;
al3 ^= cl;
@ -910,6 +989,12 @@ public:
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);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
VARIANT1_INIT(2);
VARIANT1_INIT(3);
VARIANT1_INIT(4);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
const uint8_t* l2 = ctx->memory + 2 * MEM;
@ -985,6 +1070,12 @@ public:
_mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3));
_mm_store_si128((__m128i*) &l4[idx4 & MASK], _mm_xor_si128(bx4, cx4));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
VARIANT1_1(&l2[idx2 & MASK], 2);
VARIANT1_1(&l3[idx3 & MASK], 3);
VARIANT1_1(&l4[idx4 & MASK], 4);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
idx2 = EXTRACT64(cx2);
@ -1005,8 +1096,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -1020,8 +1113,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -1035,8 +1130,10 @@ public:
al2 += hi;
ah2 += lo;
VARIANT1_2(ah2, 2);
((uint64_t*) &l2[idx2 & MASK])[0] = al2;
((uint64_t*) &l2[idx2 & MASK])[1] = ah2;
VARIANT1_2(ah2, 2);
ah2 ^= ch;
al2 ^= cl;
@ -1050,8 +1147,10 @@ public:
al3 += hi;
ah3 += lo;
VARIANT1_2(ah3, 3);
((uint64_t*) &l3[idx3 & MASK])[0] = al3;
((uint64_t*) &l3[idx3 & MASK])[1] = ah3;
VARIANT1_2(ah3, 3);
ah3 ^= ch;
al3 ^= cl;
@ -1065,8 +1164,10 @@ public:
al4 += hi;
ah4 += lo;
VARIANT1_2(ah4, 4);
((uint64_t*) &l4[idx4 & MASK])[0] = al4;
((uint64_t*) &l4[idx4 & MASK])[1] = ah4;
VARIANT1_2(ah4, 4);
ah4 ^= ch;
al4 ^= cl;

View file

@ -0,0 +1,57 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __CRYPTONIGHT_MONERO_H__
#define __CRYPTONIGHT_MONERO_H__
// VARIANT ALTERATIONS
#define VARIANT1_INIT(part) \
const uint8_t version##part = static_cast<const uint8_t*>(input)[part * size]; \
uint64_t tweak1_2_##part = 0; \
/*if (MONERO)*/ { \
if (version##part > 6) { \
tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(reinterpret_cast<const uint8_t*>(input) + 35 + part * size) ^ \
*(reinterpret_cast<const uint64_t*>(ctx->state[part]) + 24)); \
} \
}
#define VARIANT1_1(p, part) \
/*if (MONERO)*/ { \
if (version##part > 6) { \
const uint8_t tmp = reinterpret_cast<const uint8_t*>(p)[11]; \
static const uint32_t table = 0x75310; \
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \
((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \
} \
}
#define VARIANT1_2(p, part) \
/*if (MONERO)*/ { \
if (version##part > 6) { \
(p) ^= tweak1_2_##part; \
} \
}
#endif /* __CRYPTONIGHT_MONERO_H__ */

View file

@ -25,7 +25,7 @@
#define __CRYPTONIGHT_TEST_H__
const static uint8_t test_input[456] = {
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,
@ -46,7 +46,7 @@ const static uint8_t test_input[456] = {
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,
0x01, 0x00, 0xFB, 0x8E, 0x8A, 0xC8, 0x05, 0x89, 0x93, 0x23, 0x37, 0x1B, 0xB7, 0x90, 0xDB, 0x19,
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,
@ -59,7 +59,7 @@ const static uint8_t test_input[456] = {
};
const static uint8_t test_output0[192] = {
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, 0x82, 0x8A, 0x7F,
0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7,
@ -68,14 +68,14 @@ const static uint8_t test_output0[192] = {
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,
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_output1[192] = {
const static uint8_t test_output_light[] = {
0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE,
0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD,
0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E,
@ -84,11 +84,37 @@ const static uint8_t test_output1[192] = {
0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD,
0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E,
0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88,
0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE,
0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE,
0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD,
0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 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_v1_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_v1_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_v1_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_v1_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}
};
#endif /* __CRYPTONIGHT_TEST_H__ */

View file

@ -36,6 +36,7 @@
#include "crypto/CryptoNight.h"
#include "crypto/CryptoNight_monero.h"
#include "crypto/soft_aes.h"
@ -48,7 +49,6 @@ extern "C"
#include "crypto/c_skein.h"
}
static inline void do_blake_hash(const void* input, size_t len, char* output)
{
blake256_hash(reinterpret_cast<uint8_t*>(output), static_cast<const uint8_t*>(input), len);
@ -332,10 +332,18 @@ public:
uint64_t ah[NUM_HASH_BLOCKS];
__m128i bx[NUM_HASH_BLOCKS];
uint64_t idx[NUM_HASH_BLOCKS];
uint64_t tweak1_2[NUM_HASH_BLOCKS];
uint64_t version[NUM_HASH_BLOCKS];
for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) {
keccak(static_cast<const uint8_t*>(input) + hashBlock * size, (int) size,
ctx->state[hashBlock], 200);
keccak(static_cast<const uint8_t*>(input) + hashBlock * size, (int) size, ctx->state[hashBlock], 200);
version[hashBlock] = static_cast<const uint8_t*>(input)[hashBlock * size];
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
tweak1_2[hashBlock] = (*reinterpret_cast<const uint64_t*>(reinterpret_cast<const uint8_t*>(input) + 35 + hashBlock * size) ^
*(reinterpret_cast<const uint64_t*>(ctx->state[hashBlock]) + 24));
}
}
}
for (size_t hashBlock = 0; hashBlock < NUM_HASH_BLOCKS; ++hashBlock) {
@ -363,6 +371,16 @@ public:
_mm_store_si128((__m128i*) &l[hashBlock][idx[hashBlock] & MASK],
_mm_xor_si128(bx[hashBlock], cx));
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
const uint8_t tmp = reinterpret_cast<const uint8_t*>(&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;
@ -374,9 +392,21 @@ public:
al[hashBlock] += hi;
ah[hashBlock] += lo;
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
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];
/*if (MONERO)*/ {
if (version[hashBlock] > 6) {
ah[hashBlock] ^= tweak1_2[hashBlock];
}
}
ah[hashBlock] ^= ch;
al[hashBlock] ^= cl;
idx[hashBlock] = al[hashBlock];
@ -410,6 +440,8 @@ public:
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state[0], 200);
VARIANT1_INIT(0);
l = ctx->memory;
h = reinterpret_cast<uint64_t*>(ctx->state[0]);
@ -431,6 +463,7 @@ public:
}
_mm_store_si128((__m128i*) &l[idx & MASK], _mm_xor_si128(bx, cx));
VARIANT1_1(&l[idx & MASK], 0);
idx = EXTRACT64(cx);
bx = cx;
@ -442,8 +475,10 @@ public:
al += hi;
ah += lo;
VARIANT1_2(ah, 0);
((uint64_t*) &l[idx & MASK])[0] = al;
((uint64_t*) &l[idx & MASK])[1] = ah;
VARIANT1_2(ah, 0);
ah ^= ch;
al ^= cl;
@ -468,6 +503,9 @@ public:
keccak((const uint8_t*) input, (int) size, ctx->state[0], 200);
keccak((const uint8_t*) input + size, (int) size, ctx->state[1], 200);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state[0]);
@ -505,6 +543,9 @@ public:
_mm_store_si128((__m128i*) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
_mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
@ -519,8 +560,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -533,8 +576,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -565,6 +610,10 @@ public:
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);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
VARIANT1_INIT(2);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
const uint8_t* l2 = ctx->memory + 2 * MEM;
@ -614,6 +663,10 @@ public:
_mm_store_si128((__m128i*) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
_mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
VARIANT1_1(&l2[idx2 & MASK], 2);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
idx2 = EXTRACT64(cx2);
@ -631,8 +684,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -646,8 +701,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -661,8 +718,10 @@ public:
al2 += hi;
ah2 += lo;
VARIANT1_2(ah2, 2);
((uint64_t*) &l2[idx2 & MASK])[0] = al2;
((uint64_t*) &l2[idx2 & MASK])[1] = ah2;
VARIANT1_2(ah2, 2);
ah2 ^= ch;
al2 ^= cl;
@ -697,6 +756,11 @@ public:
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);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
VARIANT1_INIT(2);
VARIANT1_INIT(3);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
const uint8_t* l2 = ctx->memory + 2 * MEM;
@ -758,6 +822,11 @@ public:
_mm_store_si128((__m128i*) &l2[idx2 & MASK], _mm_xor_si128(bx2, cx2));
_mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
VARIANT1_1(&l2[idx2 & MASK], 2);
VARIANT1_1(&l3[idx3 & MASK], 3);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
idx2 = EXTRACT64(cx2);
@ -777,8 +846,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -792,8 +863,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -807,8 +880,10 @@ public:
al2 += hi;
ah2 += lo;
VARIANT1_2(ah2, 2);
((uint64_t*) &l2[idx2 & MASK])[0] = al2;
((uint64_t*) &l2[idx2 & MASK])[1] = ah2;
VARIANT1_2(ah2, 2);
ah2 ^= ch;
al2 ^= cl;
@ -822,8 +897,10 @@ public:
al3 += hi;
ah3 += lo;
VARIANT1_2(ah3, 3);
((uint64_t*) &l3[idx3 & MASK])[0] = al3;
((uint64_t*) &l3[idx3 & MASK])[1] = ah3;
VARIANT1_2(ah3, 3);
ah3 ^= ch;
al3 ^= cl;
@ -862,6 +939,12 @@ public:
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);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
VARIANT1_INIT(2);
VARIANT1_INIT(3);
VARIANT1_INIT(4);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
const uint8_t* l2 = ctx->memory + 2 * MEM;
@ -935,6 +1018,12 @@ public:
_mm_store_si128((__m128i*) &l3[idx3 & MASK], _mm_xor_si128(bx3, cx3));
_mm_store_si128((__m128i*) &l4[idx4 & MASK], _mm_xor_si128(bx4, cx4));
VARIANT1_1(&l0[idx0 & MASK], 0);
VARIANT1_1(&l1[idx1 & MASK], 1);
VARIANT1_1(&l2[idx2 & MASK], 2);
VARIANT1_1(&l3[idx3 & MASK], 3);
VARIANT1_1(&l4[idx4 & MASK], 4);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
idx2 = EXTRACT64(cx2);
@ -955,8 +1044,10 @@ public:
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -970,8 +1061,10 @@ public:
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -985,8 +1078,10 @@ public:
al2 += hi;
ah2 += lo;
VARIANT1_2(ah2, 2);
((uint64_t*) &l2[idx2 & MASK])[0] = al2;
((uint64_t*) &l2[idx2 & MASK])[1] = ah2;
VARIANT1_2(ah2, 2);
ah2 ^= ch;
al2 ^= cl;
@ -1000,8 +1095,10 @@ public:
al3 += hi;
ah3 += lo;
VARIANT1_2(ah3, 3);
((uint64_t*) &l3[idx3 & MASK])[0] = al3;
((uint64_t*) &l3[idx3 & MASK])[1] = ah3;
VARIANT1_2(ah3, 3);
ah3 ^= ch;
al3 ^= cl;
@ -1015,8 +1112,10 @@ public:
al4 += hi;
ah4 += lo;
VARIANT1_2(ah4, 4);
((uint64_t*) &l4[idx4 & MASK])[0] = al4;
((uint64_t*) &l4[idx4 & MASK])[1] = ah4;
VARIANT1_2(ah4, 4);
ah4 ^= ch;
al4 ^= cl;

View file

@ -230,7 +230,7 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code)
int64_t Client::send(size_t size)
{
LOG_DEBUG("[%s:%u] send (%d bytes): \"%s\"", m_url.host(), m_url.port(), size, buf);
LOG_DEBUG("[%s:%u] send (%d bytes): \"%s\"", m_url.host(), m_url.port(), size, m_sendBuf);
if (!m_net) {
LOG_DEBUG_ERR("[%s:%u] send failed", m_url.host(), m_url.port());
return -1;