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