Add memory to cryptonight_ctx.
This commit is contained in:
parent
f29d05bdde
commit
8ab4c1c8bd
13 changed files with 85 additions and 81 deletions
|
@ -40,6 +40,6 @@ extern void (* const extra_hashes[4])(const void *, size_t, char *);
|
|||
|
||||
void 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, const uint32_t *restrict ptarget, uint32_t max_nonce, unsigned long *restrict hashes_done, const char *memory, struct cryptonight_ctx *persistentctx);
|
||||
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, const uint32_t *restrict ptarget, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx);
|
||||
|
||||
#endif /* __CRYPTONIGHT_H__ */
|
||||
|
|
|
@ -222,13 +222,13 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
|
|||
}
|
||||
|
||||
|
||||
void cryptonight_av1_aesni(void *restrict output, const void *restrict input, char *restrict memory, struct cryptonight_ctx *restrict ctx)
|
||||
void cryptonight_av1_aesni(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
|
||||
{
|
||||
keccak((const uint8_t *) input, 76, ctx->state, 200);
|
||||
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = memory;
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = (uint64_t*) ctx->state;
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
|
@ -239,16 +239,16 @@ void cryptonight_av1_aesni(void *restrict output, const void *restrict input, ch
|
|||
|
||||
for (size_t i = 0; __builtin_expect(i < 0x80000, 1); i++) {
|
||||
__m128i cx;
|
||||
cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]);
|
||||
cx = _mm_load_si128((__m128i *) &l0[idx0 & 0x1FFFF0]);
|
||||
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
|
||||
|
||||
_mm_store_si128((__m128i *)&l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx));
|
||||
_mm_store_si128((__m128i *) &l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx));
|
||||
idx0 = _mm_cvtsi128_si64(cx);
|
||||
bx0 = cx;
|
||||
|
||||
uint64_t hi, lo, cl, ch;
|
||||
cl = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[0];
|
||||
ch = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[1];
|
||||
cl = ((uint64_t*) &l0[idx0 & 0x1FFFF0])[0];
|
||||
ch = ((uint64_t*) &l0[idx0 & 0x1FFFF0])[1];
|
||||
lo = _umul128(idx0, cl, &hi);
|
||||
|
||||
al0 += hi;
|
||||
|
@ -262,7 +262,7 @@ void cryptonight_av1_aesni(void *restrict output, const void *restrict input, ch
|
|||
idx0 = al0;
|
||||
}
|
||||
|
||||
cn_implode_scratchpad((__m128i*) memory, (__m128i*) ctx->state);
|
||||
cn_implode_scratchpad((__m128i*) ctx->memory, (__m128i*) ctx->state);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state[0] & 3](ctx->state, 200, output);
|
||||
|
|
|
@ -222,13 +222,13 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
|
|||
}
|
||||
|
||||
|
||||
void cryptonight_av2_aesni_stak(void *restrict output, const void *restrict input, char *restrict memory, struct cryptonight_ctx *restrict ctx)
|
||||
void cryptonight_av2_aesni_stak(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
|
||||
{
|
||||
keccak((const uint8_t *) input, 76, ctx->state, 200);
|
||||
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = memory;
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = (uint64_t*) ctx->state;
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
|
@ -266,7 +266,7 @@ void cryptonight_av2_aesni_stak(void *restrict output, const void *restrict inpu
|
|||
_mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0);
|
||||
}
|
||||
|
||||
cn_implode_scratchpad((__m128i*) memory, (__m128i*) ctx->state);
|
||||
cn_implode_scratchpad((__m128i*) ctx->memory, (__m128i*) ctx->state);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state[0] & 3](ctx->state, 200, output);
|
||||
|
|
|
@ -222,13 +222,13 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
|
|||
}
|
||||
|
||||
|
||||
void cryptonight_av3_aesni_bmi2(void *restrict output, const void *restrict input, char *restrict memory, struct cryptonight_ctx *restrict ctx)
|
||||
void cryptonight_av3_aesni_bmi2(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
|
||||
{
|
||||
keccak((const uint8_t *) input, 76, ctx->state, 200);
|
||||
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = memory;
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = (uint64_t*) ctx->state;
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
|
@ -262,7 +262,7 @@ void cryptonight_av3_aesni_bmi2(void *restrict output, const void *restrict inpu
|
|||
idx0 = al0;
|
||||
}
|
||||
|
||||
cn_implode_scratchpad((__m128i*) memory, (__m128i*) ctx->state);
|
||||
cn_implode_scratchpad((__m128i*) ctx->memory, (__m128i*) ctx->state);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state[0] & 3](ctx->state, 200, output);
|
||||
|
|
|
@ -203,13 +203,13 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
|
|||
}
|
||||
|
||||
|
||||
void cryptonight_av4_softaes(void *restrict output, const void *restrict input, char *restrict memory, struct cryptonight_ctx *restrict ctx)
|
||||
void cryptonight_av4_softaes(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
|
||||
{
|
||||
keccak((const uint8_t *) input, 76, ctx->state, 200);
|
||||
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = memory;
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = (uint64_t*) ctx->state;
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
|
@ -243,7 +243,7 @@ void cryptonight_av4_softaes(void *restrict output, const void *restrict input,
|
|||
idx0 = al0;
|
||||
}
|
||||
|
||||
cn_implode_scratchpad((__m128i*) memory, (__m128i*) ctx->state);
|
||||
cn_implode_scratchpad((__m128i*) ctx->memory, (__m128i*) ctx->state);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state[0] & 3](ctx->state, 200, output);
|
||||
|
|
|
@ -213,8 +213,10 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
|
|||
}
|
||||
|
||||
|
||||
void cryptonight_av5_aesni_experimental(void *restrict output, const void *restrict input, char *restrict memory, struct cryptonight_ctx *restrict ctx)
|
||||
void cryptonight_av5_aesni_experimental(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
|
||||
{
|
||||
const uint8_t* memory = ctx->memory;
|
||||
|
||||
keccak((const uint8_t *) input, 76, ctx->state, 200);
|
||||
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
|
||||
|
||||
|
|
|
@ -37,18 +37,18 @@
|
|||
|
||||
|
||||
#if defined(__x86_64__)
|
||||
void cryptonight_av1_aesni(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av2_aesni_stak(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av3_aesni_bmi2(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av4_softaes(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av5_aesni_experimental(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av1_aesni(void* output, const void* input, struct cryptonight_ctx* ctx);
|
||||
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_av4_softaes(void* output, const void* input, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av5_aesni_experimental(void* output, const void* input, struct cryptonight_ctx* ctx);
|
||||
#elif defined(__i386__)
|
||||
void cryptonight_av1_aesni32(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
#endif
|
||||
|
||||
void cryptonight_av4_softaes(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx);
|
||||
void cryptonight_av4_softaes(void* output, const void* input, struct cryptonight_ctx* ctx);
|
||||
|
||||
void (*cryptonight_hash_ctx)(void* output, const void* input, const char *memory, struct cryptonight_ctx* ctx) = NULL;
|
||||
void (*cryptonight_hash_ctx)(void* output, const void* input, struct cryptonight_ctx* ctx) = NULL;
|
||||
|
||||
|
||||
void cryptonight_init(int variant)
|
||||
|
@ -111,26 +111,15 @@ static inline void do_skein_hash(const void* input, size_t len, char* output) {
|
|||
void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
|
||||
|
||||
|
||||
void cryptonight_hash(void* output, const void* input, size_t len) {
|
||||
uint8_t *memory __attribute((aligned(16))) = (uint8_t *) malloc(MEMORY);
|
||||
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
|
||||
|
||||
cryptonight_hash_ctx(output, input, memory, ctx);
|
||||
|
||||
free(memory);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
||||
#ifndef BUILD_TEST
|
||||
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, const uint32_t *restrict ptarget, uint32_t max_nonce, unsigned long *restrict hashes_done, const char *restrict memory, struct cryptonight_ctx *persistentctx) {
|
||||
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, const uint32_t *restrict ptarget, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) {
|
||||
uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39);
|
||||
uint32_t n = *nonceptr - 1;
|
||||
const uint32_t first_nonce = n + 1;
|
||||
|
||||
do {
|
||||
*nonceptr = ++n;
|
||||
cryptonight_hash_ctx(hash, pdata, memory, persistentctx);
|
||||
cryptonight_hash_ctx(hash, pdata, ctx);
|
||||
|
||||
if (unlikely(hash[7] < ptarget[7])) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue