diff --git a/algo/cryptonight/cryptonight.h b/algo/cryptonight/cryptonight.h index d677a668d..c238da7ac 100644 --- a/algo/cryptonight/cryptonight.h +++ b/algo/cryptonight/cryptonight.h @@ -40,7 +40,6 @@ struct cryptonight_ctx { extern void (* const extra_hashes[4])(const void *, size_t, char *); bool cryptonight_init(int variant); -void cryptonight_hash(void* output, const void* input, size_t input_len); -int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx); +int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict blob, size_t blob_size, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx); #endif /* __CRYPTONIGHT_H__ */ diff --git a/algo/cryptonight/cryptonight_av1_aesni.c b/algo/cryptonight/cryptonight_av1_aesni.c index 0300a734c..9bb374a8b 100644 --- a/algo/cryptonight/cryptonight_av1_aesni.c +++ b/algo/cryptonight/cryptonight_av1_aesni.c @@ -222,9 +222,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output) } -void cryptonight_av1_aesni(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx) +void cryptonight_av1_aesni(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx) { - keccak((const uint8_t *) input, 76, ctx->state, 200); + keccak((const uint8_t *) input, size, ctx->state, 200); cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory); diff --git a/algo/cryptonight/cryptonight_av2_aesni_stak.c b/algo/cryptonight/cryptonight_av2_aesni_stak.c index c0eb4ee8e..a3cefe0b0 100644 --- a/algo/cryptonight/cryptonight_av2_aesni_stak.c +++ b/algo/cryptonight/cryptonight_av2_aesni_stak.c @@ -222,9 +222,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output) } -void cryptonight_av2_aesni_stak(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx) +void cryptonight_av2_aesni_stak(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx) { - keccak((const uint8_t *) input, 76, ctx->state, 200); + keccak((const uint8_t *) input, size, ctx->state, 200); cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory); diff --git a/algo/cryptonight/cryptonight_av3_aesni_bmi2.c b/algo/cryptonight/cryptonight_av3_aesni_bmi2.c index 92ddac5b2..d532bce8c 100644 --- a/algo/cryptonight/cryptonight_av3_aesni_bmi2.c +++ b/algo/cryptonight/cryptonight_av3_aesni_bmi2.c @@ -213,9 +213,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output) } -void cryptonight_av3_aesni_bmi2(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx) +void cryptonight_av3_aesni_bmi2(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx) { - keccak((const uint8_t *) input, 76, ctx->state, 200); + keccak((const uint8_t *) input, size, ctx->state, 200); cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory); diff --git a/algo/cryptonight/cryptonight_av4_softaes.c b/algo/cryptonight/cryptonight_av4_softaes.c index 01c211c41..b7a17af78 100644 --- a/algo/cryptonight/cryptonight_av4_softaes.c +++ b/algo/cryptonight/cryptonight_av4_softaes.c @@ -203,9 +203,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output) } -void cryptonight_av4_softaes(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx) +void cryptonight_av4_softaes(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx) { - keccak((const uint8_t *) input, 76, ctx->state, 200); + keccak((const uint8_t *) input, size, ctx->state, 200); cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory); diff --git a/algo/cryptonight/cryptonight_av5_aesni_experimental.c b/algo/cryptonight/cryptonight_av5_aesni_experimental.c index 79a50c804..cad6290f7 100644 --- a/algo/cryptonight/cryptonight_av5_aesni_experimental.c +++ b/algo/cryptonight/cryptonight_av5_aesni_experimental.c @@ -213,11 +213,11 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output) } -void cryptonight_av5_aesni_experimental(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx) +void cryptonight_av5_aesni_experimental(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx) { const uint8_t* memory = ctx->memory; - keccak((const uint8_t *) input, 76, ctx->state, 200); + keccak((const uint8_t *) input, size, ctx->state, 200); cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory); uint64_t* state = (uint64_t*) ctx->state; diff --git a/algo/cryptonight/cryptonight_common.c b/algo/cryptonight/cryptonight_common.c index d97957cfb..e82ef4231 100644 --- a/algo/cryptonight/cryptonight_common.c +++ b/algo/cryptonight/cryptonight_common.c @@ -23,6 +23,7 @@ #include +#include #ifndef BUILD_TEST # include "xmrig.h" @@ -52,16 +53,16 @@ const static char test_output[32] = { }; -void cryptonight_av1_aesni(void* output, const void* input, struct cryptonight_ctx* ctx); -void cryptonight_av4_softaes(void* output, const void* input, struct cryptonight_ctx* ctx); +void cryptonight_av1_aesni(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx); +void cryptonight_av4_softaes(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx); #if defined(__x86_64__) - void cryptonight_av2_aesni_stak(void* output, const void* input, struct cryptonight_ctx* ctx); - void cryptonight_av3_aesni_bmi2(void* output, const void* input, struct cryptonight_ctx* ctx); - void cryptonight_av5_aesni_experimental(void* output, const void* input, struct cryptonight_ctx* ctx); + void cryptonight_av2_aesni_stak(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx); + void cryptonight_av3_aesni_bmi2(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx); + void cryptonight_av5_aesni_experimental(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx); #endif -void (*cryptonight_hash_ctx)(void* output, const void* input, struct cryptonight_ctx* ctx) = NULL; +void (*cryptonight_hash_ctx)(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx) = NULL; static bool self_test() { @@ -70,7 +71,7 @@ static bool self_test() { struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) malloc(sizeof(struct cryptonight_ctx)); ctx->memory = (uint8_t *) malloc(MEMORY); - cryptonight_hash_ctx(output, test_input, ctx); + cryptonight_hash_ctx(test_input, sizeof(test_input), output, ctx); free(ctx->memory); free(ctx); @@ -136,14 +137,14 @@ void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, d #ifndef BUILD_TEST -int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) { - uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39); +int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict blob, size_t blob_size, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) { + uint32_t *nonceptr = (uint32_t*) (((char*) blob) + 39); uint32_t n = *nonceptr - 1; const uint32_t first_nonce = n + 1; do { *nonceptr = ++n; - cryptonight_hash_ctx(hash, pdata, ctx); + cryptonight_hash_ctx(blob, blob_size, hash, ctx); if (unlikely(hash[7] < target)) { *hashes_done = n - first_nonce + 1; diff --git a/xmrig.c b/xmrig.c index 2beecabdf..595536361 100644 --- a/xmrig.c +++ b/xmrig.c @@ -295,7 +295,7 @@ static void *miner_thread(void *userdata) { if (memcmp(work.blob, stratum_ctx->g_work.blob, 39) || memcmp(((uint8_t*) work.blob) + 43, ((uint8_t*) stratum_ctx->g_work.blob) + 43, 33)) { work_free(&work); work_copy(&work, &stratum_ctx->g_work); - nonceptr = (uint32_t*) (((char*)work.blob) + 39); + nonceptr = (uint32_t*) (((char*) work.blob) + 39); *nonceptr = 0xffffffffU / opt_n_threads * thr_id; } else { ++(*nonceptr); @@ -323,7 +323,7 @@ static void *miner_thread(void *userdata) { gettimeofday(&tv_start, NULL ); /* scan nonces for a proof-of-work hash */ - rc = scanhash_cryptonight(thr_id, hash, work.blob, work.target, max_nonce, &hashes_done, persistentctx); + rc = scanhash_cryptonight(thr_id, hash, work.blob, work.blob_size, work.target, max_nonce, &hashes_done, persistentctx); stats_add_hashes(thr_id, &tv_start, hashes_done); memcpy(work.hash, hash, 32);