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