diff --git a/src/crypto/randomx/blake2/blake2-impl.h b/src/crypto/randomx/blake2/blake2-impl.h index 28f0e301..617f7c8a 100644 --- a/src/crypto/randomx/blake2/blake2-impl.h +++ b/src/crypto/randomx/blake2/blake2-impl.h @@ -37,7 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include "crypto/randomx/blake2/endian.h" +#include "endian.h" static FORCE_INLINE uint64_t load48(const void *src) { const uint8_t *p = (const uint8_t *)src; diff --git a/src/crypto/randomx/blake2/blake2b.c b/src/crypto/randomx/blake2/blake2b.c index 24305c3c..710fe7ff 100644 --- a/src/crypto/randomx/blake2/blake2b.c +++ b/src/crypto/randomx/blake2/blake2b.c @@ -36,8 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "crypto/randomx/blake2/blake2.h" -#include "crypto/randomx/blake2/blake2-impl.h" +#include "blake2.h" +#include "blake2-impl.h" static const uint64_t blake2b_IV[8] = { UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b), @@ -45,7 +45,7 @@ static const uint64_t blake2b_IV[8] = { UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f), UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179) }; -static const uint8_t blake2b_sigma[12][16] = { +static const unsigned int blake2b_sigma[12][16] = { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, diff --git a/src/crypto/randomx/blake2/blamka-round-ref.h b/src/crypto/randomx/blake2/blamka-round-ref.h index 45606b8f..f1fb50bf 100644 --- a/src/crypto/randomx/blake2/blamka-round-ref.h +++ b/src/crypto/randomx/blake2/blamka-round-ref.h @@ -35,8 +35,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef BLAKE_ROUND_MKA_H #define BLAKE_ROUND_MKA_H -#include "crypto/randomx/blake2/blake2.h" -#include "crypto/randomx/blake2/blake2-impl.h" +#include "blake2.h" +#include "blake2-impl.h" /* designed by the Lyra PHC team */ static FORCE_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) { diff --git a/src/crypto/randomx/blake2/endian.h b/src/crypto/randomx/blake2/endian.h index 8fd6b970..c7afed26 100644 --- a/src/crypto/randomx/blake2/endian.h +++ b/src/crypto/randomx/blake2/endian.h @@ -3,10 +3,8 @@ #include #if defined(_MSC_VER) -#define FORCE_INLINE __forceinline -#elif defined(__GNUC__) -#define FORCE_INLINE __attribute__((always_inline)) inline -#elif defined(__clang__) +#define FORCE_INLINE __inline +#elif defined(__GNUC__) || defined(__clang__) #define FORCE_INLINE __inline__ #else #define FORCE_INLINE diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index 43d257b9..fa2f4e4c 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -134,55 +134,44 @@ RandomX_ConfigurationScala::RandomX_ConfigurationScala() // End of DefyX DATASET } +//RandomX_ConfigurationScala2::RandomX_ConfigurationScala2() +//{ +// ArgonIterations = 4; +// ArgonLanes = 2; +// ArgonSalt = "Panthera\x03"; +// DatasetBaseSize = 33554432; +// ProgramSize = 320; +// ProgramCount = 3; +// ScratchpadL3_Size = 262144; +// ScratchpadL2_Size = 65536; +// +//} + RandomX_ConfigurationScala2::RandomX_ConfigurationScala2() { - ArgonMemory = 262144; - ArgonIterations = 4; - ArgonLanes = 2; - ArgonSalt = "Panthera\x03"; - CacheAccesses = 8; - SuperscalarLatency = 170; - DatasetBaseSize = 33554432; - DatasetExtraSize = 33554368; - ProgramSize = 320; - ProgramIterations = 2048; - ProgramCount = 3; - ScratchpadL3_Size = 262144; - ScratchpadL2_Size = 65536; - ScratchpadL1_Size = 16384; - JumpBits = 8; - JumpOffset = 8; - - RANDOMX_FREQ_IADD_RS = 16; - RANDOMX_FREQ_IADD_M = 7; - RANDOMX_FREQ_ISUB_R = 16; - RANDOMX_FREQ_ISUB_M = 7; - RANDOMX_FREQ_IMUL_R = 16; - RANDOMX_FREQ_IMUL_M = 4; - RANDOMX_FREQ_IMULH_R = 4; - RANDOMX_FREQ_IMULH_M = 1; - RANDOMX_FREQ_ISMULH_R = 4; - RANDOMX_FREQ_ISMULH_M = 1; - RANDOMX_FREQ_IMUL_RCP = 8; - RANDOMX_FREQ_INEG_R = 2; - RANDOMX_FREQ_IXOR_R = 15; - RANDOMX_FREQ_IXOR_M = 5; - RANDOMX_FREQ_IROR_R = 8; - RANDOMX_FREQ_IROL_R = 2; - RANDOMX_FREQ_ISWAP_R = 4; - RANDOMX_FREQ_FSWAP_R = 4; - RANDOMX_FREQ_FADD_R = 16; - RANDOMX_FREQ_FADD_M = 5; - RANDOMX_FREQ_FSUB_R = 16; - RANDOMX_FREQ_FSUB_M = 5; - RANDOMX_FREQ_FSCAL_R = 6; - RANDOMX_FREQ_FMUL_R = 32; - RANDOMX_FREQ_FDIV_M = 4; - RANDOMX_FREQ_FSQRT_R = 6; - RANDOMX_FREQ_CBRANCH = 25; - RANDOMX_FREQ_CFROUND = 1; - RANDOMX_FREQ_ISTORE = 16; - RANDOMX_FREQ_NOP = 0; + ArgonMemory = 131072; + ArgonIterations = 2; + ArgonSalt = "DefyXScala\x13"; + CacheAccesses = 2; + DatasetBaseSize = 33554432; + ProgramSize = 64; + ProgramIterations = 1024; + ProgramCount = 4; + ScratchpadL3_Size = 262144; + ScratchpadL2_Size = 131072; + ScratchpadL1_Size = 65536; + + RANDOMX_FREQ_IADD_RS = 25; + RANDOMX_FREQ_CBRANCH = 16; + + // DefyX DATASET (thanks MoneroOcean for the fix !) + const uint32_t DatasetBaseMask = DatasetBaseSize - RANDOMX_DATASET_ITEM_SIZE; + *(uint32_t*)(codeReadDatasetRyzenTweaked + 9) = DatasetBaseMask; + *(uint32_t*)(codeReadDatasetRyzenTweaked + 24) = DatasetBaseMask; + *(uint32_t*)(codeReadDatasetTweaked + 7) = DatasetBaseMask; + *(uint32_t*)(codeReadDatasetTweaked + 23) = DatasetBaseMask; + *(uint32_t*)(codeReadDatasetLightSshInitTweaked + 59) = DatasetBaseMask; + // End of DefyX DATASET } RandomX_ConfigurationKeva::RandomX_ConfigurationKeva() @@ -470,8 +459,8 @@ int yespower_hash(const void *data, size_t length, void *hash) { yespower_params_t params = { .version = YESPOWER_1_0, - .N = 1024, - .r = 4, + .N = 2048, + .r = 8, .pers = NULL }; @@ -479,13 +468,6 @@ int yespower_hash(const void *data, size_t length, void *hash) return finale_yespower; //0 for success } -int k12_yp(const void *data, size_t length, void *hash) -{ - - int kDo = KangarooTwelve((const unsigned char *)data, length, (unsigned char *)hash, 32, 0, 0); - return kDo; -} - extern "C" { void defyx2_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output) { @@ -493,8 +475,9 @@ extern "C" { assert(inputSize == 0 || input != nullptr); assert(output != nullptr); alignas(16) uint64_t tempHash[8]; - yespower_hash(input, inputSize, tempHash); - k12_yp(input, inputSize, tempHash); + rx_blake2b(tempHash, sizeof(tempHash), input, inputSize, 0, 0); + yespower_hash(tempHash, sizeof(tempHash), tempHash); + k12(tempHash, sizeof(tempHash), tempHash); machine->initScratchpad(&tempHash); machine->resetRoundingMode(); for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) { @@ -506,8 +489,9 @@ extern "C" { } void defyx2_calculate_hash_first(randomx_vm* machine, uint64_t (&tempHash)[8], const void* input, size_t inputSize) { - yespower_hash(input, inputSize, tempHash); - k12_yp(input, inputSize, tempHash); + rx_blake2b(tempHash, sizeof(tempHash), input, inputSize, 0, 0); + yespower_hash(tempHash, sizeof(tempHash), tempHash); + k12(tempHash, sizeof(tempHash), tempHash); machine->initScratchpad(tempHash); } @@ -520,8 +504,9 @@ extern "C" { machine->run(&tempHash); // Finish current hash and fill the scratchpad for the next hash at the same time - yespower_hash(nextInput, nextInputSize, tempHash); - k12_yp(nextInput, nextInputSize, tempHash); + rx_blake2b(tempHash, sizeof(tempHash), nextInput, nextInputSize, 0, 0); + yespower_hash(tempHash, sizeof(tempHash), tempHash); + k12(tempHash, sizeof(tempHash), tempHash); machine->hashAndFill(output, RANDOMX_HASH_SIZE, tempHash); }