3 #include "sha3/sph_blake.h"
4 #include "sha3/sph_cubehash.h"
5 #include "sha3/sph_keccak.h"
6 #include "sha3/sph_skein.h"
7 #include "sha3/sph_bmw.h"
9 #include "lyra2/Lyra2.h"
13 void lyra2rev2_hash(void *state, const void *input)
15 uint32_t _ALIGN(128) hashA[8], hashB[8];
17 sph_blake256_context ctx_blake;
18 sph_keccak256_context ctx_keccak;
19 sph_cubehash256_context ctx_cubehash;
20 sph_skein256_context ctx_skein;
21 sph_bmw256_context ctx_bmw;
23 sph_blake256_init(&ctx_blake);
24 sph_blake256(&ctx_blake, input, 80);
25 sph_blake256_close(&ctx_blake, hashA);
27 sph_keccak256_init(&ctx_keccak);
28 sph_keccak256(&ctx_keccak, hashA, 32);
29 sph_keccak256_close(&ctx_keccak, hashB);
31 sph_cubehash256_init(&ctx_cubehash);
32 sph_cubehash256(&ctx_cubehash, hashB, 32);
33 sph_cubehash256_close(&ctx_cubehash, hashA);
35 LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4);
37 sph_skein256_init(&ctx_skein);
38 sph_skein256(&ctx_skein, hashB, 32);
39 sph_skein256_close(&ctx_skein, hashA);
41 sph_cubehash256_init(&ctx_cubehash);
42 sph_cubehash256(&ctx_cubehash, hashA, 32);
43 sph_cubehash256_close(&ctx_cubehash, hashB);
45 sph_bmw256_init(&ctx_bmw);
46 sph_bmw256(&ctx_bmw, hashB, 32);
47 sph_bmw256_close(&ctx_bmw, hashA);
49 memcpy(state, hashA, 32);
52 int scanhash_lyra2rev2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
54 uint32_t _ALIGN(128) hash[8];
55 uint32_t _ALIGN(128) endiandata[20];
56 uint32_t *pdata = work->data;
57 uint32_t *ptarget = work->target;
59 const uint32_t Htarg = ptarget[7];
60 const uint32_t first_nonce = pdata[19];
61 uint32_t nonce = first_nonce;
64 ptarget[7] = 0x0000ff;
66 for (int i=0; i < 19; i++) {
67 be32enc(&endiandata[i], pdata[i]);
71 be32enc(&endiandata[19], nonce);
72 lyra2rev2_hash(hash, endiandata);
74 if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
75 work_set_target_ratio(work, hash);
77 *hashes_done = pdata[19] - first_nonce;
82 } while (nonce < max_nonce && !work_restart[thr_id].restart);
85 *hashes_done = pdata[19] - first_nonce + 1;