Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/ink.c
1201 views
1
#include "miner.h"
2
3
#include <string.h>
4
#include <stdint.h>
5
6
#include "sha3/sph_shavite.h"
7
8
extern void inkhash(void *state, const void *input)
9
{
10
uint32_t _ALIGN(128) hash[16];
11
sph_shavite512_context ctx_shavite;
12
13
sph_shavite512_init(&ctx_shavite);
14
sph_shavite512 (&ctx_shavite, (const void*) input, 80);
15
sph_shavite512_close(&ctx_shavite, (void*) hash);
16
17
sph_shavite512_init(&ctx_shavite);
18
sph_shavite512(&ctx_shavite, (const void*) hash, 64);
19
sph_shavite512_close(&ctx_shavite, (void*) hash);
20
21
memcpy(state, hash, 32);
22
}
23
24
int scanhash_ink(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
25
{
26
uint32_t _ALIGN(128) hash32[8];
27
uint32_t _ALIGN(128) endiandata[20];
28
uint32_t *pdata = work->data;
29
uint32_t *ptarget = work->target;
30
31
uint32_t n = pdata[19] - 1;
32
const uint32_t first_nonce = pdata[19];
33
34
for (int k=0; k < 19; k++)
35
be32enc(&endiandata[k], pdata[k]);
36
37
const uint32_t Htarg = ptarget[7];
38
do {
39
be32enc(&endiandata[19], n);
40
inkhash(hash32, endiandata);
41
42
if (hash32[7] <= Htarg && fulltest(hash32, ptarget)) {
43
work_set_target_ratio(work, hash32);
44
pdata[19] = n;
45
*hashes_done = pdata[19] - first_nonce;
46
return 1;
47
}
48
n++;
49
50
} while (n < max_nonce && !work_restart[thr_id].restart);
51
52
*hashes_done = n - first_nonce + 1;
53
pdata[19] = n;
54
return 0;
55
}
56
57