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