Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/lyra2rev2.c
1201 views
1
#include <memory.h>
2
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"
8
9
#include "lyra2/Lyra2.h"
10
11
#include "miner.h"
12
13
void lyra2rev2_hash(void *state, const void *input)
14
{
15
uint32_t _ALIGN(128) hashA[8], hashB[8];
16
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;
22
23
sph_blake256_init(&ctx_blake);
24
sph_blake256(&ctx_blake, input, 80);
25
sph_blake256_close(&ctx_blake, hashA);
26
27
sph_keccak256_init(&ctx_keccak);
28
sph_keccak256(&ctx_keccak, hashA, 32);
29
sph_keccak256_close(&ctx_keccak, hashB);
30
31
sph_cubehash256_init(&ctx_cubehash);
32
sph_cubehash256(&ctx_cubehash, hashB, 32);
33
sph_cubehash256_close(&ctx_cubehash, hashA);
34
35
LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4);
36
37
sph_skein256_init(&ctx_skein);
38
sph_skein256(&ctx_skein, hashB, 32);
39
sph_skein256_close(&ctx_skein, hashA);
40
41
sph_cubehash256_init(&ctx_cubehash);
42
sph_cubehash256(&ctx_cubehash, hashA, 32);
43
sph_cubehash256_close(&ctx_cubehash, hashB);
44
45
sph_bmw256_init(&ctx_bmw);
46
sph_bmw256(&ctx_bmw, hashB, 32);
47
sph_bmw256_close(&ctx_bmw, hashA);
48
49
memcpy(state, hashA, 32);
50
}
51
52
int scanhash_lyra2rev2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
53
{
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;
58
59
const uint32_t Htarg = ptarget[7];
60
const uint32_t first_nonce = pdata[19];
61
uint32_t nonce = first_nonce;
62
63
if (opt_benchmark)
64
ptarget[7] = 0x0000ff;
65
66
for (int i=0; i < 19; i++) {
67
be32enc(&endiandata[i], pdata[i]);
68
}
69
70
do {
71
be32enc(&endiandata[19], nonce);
72
lyra2rev2_hash(hash, endiandata);
73
74
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
75
work_set_target_ratio(work, hash);
76
pdata[19] = nonce;
77
*hashes_done = pdata[19] - first_nonce;
78
return 1;
79
}
80
nonce++;
81
82
} while (nonce < max_nonce && !work_restart[thr_id].restart);
83
84
pdata[19] = nonce;
85
*hashes_done = pdata[19] - first_nonce + 1;
86
return 0;
87
}
88
89