Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/blake.c
1201 views
1
#include "miner.h"
2
3
#include "sha3/sph_blake.h"
4
5
#include <string.h>
6
#include <stdint.h>
7
#include <memory.h>
8
9
static __thread sph_blake256_context blake_mid;
10
static __thread bool ctx_midstate_done = false;
11
12
void blakehash(void *state, const void *input)
13
{
14
sph_blake256_context ctx;
15
16
uint8_t *ending = (uint8_t*) input;
17
ending += 64;
18
19
// do one memcopy to get a fresh context
20
if (!ctx_midstate_done) {
21
sph_blake256_init(&blake_mid);
22
sph_blake256(&blake_mid, input, 64);
23
ctx_midstate_done = true;
24
}
25
memcpy(&ctx, &blake_mid, sizeof(blake_mid));
26
27
sph_blake256(&ctx, ending, 16);
28
sph_blake256_close(&ctx, state);
29
}
30
31
int scanhash_blake(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
32
{
33
uint32_t _ALIGN(128) hash32[8];
34
uint32_t _ALIGN(128) endiandata[20];
35
uint32_t *pdata = work->data;
36
uint32_t *ptarget = work->target;
37
38
const uint32_t first_nonce = pdata[19];
39
const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7];
40
41
uint32_t n = first_nonce;
42
43
ctx_midstate_done = false;
44
45
// we need big endian data...
46
for (int kk=0; kk < 19; kk++) {
47
be32enc(&endiandata[kk], pdata[kk]);
48
}
49
50
#ifdef DEBUG_ALGO
51
applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]);
52
#endif
53
54
do {
55
be32enc(&endiandata[19], n);
56
blakehash(hash32, endiandata);
57
58
if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) {
59
work_set_target_ratio(work, hash32);
60
*hashes_done = n - first_nonce + 1;
61
return 1;
62
}
63
64
n++; pdata[19] = n;
65
66
} while (n < max_nonce && !work_restart[thr_id].restart);
67
68
*hashes_done = n - first_nonce + 1;
69
pdata[19] = n;
70
return 0;
71
}
72
73