Skip to content

Commit

Permalink
Showing 4 changed files with 17 additions and 11 deletions.
13 changes: 5 additions & 8 deletions multihashing.cc
Original file line number Diff line number Diff line change
@@ -55,11 +55,9 @@ extern "C" {
#endif


const size_t max_mem_size = 4 * 1024 * 1024;
const size_t max_mem_size20 = 20 * 1024 * 1024;
xmrig::VirtualMemory memrx(2 * 1024 * 1024, true, false, 0, 4096);
const size_t max_mem_size = 20 * 1024 * 1024;
xmrig::VirtualMemory mem(max_mem_size, true, false, 0, 4096);
static struct cryptonight_ctx* ctx = nullptr;
static struct cryptonight_ctx* ctx20 = nullptr;
static randomx_cache* rx_cache[xmrig::Algorithm::Id::MAX] = {nullptr};
static randomx_vm* rx_vm[xmrig::Algorithm::Id::MAX] = {nullptr};
//static xmrig::Algorithm::Id rx_variant = xmrig::Algorithm::Id::MAX;
@@ -68,7 +66,6 @@ static uint8_t rx_seed_hash[xmrig::Algorithm::Id::MAX][32] = {};
struct InitCtx {
InitCtx() {
xmrig::CnCtx::create(&ctx, static_cast<uint8_t*>(_mm_malloc(max_mem_size, 4096)), max_mem_size, 1);
xmrig::CnCtx::create(&ctx20, static_cast<uint8_t*>(_mm_malloc(max_mem_size20, 4096)), max_mem_size20, 1);
}
} s;

@@ -124,9 +121,9 @@ void init_rx(const uint8_t* seed_hash_data, xmrig::Algorithm::Id algo) {
flags |= RANDOMX_FLAG_HARD_AES;
#endif

rx_vm[algo] = randomx_create_vm(static_cast<randomx_flags>(flags), rx_cache[algo], nullptr, memrx.scratchpad());
rx_vm[algo] = randomx_create_vm(static_cast<randomx_flags>(flags), rx_cache[algo], nullptr, mem.scratchpad());
if (!rx_vm[algo]) {
rx_vm[algo] = randomx_create_vm(static_cast<randomx_flags>(flags - RANDOMX_FLAG_LARGE_PAGES), rx_cache[algo], nullptr, memrx.scratchpad());
rx_vm[algo] = randomx_create_vm(static_cast<randomx_flags>(flags - RANDOMX_FLAG_LARGE_PAGES), rx_cache[algo], nullptr, mem.scratchpad());
}
}
}
@@ -380,7 +377,7 @@ NAN_METHOD(astrobwt) {
const xmrig::cn_hash_fun fn = get_astrobwt_fn(algo);

char output[32];
fn(reinterpret_cast<const uint8_t*>(Buffer::Data(target)), Buffer::Length(target), reinterpret_cast<uint8_t*>(output), &ctx20, 0);
fn(reinterpret_cast<const uint8_t*>(Buffer::Data(target)), Buffer::Length(target), reinterpret_cast<uint8_t*>(output), &ctx, 0);

v8::Local<v8::Value> returnValue = Nan::CopyBuffer(output, 32).ToLocalChecked();
info.GetReturnValue().Set(returnValue);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cryptonight-hashing",
"version": "17.0.2",
"version": "17.0.3",
"main": "cryptonight-hashing",
"author": {
"name": "Multiple",
12 changes: 10 additions & 2 deletions xmrig/crypto/astrobwt/AstroBWT.cpp
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
#include "AstroBWT.h"
#include "sha3.h"
#include "crypto/cn/CryptoNight.h"
#include <limits>

constexpr int STAGE1_SIZE = 147253;
constexpr int ALLOCATION_SIZE = (STAGE1_SIZE + 1048576) + (128 - (STAGE1_SIZE & 63));
@@ -64,6 +65,7 @@ static void Salsa20_XORKeyStream(const void* key, void* output, size_t size)
ECRYPT_keysetup(&ctx, static_cast<const uint8_t*>(key), 256, 64);
ECRYPT_ivsetup(&ctx, iv);
ECRYPT_keystream_bytes(&ctx, static_cast<uint8_t*>(output), size);
memset(static_cast<uint8_t*>(output) - 16, 0, 16);
memset(static_cast<uint8_t*>(output) + size, 0, 16);
}
#else
@@ -74,6 +76,7 @@ static void Salsa20_XORKeyStream(const void* key, void* output, size_t size)
const uint64_t iv = 0;
ZeroTier::Salsa20 s(key, &iv);
s.XORKeyStream(output, size);
memset(static_cast<uint8_t*>(output) - 16, 0, 16);
memset(static_cast<uint8_t*>(output) + size, 0, 16);
}
#endif
@@ -152,7 +155,7 @@ void sort_indices(int N, const uint8_t* v, uint64_t* indices, uint64_t* tmp_indi
}
}

void astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash)
bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size)
{
uint8_t key[32];
uint8_t* scratchpad_ptr = (uint8_t*)(scratchpad) + 64;
@@ -178,6 +181,9 @@ void astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad
sha3_HashBuffer(256, SHA3_FLAGS_NONE, stage1_result, STAGE1_SIZE + 1, key, sizeof(key));

const int stage2_size = STAGE1_SIZE + (*(uint32_t*)(key) & 0xfffff);
if (stage2_size > stage2_max_size)
return false;

Salsa20_XORKeyStream(key, stage2_output, stage2_size);

sort_indices(stage2_size + 1, stage2_output, indices, tmp_indices);
@@ -198,10 +204,12 @@ void astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad
}

sha3_HashBuffer(256, SHA3_FLAGS_NONE, stage2_result, stage2_size + 1, output_hash, 32);

return true;
}

template<>
void xmrig::astrobwt::single_hash<xmrig::Algorithm::ASTROBWT_DERO>(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t)
{
astrobwt_dero(input, static_cast<uint32_t>(size), ctx[0]->memory, output);
astrobwt_dero(input, static_cast<uint32_t>(size), ctx[0]->memory, output, std::numeric_limits<int>::max());
}
1 change: 1 addition & 0 deletions xmrig/crypto/astrobwt/AstroBWT.h
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ struct cryptonight_ctx;

namespace xmrig { namespace astrobwt {

bool astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size);

template<Algorithm::Id ALGO>
void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t);

0 comments on commit 79e24f4

Please sign in to comment.