-
Notifications
You must be signed in to change notification settings - Fork 116
/
keccak.c
52 lines (41 loc) · 1.13 KB
/
keccak.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "cpuminer-config.h"
#include "miner.h"
#include <string.h>
#include <stdint.h>
#include "sha3/sph_keccak.h"
static void keccakhash(void *state, const void *input)
{
sph_keccak256_context ctx_keccak;
uint32_t hash[32];
sph_keccak256_init(&ctx_keccak);
sph_keccak256 (&ctx_keccak,input, 80);
sph_keccak256_close(&ctx_keccak, hash);
memcpy(state, hash, 32);
}
int scanhash_keccak(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t n = pdata[19] - 1;
const uint32_t first_nonce = pdata[19];
const uint32_t Htarg = ptarget[7];
uint32_t hash64[8] __attribute__((aligned(32)));
uint32_t endiandata[32];
int kk=0;
for (; kk < 32; kk++)
{
be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
};
do {
pdata[19] = ++n;
be32enc(&endiandata[19], n);
keccakhash(hash64, &endiandata);
if (((hash64[7]&0xFFFFFF00)==0) &&
fulltest(hash64, ptarget)) {
*hashes_done = n - first_nonce + 1;
return true;
}
} while (n < max_nonce && !work_restart[thr_id].restart);
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return 0;
}