mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-18 08:45:04 +00:00
Pass blob size to cryptonight_hash_ctx.
This commit is contained in:
parent
54cef68aa9
commit
97a8d448c0
8 changed files with 24 additions and 24 deletions
|
@ -40,7 +40,6 @@ struct cryptonight_ctx {
|
||||||
extern void (* const extra_hashes[4])(const void *, size_t, char *);
|
extern void (* const extra_hashes[4])(const void *, size_t, char *);
|
||||||
|
|
||||||
bool cryptonight_init(int variant);
|
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 blob, size_t blob_size, 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 pdata, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx);
|
|
||||||
|
|
||||||
#endif /* __CRYPTONIGHT_H__ */
|
#endif /* __CRYPTONIGHT_H__ */
|
||||||
|
|
|
@ -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);
|
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
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);
|
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
|
||||||
|
|
||||||
uint64_t* state = (uint64_t*) ctx->state;
|
uint64_t* state = (uint64_t*) ctx->state;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef BUILD_TEST
|
#ifndef BUILD_TEST
|
||||||
# include "xmrig.h"
|
# 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_av1_aesni(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
|
||||||
void cryptonight_av4_softaes(void* output, const void* input, struct cryptonight_ctx* ctx);
|
void cryptonight_av4_softaes(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__)
|
||||||
void cryptonight_av2_aesni_stak(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* output, const void* input, 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* output, const void* input, struct cryptonight_ctx* ctx);
|
void cryptonight_av5_aesni_experimental(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
|
||||||
#endif
|
#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() {
|
static bool self_test() {
|
||||||
|
@ -70,7 +71,7 @@ static bool self_test() {
|
||||||
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) malloc(sizeof(struct cryptonight_ctx));
|
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) malloc(sizeof(struct cryptonight_ctx));
|
||||||
ctx->memory = (uint8_t *) malloc(MEMORY);
|
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->memory);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
@ -136,14 +137,14 @@ void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, d
|
||||||
|
|
||||||
|
|
||||||
#ifndef BUILD_TEST
|
#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) {
|
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*)pdata) + 39);
|
uint32_t *nonceptr = (uint32_t*) (((char*) blob) + 39);
|
||||||
uint32_t n = *nonceptr - 1;
|
uint32_t n = *nonceptr - 1;
|
||||||
const uint32_t first_nonce = n + 1;
|
const uint32_t first_nonce = n + 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
*nonceptr = ++n;
|
*nonceptr = ++n;
|
||||||
cryptonight_hash_ctx(hash, pdata, ctx);
|
cryptonight_hash_ctx(blob, blob_size, hash, ctx);
|
||||||
|
|
||||||
if (unlikely(hash[7] < target)) {
|
if (unlikely(hash[7] < target)) {
|
||||||
*hashes_done = n - first_nonce + 1;
|
*hashes_done = n - first_nonce + 1;
|
||||||
|
|
4
xmrig.c
4
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)) {
|
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_free(&work);
|
||||||
work_copy(&work, &stratum_ctx->g_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;
|
*nonceptr = 0xffffffffU / opt_n_threads * thr_id;
|
||||||
} else {
|
} else {
|
||||||
++(*nonceptr);
|
++(*nonceptr);
|
||||||
|
@ -323,7 +323,7 @@ static void *miner_thread(void *userdata) {
|
||||||
gettimeofday(&tv_start, NULL );
|
gettimeofday(&tv_start, NULL );
|
||||||
|
|
||||||
/* scan nonces for a proof-of-work hash */
|
/* 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);
|
stats_add_hashes(thr_id, &tv_start, hashes_done);
|
||||||
|
|
||||||
memcpy(work.hash, hash, 32);
|
memcpy(work.hash, hash, 32);
|
||||||
|
|
Loading…
Reference in a new issue