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