Added generic Argon2 implementation (conflicts with RandomX).

This commit is contained in:
XMRig 2019-08-16 00:31:29 +07:00
parent df58821655
commit 0c25424a3e
53 changed files with 5140 additions and 126 deletions

View file

@ -0,0 +1,67 @@
/* 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-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 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 XMRIG_ARGON2_H
#define XMRIG_ARGON2_H
#include "3rdparty/argon2.h"
#include "crypto/common/Algorithm.h"
struct cryptonight_ctx;
namespace xmrig {
template<Algorithm::Id ALGO>
inline void argon2_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__, uint64_t)
{
// static bool argon_optimization_selected = false;
// if (!argon_optimization_selected) {
// argon2_select_impl(stdout, nullptr);
// argon_optimization_selected = true;
// }
uint8_t salt[16];
memcpy(salt, input, sizeof(salt));
if (ALGO == Algorithm::AR2_CHUKWA) {
argon2id_hash_raw(3, 512, 1, input, size, salt, 16, output, 32);
}
else if (ALGO == Algorithm::AR2_WRKZ) {
argon2id_hash_raw(4, 256, 1, input, size, salt, 16, output, 32);
}
}
} // namespace xmrig
#endif /* XMRIG_ARGON2_H */

View file

@ -132,6 +132,10 @@ private:
0, // RX_0
0, // RX_WOW
0, // RX_LOKI
# endif
# ifdef XMRIG_ALGO_ARGON2
0, // AR2_CHUKWA
0, // AR2_WRKZ
# endif
};
@ -167,6 +171,10 @@ private:
0, // RX_0
0, // RX_WOW
0, // RX_LOKI
# endif
# ifdef XMRIG_ALGO_ARGON2
0, // AR2_CHUKWA
0, // AR2_WRKZ
# endif
};
@ -202,6 +210,10 @@ private:
Algorithm::INVALID, // RX_0
Algorithm::INVALID, // RX_WOW
Algorithm::INVALID, // RX_LOKI
# endif
# ifdef XMRIG_ALGO_ARGON2
Algorithm::INVALID, // AR2_CHUKWA
Algorithm::INVALID, // AR2_WRKZ
# endif
};
};

View file

@ -38,6 +38,11 @@
#endif
#ifdef XMRIG_ALGO_ARGON2
# include "crypto/argon2/Argon2.h"
#endif
#define ADD_FN(algo) \
m_map[algo][AV_SINGLE][Assembly::NONE] = cryptonight_single_hash<algo, false>; \
m_map[algo][AV_SINGLE_SOFT][Assembly::NONE] = cryptonight_single_hash<algo, true>; \
@ -249,6 +254,13 @@ xmrig::CnHash::CnHash()
ADD_FN_ASM(Algorithm::CN_PICO_0);
# endif
# ifdef XMRIG_ALGO_ARGON2
m_map[Algorithm::AR2_CHUKWA][AV_SINGLE][Assembly::NONE] = argon2_single_hash<Algorithm::AR2_CHUKWA>;
m_map[Algorithm::AR2_CHUKWA][AV_SINGLE_SOFT][Assembly::NONE] = argon2_single_hash<Algorithm::AR2_CHUKWA>;
m_map[Algorithm::AR2_WRKZ][AV_SINGLE][Assembly::NONE] = argon2_single_hash<Algorithm::AR2_WRKZ>;
m_map[Algorithm::AR2_WRKZ][AV_SINGLE_SOFT][Assembly::NONE] = argon2_single_hash<Algorithm::AR2_WRKZ>;
# endif
# ifdef XMRIG_FEATURE_ASM
patchAsmVariants();
# endif

View file

@ -30,6 +30,9 @@
#include <stdint.h>
namespace xmrig {
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,
@ -355,19 +358,29 @@ const static uint8_t test_output_pico_trtl[160] = {
#ifdef XMRIG_ALGO_CN_GPU
// "cn/gpu"
const static uint8_t test_output_gpu[160] = {
const static uint8_t test_output_gpu[32] = {
0xE5, 0x5C, 0xB2, 0x3E, 0x51, 0x64, 0x9A, 0x59, 0xB1, 0x27, 0xB9, 0x6B, 0x51, 0x5F, 0x2B, 0xF7,
0xBF, 0xEA, 0x19, 0x97, 0x41, 0xA0, 0x21, 0x6C, 0xF8, 0x38, 0xDE, 0xD0, 0x6E, 0xFF, 0x82, 0xDF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xBF, 0xEA, 0x19, 0x97, 0x41, 0xA0, 0x21, 0x6C, 0xF8, 0x38, 0xDE, 0xD0, 0x6E, 0xFF, 0x82, 0xDF
};
#endif
#ifdef XMRIG_ALGO_ARGON2
// "argon2/chukwa"
const static uint8_t argon2_chukwa_test_out[32] = {
0xC1, 0x58, 0xA1, 0x05, 0xAE, 0x75, 0xC7, 0x56, 0x1C, 0xFD, 0x02, 0x90, 0x83, 0xA4, 0x7A, 0x87,
0x65, 0x3D, 0x51, 0xF9, 0x14, 0x12, 0x8E, 0x21, 0xC1, 0x97, 0x1D, 0x8B, 0x10, 0xC4, 0x90, 0x34
};
// "argon2/wrkz"
const static uint8_t argon2_wrkz_test_out[32] = {
0x35, 0xE0, 0x83, 0xD4, 0xB9, 0xC6, 0x4C, 0x2A, 0x68, 0x82, 0x0A, 0x43, 0x1F, 0x61, 0x31, 0x19,
0x98, 0xA8, 0xCD, 0x18, 0x64, 0xDB, 0xA4, 0x07, 0x7E, 0x25, 0xB7, 0xF1, 0x21, 0xD5, 0x4B, 0xD1,
};
#endif
} // namespace xmrig
#endif /* XMRIG_CRYPTONIGHT_TEST_H */

View file

@ -116,30 +116,17 @@ static AlgoName const algorithm_names[] = {
{ "randomx/loki", "rx/loki", Algorithm::RX_LOKI },
{ "RandomXL", nullptr, Algorithm::RX_LOKI },
# endif
# ifdef XMRIG_ALGO_ARGON2
{ "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ },
# endif
};
} /* namespace xmrig */
int xmrig::Algorithm::maxIntensity() const
{
# ifdef XMRIG_ALGO_RANDOMX
if (family() == RANDOM_X) {
return 1;
}
# endif
# ifdef XMRIG_ALGO_CN_GPU
if (m_id == CN_GPU) {
return 1;
}
# endif
return 5;
}
rapidjson::Value xmrig::Algorithm::toJSON() const
{
using namespace rapidjson;
@ -170,6 +157,8 @@ size_t xmrig::Algorithm::l2() const
size_t xmrig::Algorithm::l3() const
{
constexpr size_t oneMiB = 0x100000;
const Family f = family();
assert(f != UNKNOWN);
@ -179,8 +168,6 @@ size_t xmrig::Algorithm::l3() const
# ifdef XMRIG_ALGO_RANDOMX
if (f == RANDOM_X) {
constexpr size_t oneMiB = 0x100000;
switch (m_id) {
case RX_0:
case RX_LOKI:
@ -195,10 +182,49 @@ size_t xmrig::Algorithm::l3() const
}
# endif
# ifdef XMRIG_ALGO_ARGON2
if (f == ARGON2) {
switch (m_id) {
case AR2_CHUKWA:
return oneMiB / 2;
case AR2_WRKZ:
return oneMiB / 4;
default:
break;
}
}
# endif
return 0;
}
uint32_t xmrig::Algorithm::maxIntensity() const
{
# ifdef XMRIG_ALGO_RANDOMX
if (family() == RANDOM_X) {
return 1;
}
# endif
# ifdef XMRIG_ALGO_ARGON2
if (family() == ARGON2) {
return 1;
}
# endif
# ifdef XMRIG_ALGO_CN_GPU
if (m_id == CN_GPU) {
return 1;
}
# endif
return 5;
}
xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
{
switch (id) {
@ -244,6 +270,12 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
return RANDOM_X;
# endif
# ifdef XMRIG_ALGO_ARGON2
case AR2_CHUKWA:
case AR2_WRKZ:
return ARGON2;
# endif
case INVALID:
case MAX:
return UNKNOWN;
@ -273,7 +305,7 @@ const char *xmrig::Algorithm::name(bool shortName) const
{
for (size_t i = 0; i < ARRAY_SIZE(algorithm_names); i++) {
if (algorithm_names[i].id == m_id) {
return shortName ? algorithm_names[i].shortName : algorithm_names[i].name;
return (shortName && algorithm_names[i].shortName) ? algorithm_names[i].shortName : algorithm_names[i].name;
}
}

View file

@ -72,6 +72,10 @@ public:
RX_0, // "rx/0" RandomX (reference configuration).
RX_WOW, // "rx/wow" RandomWOW (Wownero).
RX_LOKI, // "rx/loki" RandomXL (Loki).
# endif
# ifdef XMRIG_ALGO_ARGON2
AR2_CHUKWA, // "argon2/chukwa"
AR2_WRKZ, // "argon2/wrkz"
# endif
MAX
};
@ -82,7 +86,8 @@ public:
CN_LITE,
CN_HEAVY,
CN_PICO,
RANDOM_X
RANDOM_X,
ARGON2
};
inline Algorithm() {}
@ -102,10 +107,10 @@ public:
inline bool operator==(const Algorithm &other) const { return isEqual(other); }
inline operator Algorithm::Id() const { return m_id; }
int maxIntensity() const;
rapidjson::Value toJSON() const;
size_t l2() const;
size_t l3() const;
uint32_t maxIntensity() const;
static Family family(Id id);
static Id parse(const char *name);

View file

@ -47,23 +47,3 @@ xmrig::Algorithm::Id xmrig::RxAlgo::apply(Algorithm::Id algorithm)
return algorithm;
}
size_t xmrig::RxAlgo::l3(Algorithm::Id algorithm)
{
switch (algorithm) {
case Algorithm::RX_0:
return RandomX_MoneroConfig.ScratchpadL3_Size;
case Algorithm::RX_WOW:
return RandomX_WowneroConfig.ScratchpadL3_Size;
case Algorithm::RX_LOKI:
return RandomX_LokiConfig.ScratchpadL3_Size;
default:
break;
}
return 0;
}

View file

@ -35,9 +35,6 @@
#include "crypto/common/Algorithm.h"
struct RandomX_ConfigurationBase;
namespace xmrig
{
@ -46,7 +43,6 @@ class RxAlgo
{
public:
static Algorithm::Id apply(Algorithm::Id algorithm);
static size_t l3(Algorithm::Id algorithm);
};