Changes for the Monero v1 PoW

This commit is contained in:
Lee Clagett 2018-03-02 22:10:46 -05:00
parent 79345119c6
commit 48b1de0b59
6 changed files with 128 additions and 52 deletions

View file

@ -307,11 +307,14 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
}
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES>
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, bool MONERO>
inline bool cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx, uint8_t version)
{
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200);
VARIANT1_CHECK();
VARIANT1_INIT(0);
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
const uint8_t* l0 = ctx->memory;
@ -334,6 +337,7 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
}
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
VARIANT1_1(&l0[idx0 & MASK]);
idx0 = EXTRACT64(cx);
bx0 = cx;
@ -345,8 +349,10 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*)&l0[idx0 & MASK])[0] = al0;
((uint64_t*)&l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -357,15 +363,20 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
keccakf(h0, 24);
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
return true;
}
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES>
inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, bool MONERO>
inline bool cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx, uint8_t version)
{
keccak((const uint8_t *) input, (int) size, ctx->state0, 200);
keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200);
VARIANT1_CHECK();
VARIANT1_INIT(0);
VARIANT1_INIT(1);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
@ -401,6 +412,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
_mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
VARIANT1_1(&l0[idx0 & MASK]);
VARIANT1_1(&l1[idx1 & MASK]);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
@ -416,8 +429,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -430,8 +445,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -446,6 +463,7 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast<char*>(output) + 32);
return true;
}
#endif /* __CRYPTONIGHT_X86_H__ */