diff --git a/src/3rdparty/argon2/include/argon2.h b/src/3rdparty/argon2/include/argon2.h index 7dedf00ce..7759a8857 100644 --- a/src/3rdparty/argon2/include/argon2.h +++ b/src/3rdparty/argon2/include/argon2.h @@ -308,6 +308,14 @@ ARGON2_PUBLIC int argon2id_hash_raw(const uint32_t t_cost, const size_t saltlen, void *hash, const size_t hashlen); +ARGON2_PUBLIC int argon2id_hash_raw_ex(const uint32_t t_cost, + const uint32_t m_cost, + const uint32_t parallelism, const void *pwd, + const size_t pwdlen, const void *salt, + const size_t saltlen, void *hash, + const size_t hashlen, + void *memory); + /* generic function underlying the above ones */ ARGON2_PUBLIC int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, const uint32_t parallelism, const void *pwd, diff --git a/src/3rdparty/argon2/lib/argon2.c b/src/3rdparty/argon2/lib/argon2.c index 28d3d4029..d4d038a97 100644 --- a/src/3rdparty/argon2/lib/argon2.c +++ b/src/3rdparty/argon2/lib/argon2.c @@ -259,6 +259,34 @@ int argon2id_hash_raw(const uint32_t t_cost, const uint32_t m_cost, ARGON2_VERSION_NUMBER); } +int argon2id_hash_raw_ex(const uint32_t t_cost, const uint32_t m_cost, + const uint32_t parallelism, const void *pwd, + const size_t pwdlen, const void *salt, + const size_t saltlen, void *hash, const size_t hashlen, void *memory) { + argon2_context context; + + context.out = (uint8_t *)hash; + context.outlen = (uint32_t)hashlen; + context.pwd = CONST_CAST(uint8_t *)pwd; + context.pwdlen = (uint32_t)pwdlen; + context.salt = CONST_CAST(uint8_t *)salt; + context.saltlen = (uint32_t)saltlen; + context.secret = NULL; + context.secretlen = 0; + context.ad = NULL; + context.adlen = 0; + context.t_cost = t_cost; + context.m_cost = m_cost; + context.lanes = parallelism; + context.threads = parallelism; + context.allocate_cbk = NULL; + context.free_cbk = NULL; + context.flags = ARGON2_DEFAULT_FLAGS; + context.version = ARGON2_VERSION_NUMBER; + + return argon2_ctx_mem(&context, Argon2_id, memory, m_cost * 1024); +} + static int argon2_compare(const uint8_t *b1, const uint8_t *b2, size_t len) { size_t i; uint8_t d = 0U; diff --git a/src/3rdparty/argon2/lib/core.c b/src/3rdparty/argon2/lib/core.c index 62ae12087..5d130c04a 100644 --- a/src/3rdparty/argon2/lib/core.c +++ b/src/3rdparty/argon2/lib/core.c @@ -139,7 +139,7 @@ void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) { } /* Memory clear flag defaults to true. */ -int FLAG_clear_internal_memory = 1; +int FLAG_clear_internal_memory = 0; void clear_internal_memory(void *v, size_t n) { if (FLAG_clear_internal_memory && v) { secure_wipe_memory(v, n); diff --git a/src/crypto/argon2/Hash.h b/src/crypto/argon2/Hash.h index 743d083e8..b337f1934 100644 --- a/src/crypto/argon2/Hash.h +++ b/src/crypto/argon2/Hash.h @@ -27,23 +27,21 @@ #include "3rdparty/argon2.h" +#include "crypto/cn/CryptoNight.h" #include "crypto/common/Algorithm.h" -struct cryptonight_ctx; - - namespace xmrig { namespace argon2 { template -inline void single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__, uint64_t) +inline void single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx, uint64_t) { if (ALGO == Algorithm::AR2_CHUKWA) { - argon2id_hash_raw(3, 512, 1, input, size, input, 16, output, 32); + argon2id_hash_raw_ex(3, 512, 1, input, size, input, 16, output, 32, ctx[0]->memory); } else if (ALGO == Algorithm::AR2_WRKZ) { - argon2id_hash_raw(4, 256, 1, input, size, input, 16, output, 32); + argon2id_hash_raw_ex(4, 256, 1, input, size, input, 16, output, 32, ctx[0]->memory); } }