Integrated thread based double hash mode
This commit is contained in:
parent
196beded79
commit
daa4d912b3
17 changed files with 161 additions and 134 deletions
|
@ -30,7 +30,8 @@
|
|||
#include "Options.h"
|
||||
|
||||
|
||||
void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr;
|
||||
void (*cryptonight_hash_ctx_s)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr;
|
||||
void (*cryptonight_hash_ctx_d)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr;
|
||||
|
||||
|
||||
static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx) {
|
||||
|
@ -93,40 +94,43 @@ void (*cryptonight_variations[4])(const void *input, size_t size, void *output,
|
|||
#endif
|
||||
|
||||
|
||||
bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx)
|
||||
void CryptoNight::hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx)
|
||||
{
|
||||
cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx);
|
||||
|
||||
return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target();
|
||||
cryptonight_hash_ctx_s(input, size, output, ctx);
|
||||
}
|
||||
|
||||
void CryptoNight::hashDouble(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx)
|
||||
{
|
||||
cryptonight_hash_ctx_d(input, size, output, ctx);
|
||||
}
|
||||
|
||||
bool CryptoNight::init(int algo, int variant)
|
||||
{
|
||||
if (variant < 1 || variant > 4) {
|
||||
if (variant < 1 || variant > 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
const int index = algo == Options::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1);
|
||||
# else
|
||||
const int index = variant - 1;
|
||||
# endif
|
||||
int index = 0;
|
||||
|
||||
cryptonight_hash_ctx = cryptonight_variations[index];
|
||||
if (variant == 3 || variant == 4)
|
||||
{
|
||||
index = 4;
|
||||
}
|
||||
|
||||
if (algo == Options::ALGO_CRYPTONIGHT_LITE) {
|
||||
index += 4;
|
||||
}
|
||||
|
||||
cryptonight_hash_ctx_s = cryptonight_variations[index];
|
||||
cryptonight_hash_ctx_d = cryptonight_variations[index+1];
|
||||
|
||||
return selfTest(algo);
|
||||
}
|
||||
|
||||
|
||||
void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx)
|
||||
bool CryptoNight::selfTest(int algo)
|
||||
{
|
||||
cryptonight_hash_ctx(input, size, output, ctx);
|
||||
}
|
||||
|
||||
|
||||
bool CryptoNight::selfTest(int algo) {
|
||||
if (cryptonight_hash_ctx == nullptr) {
|
||||
if (cryptonight_hash_ctx_d == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -135,14 +139,22 @@ bool CryptoNight::selfTest(int algo) {
|
|||
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16);
|
||||
ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 2, 16);
|
||||
|
||||
cryptonight_hash_ctx(test_input, 76, output, ctx);
|
||||
cryptonight_hash_ctx_d(test_input, 76, output, ctx);
|
||||
|
||||
_mm_free(ctx->memory);
|
||||
_mm_free(ctx);
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
return memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0;
|
||||
# else
|
||||
return memcmp(output, test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0;
|
||||
# endif
|
||||
bool resultSingle = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 32) == 0;
|
||||
|
||||
ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16);
|
||||
ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 2, 16);
|
||||
|
||||
cryptonight_hash_ctx_d(test_input, 76, output, ctx);
|
||||
|
||||
_mm_free(ctx->memory);
|
||||
_mm_free(ctx);
|
||||
|
||||
bool resultDouble = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 64) == 0;
|
||||
|
||||
return resultSingle && resultDouble;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue