Pass blob size to cryptonight_hash_ctx.

This commit is contained in:
XMRig 2017-04-22 15:34:05 +03:00
parent 54cef68aa9
commit 97a8d448c0
8 changed files with 24 additions and 24 deletions

View file

@ -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__ */

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#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;

View file

@ -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);