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