Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/lyra2re.c
1201 views
1
#include <memory.h>
2
3
#include "sha3/sph_blake.h"
4
#include "sha3/sph_groestl.h"
5
#include "sha3/sph_skein.h"
6
#include "sha3/sph_keccak.h"
7
8
#include "lyra2/Lyra2.h"
9
10
#include "miner.h"
11
12
void lyra2_hash(void *state, const void *input)
13
{
14
sph_blake256_context ctx_blake;
15
sph_keccak256_context ctx_keccak;
16
sph_skein256_context ctx_skein;
17
sph_groestl256_context ctx_groestl;
18
19
uint32_t hashA[8], hashB[8];
20
21
sph_blake256_init(&ctx_blake);
22
sph_blake256(&ctx_blake, input, 80);
23
sph_blake256_close(&ctx_blake, hashA);
24
25
sph_keccak256_init(&ctx_keccak);
26
sph_keccak256(&ctx_keccak, hashA, 32);
27
sph_keccak256_close(&ctx_keccak, hashB);
28
29
LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8);
30
31
sph_skein256_init(&ctx_skein);
32
sph_skein256(&ctx_skein, hashA, 32);
33
sph_skein256_close(&ctx_skein, hashB);
34
35
sph_groestl256_init(&ctx_groestl);
36
sph_groestl256(&ctx_groestl, hashB, 32);
37
sph_groestl256_close(&ctx_groestl, hashA);
38
39
memcpy(state, hashA, 32);
40
}
41
42
int scanhash_lyra2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
43
{
44
uint32_t _ALIGN(128) hash[8];
45
uint32_t _ALIGN(128) endiandata[20];
46
uint32_t *pdata = work->data;
47
uint32_t *ptarget = work->target;
48
49
const uint32_t Htarg = ptarget[7];
50
const uint32_t first_nonce = pdata[19];
51
uint32_t nonce = first_nonce;
52
53
if (opt_benchmark)
54
ptarget[7] = 0x0000ff;
55
56
for (int i=0; i < 19; i++) {
57
be32enc(&endiandata[i], pdata[i]);
58
}
59
60
do {
61
be32enc(&endiandata[19], nonce);
62
lyra2_hash(hash, endiandata);
63
64
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
65
work_set_target_ratio(work, hash);
66
pdata[19] = nonce;
67
*hashes_done = pdata[19] - first_nonce;
68
return 1;
69
}
70
nonce++;
71
72
} while (nonce < max_nonce && !work_restart[thr_id].restart);
73
74
pdata[19] = nonce;
75
*hashes_done = pdata[19] - first_nonce + 1;
76
return 0;
77
}
78
79