Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/bmw256.c
1201 views
1
#include "miner.h"
2
3
#include <string.h>
4
#include <stdint.h>
5
6
#include "sha3/sph_bmw.h"
7
8
void bmwhash(void *output, const void *input)
9
{
10
uint32_t hash[16];
11
sph_bmw256_context ctx;
12
13
sph_bmw256_init(&ctx);
14
sph_bmw256(&ctx, input, 80);
15
sph_bmw256_close(&ctx, hash);
16
17
memcpy(output, hash, 32);
18
}
19
20
int scanhash_bmw(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
const uint32_t Htarg = ptarget[7];
28
const uint32_t first_nonce = pdata[19];
29
30
uint32_t n = first_nonce;
31
32
for (int i=0; i < 19; i++) {
33
be32enc(&endiandata[i], pdata[i]);
34
};
35
36
do {
37
be32enc(&endiandata[19], n);
38
bmwhash(hash32, endiandata);
39
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
40
work_set_target_ratio(work, hash32);
41
*hashes_done = n - first_nonce + 1;
42
pdata[19] = n;
43
return 1;
44
}
45
n++;
46
47
} while (n < max_nonce && !work_restart[thr_id].restart);
48
49
*hashes_done = n - first_nonce + 1;
50
pdata[19] = n;
51
52
return 0;
53
}
54
55